From 74791a07280f3ad08ed5e9b6f001ad94f89157fd Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 21 Apr 2023 15:01:10 +0200 Subject: [PATCH 1/2] pdfiumload: support forms See: #3455. --- libvips/foreign/pdfiumload.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libvips/foreign/pdfiumload.c b/libvips/foreign/pdfiumload.c index 7f62246941..6d87953eec 100644 --- a/libvips/foreign/pdfiumload.c +++ b/libvips/foreign/pdfiumload.c @@ -107,6 +107,7 @@ EOF #include #include #include +#include typedef struct _VipsForeignLoadPdf { VipsForeignLoad parent_object; @@ -142,6 +143,8 @@ typedef struct _VipsForeignLoadPdf { FPDF_FILEACCESS file_access; FPDF_DOCUMENT doc; FPDF_PAGE page; + FPDF_FORMFILLINFO form_callbacks; + FPDF_FORMHANDLE form; int current_page; /* Doc has this many pages. @@ -195,6 +198,7 @@ vips_foreign_load_pdf_close( VipsForeignLoadPdf *pdf ) g_mutex_lock( vips_pdfium_mutex ); VIPS_FREEF( FPDF_ClosePage, pdf->page ); + VIPS_FREEF( FPDFDOC_ExitFormFillEnvironment, pdf->form ); VIPS_FREEF( FPDF_CloseDocument, pdf->doc ); VIPS_UNREF( pdf->source ); @@ -272,6 +276,8 @@ vips_foreign_load_pdf_build( VipsObject *object ) if( !vips_object_argument_isset( object, "scale" ) ) pdf->scale = pdf->dpi / 72.0; + pdf->form_callbacks.version = 2; + /* pdfium must know the file length, unfortunately. */ if( pdf->source ) { @@ -301,6 +307,17 @@ vips_foreign_load_pdf_build( VipsObject *object ) return( -1 ); } + if( !(pdf->form = FPDFDOC_InitFormFillEnvironment( pdf->doc, + &pdf->form_callbacks )) ) { + g_mutex_unlock( vips_pdfium_mutex ); + vips_pdfium_error(); + vips_error( "pdfload", + _( "%s: unable to initialize form fill environment" ), + vips_connection_nick( + VIPS_CONNECTION( pdf->source ) ) ); + return( -1 ); + } + g_mutex_unlock( vips_pdfium_mutex ); } @@ -593,6 +610,10 @@ vips_foreign_load_pdf_generate( VipsRegion *or, 0, 0, rect.width, rect.height, 0, 0 ); + FPDF_FFLDraw( pdf->form, bitmap, pdf->page, + 0, 0, rect.width, rect.height, + 0, 0 ); + FPDFBitmap_Destroy( bitmap ); g_mutex_unlock( vips_pdfium_mutex ); From 42341b1a3c458d0218d03caa5e5d70a01988e99f Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 22 Apr 2023 10:14:50 +0200 Subject: [PATCH 2/2] Add changelog notes --- ChangeLog | 1 + libvips/foreign/pdfiumload.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7846a5f4a3..890a8b2cf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ - add `premultiplied` option to smartcrop [lovell] - add "prewitt" and "scharr" edge detectors, "sobel" is more accurate for non-uchar formats [jcupitt] +- add support for forms in pdfium loader [kleisauke] TBD 8.14.3 diff --git a/libvips/foreign/pdfiumload.c b/libvips/foreign/pdfiumload.c index 6d87953eec..3d0121f6a8 100644 --- a/libvips/foreign/pdfiumload.c +++ b/libvips/foreign/pdfiumload.c @@ -16,6 +16,8 @@ * - add password * 21/5/22 * - improve transparency handling [DarthSim] + * 21/4/23 + * - add support for forms [kleisauke] */ /*