diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2023-04-20 15:52:59 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2023-04-20 15:52:59 +0100 |
commit | 1b160b94329d28f5c0b7bc682abd6335175bd50e (patch) | |
tree | dbbb280648748af446da38eb73b0879669a734bd /Resource | |
parent | 7c8ea1623b22247145a438ab2bf081b697e5dc19 (diff) | |
download | ghostpdl-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.
Diffstat (limited to 'Resource')
-rw-r--r-- | Resource/Init/pdf_main.ps | 49 |
1 files changed, 45 insertions, 4 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 |