summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2023-04-20 15:52:59 +0100
committerKen Sharp <ken.sharp@artifex.com>2023-04-20 15:52:59 +0100
commit1b160b94329d28f5c0b7bc682abd6335175bd50e (patch)
treedbbb280648748af446da38eb73b0879669a734bd
parent7c8ea1623b22247145a438ab2bf081b697e5dc19 (diff)
downloadghostpdl-1b160b94329d28f5c0b7bc682abd6335175bd50e.tar.gz
GhostPDF - fix Portfolio PDF with pdfwrite
No file or bug report for this, the customer requested the files be kept private. However any PDF Collection (Portfolio) file will show the problem. GhostPDF supports preserving embedded files from the input, but when we are processing a PDF Collection we don't want to do that, because in this case we run each of the embedded files individually. If we copy the EmbeddedFIles as well then we end up duplicating them in the output. So, when processing EmbeddedFiles, check the Catalog to see if there is a /Collection key, if there is then stop processing EmbeddedFiles. The customer also pointed out there was no way to avoid embedding any EmbeddedFiles from the input, so additionally add a new switch -dPreserveEmbeddedFiles to control this. While we're doing that, add one to control the preservation of 'DOCVIEW' (PageMode, PageLayout, OpenAction) as well, -dPreserveDocView. This then leads on to preventing the EmbeddedFiles in a PDF Collection from writing their DocView information. If we let them do that then we end up opening the file incorrectly. To facilitate similar changes in the future I've rejigged the way .PDFInit works, so that it calls a helper function to read any interpreter parameters and applies them to the PDF context. I've also added a new PostScript operator '.PDFSetParams' which takes a PDF context and a dictionary of key/value pairs which it applies to the context. Sadly I can't actually use that for the docview control, because the PDF initialisation is what processes the document, so changing it afterwards is no help. So I've altered runpdfbegin to call a new function runpdfbegin_with_params and pass an empty dictionary. That then allows me to call runpdfbegin_with_params from the PDF Collection processing, and turn off PreserveDocView. So in summary; new controls PreserveDocView and PreserveEmbeddedFiles and a new function .PDFSetParams to allow us to alter the PDF interpreter parameters after .PDFInit is executed. PDF Collections no longer embed duplicate files.
-rw-r--r--Resource/Init/pdf_main.ps49
-rw-r--r--pdf/ghostpdf.c2
-rw-r--r--pdf/ghostpdf.h2
-rw-r--r--pdf/pdf_doc.c33
-rw-r--r--pdf/pdftop.c10
-rw-r--r--psi/zpdfops.c565
6 files changed, 384 insertions, 277 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index ec0865473..4c8ecfbbd 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -824,7 +824,8 @@ systemdict /OLDPDF known not {/OLDPDF //false def} if
/PDFNOCIDFALLBACK /NO_PDFMARK_OUTLINES /NO_PDFMARK_DESTS /PDFFitPage /Printed /UsePDFX3Profile
/UseBleedBox /UseCropBox /UseArtBox /UseTrimBox /ShowAcroForm /ShowAnnots /PreserveAnnots
/NoUserUnit /RENDERTTNOTDEF /DOPDFMARKS /PDFINFO /ShowAnnotTypes /PreserveAnnotTypes
- /CIDFSubstPath /CIDFSubstFont /SUBSTFONT /IgnoreToUnicode /NONATIVEFONTMAP /PreserveMarkedContent /OutputFile] def
+ /CIDFSubstPath /CIDFSubstFont /SUBSTFONT /IgnoreToUnicode /NONATIVEFONTMAP /PreserveMarkedContent /OutputFile
+ /PreserveDocView /PreserveEmbeddedFiles ] def
/newpdf_gather_parameters
{
@@ -923,6 +924,33 @@ currentdict /PDFSwitches undef
} ifelse
} bind def
+
+/runpdf_collection_entry
+{
+ <</PreserveDocView false>> runpdfbegin_with_params % <file> runpdfbegin -
+ PDFInfo type /dicttype eq
+ {
+ PDFInfo /Collection known
+ {
+ PDFInfo /Collection get
+ pdfclose
+ dup length 1 sub 0 2 3 -1 roll
+ {
+ 1 index exch get (r) file runpdf_collection_entry
+ } for
+ pop
+ }
+ {
+ process_trailer_attrs % - process_trailer_attrs -
+ runpdfpagerange % - runpdfpagerange <int> <int>
+ dopdfpages % <int> <int> dopdfpages -
+ runpdfend % - runpdfend -
+ } ifelse
+ } {
+ pop pop
+ }ifelse
+} bind def
+
% <file> runpdf -
/newpdf_runpdf
{
@@ -935,7 +963,7 @@ currentdict /PDFSwitches undef
pdfclose
dup length 1 sub 0 2 3 -1 roll
{
- 1 index exch get (r) file runpdf
+ 1 index exch get (r) file runpdf_collection_entry
} for
pop
}
@@ -950,7 +978,13 @@ currentdict /PDFSwitches undef
}ifelse
} bind def
-/newpdf_runpdfbegin
+% start a PDF file, and specify interpreter parameters to be used
+% to override any command line ones.
+% Mostly for the benefit of PDF Collections where we want to disable
+%preserving DocView information for pdfwrite.
+%
+% file <dict> runpdfbegin_with_params -
+/runpdfbegin_with_params
{
/pdfdict 10 dict def
pdfdict begin
@@ -981,7 +1015,8 @@ currentdict /PDFSwitches undef
/knownoget {2 copy known {get //true}{pop pop //false}ifelse} bind def
/pget {2 copy known {get //true}{pop pop //false}ifelse}bind def
- newpdf_gather_parameters
+ newpdf_gather_parameters % <parameter overrides dict> <parameter dict>
+ exch {2 index 3 1 roll put} forall
PDFSTOPONERROR
{
.PDFInit
@@ -1006,6 +1041,12 @@ currentdict /PDFSwitches undef
}ifelse
} bind def
+% -file- newpdf_runpdfbegin -
+/newpdf_runpdfbegin
+{
+ <<>> runpdfbegin_with_params
+} bind def
+
/newpdf_pdfgetpage
{
dup 1 sub
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index 5adac672c..6d101c7b4 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -1820,6 +1820,8 @@ pdf_context *pdfi_create_context(gs_memory_t *mem)
/* Setup some flags that don't default to 'false' */
ctx->args.showannots = true;
ctx->args.preserveannots = true;
+ ctx->args.preserveembeddedfiles = true;
+ ctx->args.preservedocview = true;
/* NOTE: For testing certain annotations on cluster, might want to set this to false */
ctx->args.printed = false; /* True if OutputFile is set, false otherwise see pdftop.c, pdf_impl_set_param() */
diff --git a/pdf/ghostpdf.h b/pdf/ghostpdf.h
index acf6b0d72..8c91ebcf6 100644
--- a/pdf/ghostpdf.h
+++ b/pdf/ghostpdf.h
@@ -137,6 +137,8 @@ typedef struct cmd_args_s {
bool preserveannots;
char **preserveannottypes; /* Null terminated array of strings, NULL if none */
bool preservemarkedcontent;
+ bool preserveembeddedfiles;
+ bool preservedocview;
bool nouserunit;
bool renderttnotdef;
bool pdfinfo;
diff --git a/pdf/pdf_doc.c b/pdf/pdf_doc.c
index ca32e55aa..272703dfa 100644
--- a/pdf/pdf_doc.c
+++ b/pdf/pdf_doc.c
@@ -1602,6 +1602,13 @@ static int pdfi_doc_EmbeddedFiles(pdf_context *ctx)
pdf_array *Names_array = NULL;
pdf_array *Kids = NULL;
+ code = pdfi_dict_knownget_type(ctx, ctx->Root, "Collection", PDF_DICT, (pdf_obj **)&Names);
+ if (code < 0) goto exit;
+ if (code > 0) {
+ code = 0;
+ goto exit;
+ }
+
code = pdfi_dict_knownget_type(ctx, ctx->Root, "Names", PDF_DICT, (pdf_obj **)&Names);
if (code <= 0) goto exit;
@@ -1796,8 +1803,6 @@ int pdfi_doc_trailer(pdf_context *ctx)
}
if (ctx->device_state.writepdfmarks) {
- code = pdfi_doc_view(ctx);
-
/* Handle Outlines */
code = pdfi_doc_Outlines(ctx);
if (code < 0) {
@@ -1807,11 +1812,13 @@ int pdfi_doc_trailer(pdf_context *ctx)
}
/* Handle Docview pdfmark stuff */
- code = pdfi_doc_view(ctx);
- if (code < 0) {
- pdfi_set_warning(ctx, code, NULL, W_PDF_BAD_VIEW, "pdfi_doc_view", NULL);
- if (ctx->args.pdfstoponerror)
- goto exit;
+ if (ctx->args.preservedocview) {
+ code = pdfi_doc_view(ctx);
+ if (code < 0) {
+ pdfi_set_warning(ctx, code, NULL, W_PDF_BAD_VIEW, "pdfi_doc_view", NULL);
+ if (ctx->args.pdfstoponerror)
+ goto exit;
+ }
}
/* Handle Info */
@@ -1828,11 +1835,13 @@ int pdfi_doc_trailer(pdf_context *ctx)
/* Handle EmbeddedFiles */
/* TODO: add a configuration option to embed or omit */
- code = pdfi_doc_EmbeddedFiles(ctx);
- if (code < 0) {
- pdfi_set_warning(ctx, 0, NULL, W_PDF_BAD_EMBEDDEDFILES, "pdfi_doc_trailer", NULL);
- if (ctx->args.pdfstoponerror)
- goto exit;
+ if (ctx->args.preserveembeddedfiles) {
+ code = pdfi_doc_EmbeddedFiles(ctx);
+ if (code < 0) {
+ pdfi_set_warning(ctx, 0, NULL, W_PDF_BAD_EMBEDDEDFILES, "pdfi_doc_trailer", NULL);
+ if (ctx->args.pdfstoponerror)
+ goto exit;
+ }
}
}
diff --git a/pdf/pdftop.c b/pdf/pdftop.c
index d80f9198c..10ea92c43 100644
--- a/pdf/pdftop.c
+++ b/pdf/pdftop.c
@@ -632,6 +632,16 @@ pdf_impl_set_param(pl_interp_implementation_t *impl,
if (code < 0)
return code;
}
+ if (argis(param, "PreserveEmbeddedFiles")) {
+ code = plist_value_get_bool(&pvalue, &ctx->args.preserveembeddedfiles);
+ if (code < 0)
+ return code;
+ }
+ if (argis(param, "PreserveDocView")) {
+ code = plist_value_get_bool(&pvalue, &ctx->args.preservedocview);
+ if (code < 0)
+ return code;
+ }
if (argis(param, "NoUserUnit")) {
code = plist_value_get_bool(&pvalue, &ctx->args.nouserunit);
if (code < 0)
diff --git a/psi/zpdfops.c b/psi/zpdfops.c
index 43ab41c2b..20620334a 100644
--- a/psi/zpdfops.c
+++ b/psi/zpdfops.c
@@ -1232,310 +1232,352 @@ static int param_value_get_namelist(gs_memory_t *ps_mem, pdf_context *ctx, ref *
return 0;
}
-static int zPDFInit(i_ctx_t *i_ctx_p)
+static int apply_interpreter_params(i_ctx_t *i_ctx_p, pdfctx_t *pdfctx, ref *pdictref)
{
- os_ptr op = osp;
- ref *pdictref = NULL, *pvalueref;
- pdfctx_t *pdfctx = NULL;
- pdf_context *ctx = NULL;
- int code = 0;
- gs_memory_t *cmem;
-
- code = gs_memory_chunk_wrap(&cmem, imemory->non_gc_memory);
- if (code < 0)
- return_error(gs_error_VMerror);
+ int code = gs_error_typecheck;
+ ref *pvalueref;
- pdfctx = gs_alloc_struct(imemory, pdfctx_t, &st_pdfctx_t, "PDFcontext");
- if (!pdfctx) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
- }
- pdfctx->pdf_memory = cmem;
- pdfctx->ctx = NULL;
- pdfctx->ps_stream = NULL;
- pdfctx->pdf_stream = NULL;
- pdfctx->UsingPDFFile = false;
- pdfctx->pdf_stream_memory = NULL;
- pdfctx->profile_cache = gsicc_profilecache_new(imemory);
- if (pdfctx->profile_cache == NULL) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
+ if (dict_find_string(pdictref, "PDFDEBUG", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.pdfdebug = pvalueref->value.boolval;
}
- pdfctx->cache_memory = imemory;
- ctx = pdfi_create_context(cmem);
- if (ctx == NULL) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
+ if (dict_find_string(pdictref, "PDFSTOPONERROR", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.pdfstoponerror = pvalueref->value.boolval;
}
- pdfctx->ctx = ctx;
- get_zfont_glyph_name(&pdfctx->ctx->get_glyph_name);
- pdfctx->ctx->get_glyph_index = zpdfi_glyph_index;
-
- if (ref_stack_count(&o_stack) > 0 && r_has_type(op, t_dictionary)) {
- pdictref = op;
+ if (dict_find_string(pdictref, "PDFSTOPONWARNING", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.pdfstoponwarning = pvalueref->value.boolval;
+ if (pvalueref->value.boolval)
+ pdfctx->ctx->args.pdfstoponerror = pvalueref->value.boolval;
+ }
- code = gs_error_typecheck;
- if (dict_find_string(pdictref, "PDFDEBUG", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.pdfdebug = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "NOTRANSPARENCY", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.notransparency = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "PDFSTOPONERROR", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.pdfstoponerror = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "QUIET", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.QUIET = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "PDFSTOPONWARNING", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.pdfstoponwarning = pvalueref->value.boolval;
- if (pvalueref->value.boolval)
- pdfctx->ctx->args.pdfstoponerror = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "VerboseErrors", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.verbose_errors = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "NOTRANSPARENCY", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.notransparency = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "VerboseWarnings", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.verbose_warnings = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "QUIET", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.QUIET = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "PDFPassword", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_string))
+ goto error;
+ pdfctx->ctx->encryption.Password = (char *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF Password from zpdfops");
+ memset(pdfctx->ctx->encryption.Password, 0x00, r_size(pvalueref) + 1);
+ memcpy(pdfctx->ctx->encryption.Password, pvalueref->value.const_bytes, r_size(pvalueref));
+ pdfctx->ctx->encryption.PasswordLen = r_size(pvalueref);
+ }
- if (dict_find_string(pdictref, "VerboseErrors", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.verbose_errors = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "FirstPage", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_integer))
+ goto error;
+ pdfctx->ctx->args.first_page = pvalueref->value.intval;
+ }
- if (dict_find_string(pdictref, "VerboseWarnings", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.verbose_warnings = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "LastPage", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_integer))
+ goto error;
+ pdfctx->ctx->args.last_page = pvalueref->value.intval;
+ }
- if (dict_find_string(pdictref, "PDFPassword", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_string))
- goto error;
- pdfctx->ctx->encryption.Password = (char *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF Password from zpdfops");
- memset(pdfctx->ctx->encryption.Password, 0x00, r_size(pvalueref) + 1);
- memcpy(pdfctx->ctx->encryption.Password, pvalueref->value.const_bytes, r_size(pvalueref));
- pdfctx->ctx->encryption.PasswordLen = r_size(pvalueref);
- }
+ if (dict_find_string(pdictref, "PDFNOCIDFALLBACK", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.nocidfallback = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "FirstPage", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_integer))
- goto error;
- pdfctx->ctx->args.first_page = pvalueref->value.intval;
- }
+ if (dict_find_string(pdictref, "NO_PDFMARK_OUTLINES", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.no_pdfmark_outlines = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "LastPage", &pvalueref) > 0) {
+ /* This one can be a boolean OR an integer */
+ if (dict_find_string(pdictref, "UsePDFX3Profile", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean)) {
if (!r_has_type(pvalueref, t_integer))
goto error;
- pdfctx->ctx->args.last_page = pvalueref->value.intval;
- }
-
- if (dict_find_string(pdictref, "PDFNOCIDFALLBACK", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.nocidfallback = pvalueref->value.boolval;
+ else {
+ pdfctx->ctx->args.UsePDFX3Profile = true;
+ pdfctx->ctx->args.PDFX3Profile_num = pvalueref->value.intval;
+ }
+ } else {
+ pdfctx->ctx->args.UsePDFX3Profile = pvalueref->value.boolval;
+ pdfctx->ctx->args.PDFX3Profile_num = 0;
}
+ }
- if (dict_find_string(pdictref, "NO_PDFMARK_OUTLINES", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.no_pdfmark_outlines = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "NO_PDFMARK_DESTS", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.no_pdfmark_dests = pvalueref->value.boolval;
+ }
- /* This one can be a boolean OR an integer */
- if (dict_find_string(pdictref, "UsePDFX3Profile", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean)) {
- if (!r_has_type(pvalueref, t_integer))
- goto error;
- else {
- pdfctx->ctx->args.UsePDFX3Profile = true;
- pdfctx->ctx->args.PDFX3Profile_num = pvalueref->value.intval;
- }
- } else {
- pdfctx->ctx->args.UsePDFX3Profile = pvalueref->value.boolval;
- pdfctx->ctx->args.PDFX3Profile_num = 0;
- }
- }
+ if (dict_find_string(pdictref, "PDFFitPage", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.pdffitpage = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "NO_PDFMARK_DESTS", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.no_pdfmark_dests = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "OutputFile", &pvalueref) > 0)
+ pdfctx->ctx->args.printed = true;
+ else
+ pdfctx->ctx->args.printed = false;
- if (dict_find_string(pdictref, "PDFFitPage", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.pdffitpage = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "Printed", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.printed = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "OutputFile", &pvalueref) > 0)
- pdfctx->ctx->args.printed = true;
- else
- pdfctx->ctx->args.printed = false;
+ if (dict_find_string(pdictref, "UseBleedBox", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.usebleedbox = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "Printed", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.printed = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "UseCropBox", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.usecropbox = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "UseBleedBox", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.usebleedbox = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "UseArtBox", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.useartbox = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "UseCropBox", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.usecropbox = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "UseTrimBox", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.usetrimbox = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "UseArtBox", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.useartbox = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "ShowAcroForm", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.showacroform = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "UseTrimBox", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.usetrimbox = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "ShowAnnots", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.showannots = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "ShowAcroForm", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.showacroform = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "PreserveAnnots", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.preserveannots = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "ShowAnnots", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.showannots = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "PreserveMarkedContent", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.preservemarkedcontent = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "PreserveAnnots", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.preserveannots = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "PreserveEmbeddedFiles", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.preserveembeddedfiles = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "PreserveMarkedContent", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.preservemarkedcontent = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "PreserveDocView", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.preservedocview = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "NoUserUnit", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.nouserunit = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "NoUserUnit", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.nouserunit = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "RENDERTTNOTDEF", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.renderttnotdef = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "RENDERTTNOTDEF", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.renderttnotdef = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "DOPDFMARKS", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.dopdfmarks = pvalueref->value.boolval;
- }
+ if (dict_find_string(pdictref, "DOPDFMARKS", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.dopdfmarks = pvalueref->value.boolval;
+ }
- if (dict_find_string(pdictref, "PDFINFO", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.pdfinfo = pvalueref->value.boolval;
- }
- if (dict_find_string(pdictref, "ShowAnnotTypes", &pvalueref) > 0) {
- code = param_value_get_namelist(imemory, pdfctx->ctx, pvalueref,
- &pdfctx->ctx->args.showannottypes);
- if (code < 0)
- goto error;
- }
- if (dict_find_string(pdictref, "PreserveAnnotTypes", &pvalueref) > 0) {
- code = param_value_get_namelist(imemory, pdfctx->ctx, pvalueref,
- &pdfctx->ctx->args.preserveannottypes);
- if (code < 0)
- goto error;
- }
- if (dict_find_string(pdictref, "CIDFSubstPath", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_string))
- goto error;
- pdfctx->ctx->args.cidfsubstpath.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF cidfsubstpath from zpdfops");
- if (pdfctx->ctx->args.cidfsubstpath.data == NULL) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
- }
- memcpy(pdfctx->ctx->args.cidfsubstpath.data, pvalueref->value.const_bytes, r_size(pvalueref));
- pdfctx->ctx->args.cidfsubstpath.size = r_size(pvalueref);
- }
- if (dict_find_string(pdictref, "CIDFSubstFont", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_string))
- goto error;
- pdfctx->ctx->args.cidfsubstfont.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF cidfsubstfont from zpdfops");
- if (pdfctx->ctx->args.cidfsubstfont.data == NULL) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
- }
- memcpy(pdfctx->ctx->args.cidfsubstfont.data, pvalueref->value.const_bytes, r_size(pvalueref));
- pdfctx->ctx->args.cidfsubstfont.size = r_size(pvalueref);
+ if (dict_find_string(pdictref, "PDFINFO", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.pdfinfo = pvalueref->value.boolval;
+ }
+ if (dict_find_string(pdictref, "ShowAnnotTypes", &pvalueref) > 0) {
+ code = param_value_get_namelist(imemory, pdfctx->ctx, pvalueref,
+ &pdfctx->ctx->args.showannottypes);
+ if (code < 0)
+ goto error;
+ }
+ if (dict_find_string(pdictref, "PreserveAnnotTypes", &pvalueref) > 0) {
+ code = param_value_get_namelist(imemory, pdfctx->ctx, pvalueref,
+ &pdfctx->ctx->args.preserveannottypes);
+ if (code < 0)
+ goto error;
+ }
+ if (dict_find_string(pdictref, "CIDFSubstPath", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_string))
+ goto error;
+ pdfctx->ctx->args.cidfsubstpath.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF cidfsubstpath from zpdfops");
+ if (pdfctx->ctx->args.cidfsubstpath.data == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
}
- if (dict_find_string(pdictref, "SUBSTFONT", &pvalueref) > 0) {
- ref nmstr, *namstrp;
- if (r_has_type(pvalueref, t_string)) {
- namstrp = pvalueref;
- pdfctx->ctx->args.defaultfont_is_name = false;
- } else if (r_has_type(pvalueref, t_name)) {
- name_string_ref(imemory, pvalueref, &nmstr);
- namstrp = &nmstr;
- pdfctx->ctx->args.defaultfont_is_name = true;
- }
- else {
- code = gs_note_error(gs_error_typecheck);
- goto error;
- }
- pdfctx->ctx->args.defaultfont.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(namstrp) + 1, "PDF defaultfontname from zpdfops");
- if (pdfctx->ctx->args.defaultfont.data == NULL) {
- code = gs_note_error(gs_error_VMerror);
- goto error;
- }
- memcpy(pdfctx->ctx->args.defaultfont.data, pvalueref->value.const_bytes, r_size(namstrp));
- pdfctx->ctx->args.defaultfont.size = r_size(namstrp);
+ memcpy(pdfctx->ctx->args.cidfsubstpath.data, pvalueref->value.const_bytes, r_size(pvalueref));
+ pdfctx->ctx->args.cidfsubstpath.size = r_size(pvalueref);
+ }
+ if (dict_find_string(pdictref, "CIDFSubstFont", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_string))
+ goto error;
+ pdfctx->ctx->args.cidfsubstfont.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(pvalueref) + 1, "PDF cidfsubstfont from zpdfops");
+ if (pdfctx->ctx->args.cidfsubstfont.data == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
}
- if (dict_find_string(pdictref, "IgnoreToUnicode", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.ignoretounicode = pvalueref->value.boolval;
+ memcpy(pdfctx->ctx->args.cidfsubstfont.data, pvalueref->value.const_bytes, r_size(pvalueref));
+ pdfctx->ctx->args.cidfsubstfont.size = r_size(pvalueref);
+ }
+ if (dict_find_string(pdictref, "SUBSTFONT", &pvalueref) > 0) {
+ ref nmstr, *namstrp;
+ if (r_has_type(pvalueref, t_string)) {
+ namstrp = pvalueref;
+ pdfctx->ctx->args.defaultfont_is_name = false;
+ } else if (r_has_type(pvalueref, t_name)) {
+ name_string_ref(imemory, pvalueref, &nmstr);
+ namstrp = &nmstr;
+ pdfctx->ctx->args.defaultfont_is_name = true;
}
- if (dict_find_string(pdictref, "NONATIVEFONTMAP", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_boolean))
- goto error;
- pdfctx->ctx->args.nonativefontmap = pvalueref->value.boolval;
+ else {
+ code = gs_note_error(gs_error_typecheck);
+ goto error;
}
- if (dict_find_string(pdictref, "PageCount", &pvalueref) > 0) {
- if (!r_has_type(pvalueref, t_integer))
- goto error;
- pdfctx->ctx->Pdfmark_InitialPage = pvalueref->value.intval;
+ pdfctx->ctx->args.defaultfont.data = (byte *)gs_alloc_bytes(pdfctx->ctx->memory, r_size(namstrp) + 1, "PDF defaultfontname from zpdfops");
+ if (pdfctx->ctx->args.defaultfont.data == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
}
- code = 0;
+ memcpy(pdfctx->ctx->args.defaultfont.data, pvalueref->value.const_bytes, r_size(namstrp));
+ pdfctx->ctx->args.defaultfont.size = r_size(namstrp);
+ }
+ if (dict_find_string(pdictref, "IgnoreToUnicode", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.ignoretounicode = pvalueref->value.boolval;
+ }
+ if (dict_find_string(pdictref, "NONATIVEFONTMAP", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_boolean))
+ goto error;
+ pdfctx->ctx->args.nonativefontmap = pvalueref->value.boolval;
+ }
+ if (dict_find_string(pdictref, "PageCount", &pvalueref) > 0) {
+ if (!r_has_type(pvalueref, t_integer))
+ goto error;
+ pdfctx->ctx->Pdfmark_InitialPage = pvalueref->value.intval;
+ }
+ code = 0;
+
+error:
+ return code;
+}
+
+static int zPDFSetParams(i_ctx_t *i_ctx_p)
+{
+ os_ptr op = osp;
+ int code = 0;
+ pdfctx_t *pdfctx = NULL;
+
+ check_op(2);
+
+ check_type(*(op - 1), t_pdfctx);
+ pdfctx = r_ptr(op - 1, pdfctx_t);
+
+ check_type(*op, t_dictionary);
+
+ code = apply_interpreter_params(i_ctx_p, pdfctx, op);
+
+ pop(2);
+ return code;
+}
+
+static int zPDFInit(i_ctx_t *i_ctx_p)
+{
+ os_ptr op = osp;
+ ref *pdictref = NULL, *pvalueref;
+ pdfctx_t *pdfctx = NULL;
+ pdf_context *ctx = NULL;
+ int code = 0;
+ gs_memory_t *cmem;
+
+ code = gs_memory_chunk_wrap(&cmem, imemory->non_gc_memory);
+ if (code < 0)
+ return_error(gs_error_VMerror);
+
+ pdfctx = gs_alloc_struct(imemory, pdfctx_t, &st_pdfctx_t, "PDFcontext");
+ if (!pdfctx) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
+ }
+ pdfctx->pdf_memory = cmem;
+ pdfctx->ctx = NULL;
+ pdfctx->ps_stream = NULL;
+ pdfctx->pdf_stream = NULL;
+ pdfctx->UsingPDFFile = false;
+ pdfctx->pdf_stream_memory = NULL;
+ pdfctx->profile_cache = gsicc_profilecache_new(imemory);
+ if (pdfctx->profile_cache == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
+ }
+ pdfctx->cache_memory = imemory;
+
+ ctx = pdfi_create_context(cmem);
+ if (ctx == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
+ }
+
+ pdfctx->ctx = ctx;
+ get_zfont_glyph_name(&pdfctx->ctx->get_glyph_name);
+ pdfctx->ctx->get_glyph_index = zpdfi_glyph_index;
+
+ if (ref_stack_count(&o_stack) > 0) {
+ if (r_has_type(op, t_dictionary))
+ code = apply_interpreter_params(i_ctx_p, pdfctx, op);
pop(1);
+ if (code < 0)
+ goto error;
}
code = zpdfi_populate_search_paths(i_ctx_p, ctx);
if (code < 0)
@@ -1694,6 +1736,7 @@ const op_def zpdfops_op_defs[] =
{"1.PDFInit", zPDFInit},
{"1.PDFparsePageList", zPDFparsePageList},
{"0.PDFAvailable", zPDFAvailable},
+ {"2.PDFSetParams", zPDFSetParams},
#ifdef HAVE_LIBIDN
{"1.saslprep", zsaslprep},
#endif