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 7f62246941..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] */ /* @@ -107,6 +109,7 @@ EOF #include #include #include +#include typedef struct _VipsForeignLoadPdf { VipsForeignLoad parent_object; @@ -142,6 +145,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 +200,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 +278,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 +309,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 +612,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 );