Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pdfiumload: add support for forms #3456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions libvips/foreign/pdfiumload.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* - add password
* 21/5/22
* - improve transparency handling [DarthSim]
* 21/4/23
* - add support for forms [kleisauke]
*/

/*
Expand Down Expand Up @@ -107,6 +109,7 @@ EOF
#include <fpdfview.h>
#include <fpdf_doc.h>
#include <fpdf_edit.h>
#include <fpdf_formfill.h>

typedef struct _VipsForeignLoadPdf {
VipsForeignLoad parent_object;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 );
Expand Down