From 97d727843d7ec6ba6eba7ec1251757013d2677a6 Mon Sep 17 00:00:00 2001 From: ktanaka101 Date: Mon, 5 May 2025 18:20:28 +0900 Subject: [PATCH] [pdfx] fix: set default image format to PNG in `PdfPage.render` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The public docs—and the native Android / iOS layers—treat PNG as the default output format when `format` is omitted, but the Dart signature still defaulted to `PdfPageImageFormat.jpeg`. --- .../lib/src/renderer/interfaces/page.dart | 2 +- packages/pdfx/test/pdfx_test.dart | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/pdfx/lib/src/renderer/interfaces/page.dart b/packages/pdfx/lib/src/renderer/interfaces/page.dart index 96f22ae8..b85bb136 100644 --- a/packages/pdfx/lib/src/renderer/interfaces/page.dart +++ b/packages/pdfx/lib/src/renderer/interfaces/page.dart @@ -66,7 +66,7 @@ abstract class PdfPage { Future render({ required double width, required double height, - PdfPageImageFormat format = PdfPageImageFormat.jpeg, + PdfPageImageFormat format = PdfPageImageFormat.png, String? backgroundColor, Rect? cropRect, int quality = 100, diff --git a/packages/pdfx/test/pdfx_test.dart b/packages/pdfx/test/pdfx_test.dart index c72c8ebd..5f90f6fa 100644 --- a/packages/pdfx/test/pdfx_test.dart +++ b/packages/pdfx/test/pdfx_test.dart @@ -184,6 +184,37 @@ void main() { expect(pageImage.quality, 100); }); + test('render default args', () async { + final width = page.width * 2, height = page.height * 2; + final pageImage = (await page.render( + width: width, + height: height, + removeTempFile: false, + ))!; + + expect(log, [ + isMethodCall( + 'render', + arguments: { + 'pageId': page.id, + 'width': width, + 'height': height, + 'format': PdfPageImageFormat.png.value, + 'backgroundColor': '#00FFFFFF', + 'crop': false, + 'crop_x': null, + 'crop_y': null, + 'crop_height': null, + 'crop_width': null, + 'quality': 100, + 'forPrint': false, + }, + ), + ]); + + expect(pageImage.format, PdfPageImageFormat.png); + }); + test('close', () async { await page.close(); expect(page.isClosed, isTrue);