From d9c00eb5ca577018b40533f041230754484ace7e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 28 Jan 2022 13:32:13 +0000 Subject: [PATCH] add password fielf to pdfiumload and docs --- libvips/foreign/foreign.c | 3 +++ libvips/foreign/pdfiumload.c | 15 ++++++++++++++- libvips/foreign/popplerload.c | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index 9bf932a6..c5d4a488 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -2583,6 +2583,7 @@ vips_jxlsave_target( VipsImage *in, VipsTarget *target, ... ) * * @dpi: %gdouble, render at this DPI * * @scale: %gdouble, scale render by this factor * * @background: #VipsArrayDouble background colour + * * @password: %gchararray background colour * * Render a PDF file into a VIPS image. * @@ -2603,6 +2604,8 @@ vips_jxlsave_target( VipsImage *in, VipsTarget *target, ... ) * Use @background to set the background RGBA colour. The default is 255 * (solid white), use eg. 0 for a transparent background. * + * Use @password to supply a decryption password. + * * The operation fills a number of header fields with metadata, for example * "pdf-author". They may be useful. * diff --git a/libvips/foreign/pdfiumload.c b/libvips/foreign/pdfiumload.c index 4b0c3c93..d8d0cf1e 100644 --- a/libvips/foreign/pdfiumload.c +++ b/libvips/foreign/pdfiumload.c @@ -12,6 +12,8 @@ * - have a lock just for pdfium [DarthSim] * - update for current pdfium * - add _source input + * 28/1/22 + * - add password */ /* @@ -130,6 +132,10 @@ typedef struct _VipsForeignLoadPdf { */ VipsArrayDouble *background; + /* Decrypt with this. + */ + const char *password; + FPDF_FILEACCESS file_access; FPDF_DOCUMENT doc; FPDF_PAGE page; @@ -281,7 +287,7 @@ vips_foreign_load_pdf_build( VipsObject *object ) g_mutex_lock( vips_pdfium_mutex ); if( !(pdf->doc = FPDF_LoadCustomDocument( &pdf->file_access, - NULL )) ) { + pdf->password )) ) { g_mutex_unlock( vips_pdfium_mutex ); vips_pdfium_error(); vips_error( "pdfload", @@ -693,6 +699,13 @@ vips_foreign_load_pdf_class_init( VipsForeignLoadPdfClass *class ) G_STRUCT_OFFSET( VipsForeignLoadPdf, background ), VIPS_TYPE_ARRAY_DOUBLE ); + VIPS_ARG_STRING( class, "password", 25, + _( "Password" ), + _( "Decrypt with this password" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsForeignLoadPdf, password ), + NULL ); + } static void diff --git a/libvips/foreign/popplerload.c b/libvips/foreign/popplerload.c index 069cc75c..2028221c 100644 --- a/libvips/foreign/popplerload.c +++ b/libvips/foreign/popplerload.c @@ -20,6 +20,8 @@ * - allow dpi and scale to both be set [le0daniel] * 21/4/21 kleisauke * - include GObject part from pdfload.c + * 28/1/22 + * - add password */ /*