summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2019-04-02 10:55:27 +0100
committerKen Sharp <ken.sharp@artifex.com>2019-04-02 10:55:27 +0100
commit2c97be9f328babb7b544ab3610e6fce05e30cdc8 (patch)
tree92fdeecec9e80f36944f5e900e7b21cd7af05584 /lib
parent978b03b453245c2a48abaee5addea3b7e025a2ed (diff)
downloadghostpdl-2c97be9f328babb7b544ab3610e6fce05e30cdc8.tar.gz
pdfwrite - change the example PDF/A and PDF/X scripts
From Bug #700930 "Typo in example command for PDF/X-3 in VectorDevices.htm" The reporter claimed that the (mis-spelled) command didn't work, which was not surprising, since it contained a typo. After fixing the documentation the reporter claimed that the command didn't work. This is true and was missed because of the misleading title. The PDFX_def.ps file was mistakenly pulling the ProcessColorModel from systemdict, which would only be set if this was set on the command line. The real problem is the fact that our setpagedevice/currentpagedevice code doesn't truly reflect the device setup, so changes to the ProcessColorModel caused by setting ColorConversionStrategy are not reflected in the values returned by currentpagedevice. This commit updates PDFX_def.ps to chaeck the ColorConversionStrategy instead, which is more reliable, and then use the ProcessColorModel from the currentpagedevice as a fallback if ColorConversionStrategy is not set. (actually this should not be possible) Update PDFA_def.ps similarly; although it was using the currentpagedvice this is not a reliable method. Finally; reformat the files, add some extra comments describing what the code is doing, make it clearer that these files *should* be customised and add additional some basic instruction on customising them.
Diffstat (limited to 'lib')
-rw-r--r--lib/PDFA_def.ps71
-rw-r--r--lib/PDFX_def.ps87
2 files changed, 129 insertions, 29 deletions
diff --git a/lib/PDFA_def.ps b/lib/PDFA_def.ps
index f0ff0d1b6..f77c90ef1 100644
--- a/lib/PDFA_def.ps
+++ b/lib/PDFA_def.ps
@@ -1,30 +1,69 @@
%!
% This is a sample prefix file for creating a PDF/A document.
-% Feel free to modify entries marked with "Customize".
-% This assumes an ICC profile to reside in the file (ISO Coated sb.icc),
-% unless the user modifies the corresponding line below.
+% Users should modify entries marked with "Customize".
+% This assumes an ICC profile resides in the file (srgb.icc),
+% in the current directory unless the user modifies the corresponding line below.
% Define entries in the document Info dictionary :
-/ICCProfile (srgb.icc) % Customise
-def
-
[ /Title (Title) % Customise
/DOCINFO pdfmark
% Define an ICC profile :
+/ICCProfile (srgb.icc) % Customise
+def
[/_objdef {icc_PDFA} /type /stream /OBJ pdfmark
+
+%% This code attempts to set the /N (number of components) key for the ICC colour space.
+%% To do this it checks the ColorConversionStrategy or the device ProcessColorModel if
+%% ColorConversionStrategy is not set.
+%% This is not 100% reliable. A better solution is for the user to edit this and replace
+%% the code between the ---8<--- lines with a simple declaration like:
+%% /N 3
+%% where the value of N is the number of components from the profile defined in /ICCProfile above.
+%%
[{icc_PDFA}
<<
- /N currentpagedevice /ProcessColorModel known {
- currentpagedevice /ProcessColorModel get dup /DeviceGray eq
- {pop 1} {
- /DeviceRGB eq
- {3}{4} ifelse
+%% ----------8<--------------8<-------------8<--------------8<----------
+ systemdict /ColorConversionStrategy known {
+ systemdict /ColorConversionStrategy get cvn dup /Gray eq {
+ pop /N 1 false
+ }{
+ dup /RGB eq {
+ pop /N 3 false
+ }{
+ /CMYK eq {
+ /N 4 false
+ }{
+ (ColorConversionStrategy not a device space, falling back to ProcessColorModel, output may not be valid PDF/A.)=
+ true
+ } ifelse
+ } ifelse
} ifelse
} {
- (ERROR, unable to determine ProcessColorModel) == flush
+ (ColorConversionStrategy not set, falling back to ProcessColorModel, output may not be valid PDF/A.)=
+ true
} ifelse
+
+ {
+ currentpagedevice /ProcessColorModel get
+ dup /DeviceGray eq {
+ pop /N 1
+ }{
+ dup /DeviceRGB eq {
+ pop /N 3
+ }{
+ dup /DeviceCMYK eq {
+ pop /N 4
+ } {
+ (ProcessColorModel not a device space.)=
+ /ProcessColorModel cvx /rangecheck signalerror
+ } ifelse
+ } ifelse
+ } ifelse
+ } if
+%% ----------8<--------------8<-------------8<--------------8<----------
+
>> /PUT pdfmark
[{icc_PDFA} ICCProfile (r) file /PUT pdfmark
@@ -32,9 +71,9 @@ def
[/_objdef {OutputIntent_PDFA} /type /dict /OBJ pdfmark
[{OutputIntent_PDFA} <<
- /Type /OutputIntent % Must be so (the standard requires).
- /S /GTS_PDFA1 % Must be so (the standard requires).
- /DestOutputProfile {icc_PDFA} % Must be so (see above).
- /OutputConditionIdentifier (sRGB) % Customize
+ /Type /OutputIntent % Must be so (the standard requires).
+ /S /GTS_PDFA1 % Must be so (the standard requires).
+ /DestOutputProfile {icc_PDFA} % Must be so (see above).
+ /OutputConditionIdentifier (sRGB) % Customize
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFA} ]>> /PUT pdfmark
diff --git a/lib/PDFX_def.ps b/lib/PDFX_def.ps
index 9ff233873..c251a82db 100644
--- a/lib/PDFX_def.ps
+++ b/lib/PDFX_def.ps
@@ -1,33 +1,94 @@
%!
% This is a sample prefix file for creating a PDF/X-3 document.
-% Feel free to modify entries marked with "Customize".
+% Users should modify entries marked with "Customize".
+% This assumes an ICC profile resides in the file (ISO Coated sb.icc)
+% in the current directory unless the user modifies the corresponding line below.
-% This assumes an ICC profile to reside in the file (ISO Coated sb.icc),
-% unless the user modifies the corresponding line below.
-
-systemdict /ProcessColorModel known {
- systemdict /ProcessColorModel get dup /DeviceGray ne exch /DeviceCMYK ne and
+% First up, attempt to ensure the user has set ColorConversionStrategy correctly.
+% PDF/X-3 only permits Gray or CMYK in the output.
+%
+systemdict /ColorConversionStrategy known {
+ systemdict /ColorConversionStrategy get cvn dup /Gray ne exch /CMYK ne and
} {
+ (\nERROR: ColorConversionStrategy not set.)=
true
} ifelse
-{ (ERROR: ProcessColorModel must be /DeviceGray or /DeviceCMYK.)=
- /ProcessColorModel cvx /rangecheck signalerror
+{ (ERROR: ColorConversionStrategy must be /DeviceGray or /DeviceCMYK.)=
+ /ColorConversionStrategy cvx /rangecheck signalerror
} if
-% Define entries to the document Info dictionary :
+{
+ (ColorConversionStrategy must be set and be either Gray or CMYK for PDF/X-3 output.)=
+ /ColorConversionStrategy cvx /rangecheck signalerror
+}if
-/ICCProfile (ISO Coated sb.icc) def % Customize or remove.
+% Define entries in the document Info dictionary :
+%
[ /GTS_PDFXVersion (PDF/X-3:2002) % Must be so (the standard requires).
/Title (Title) % Customize.
/Trapped /False % Must be so (Ghostscript doesn't provide other).
- /DOCINFO pdfmark
+/DOCINFO pdfmark
-% Define an ICC profile :
+/ICCProfile (ISO Coated sb.icc) def % Customize or remove.
+
+% Define an ICC profile in the output, if the user specified one.
+%
currentdict /ICCProfile known {
[/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
- [{icc_PDFX} <</N systemdict /ProcessColorModel get /DeviceGray eq {1} {4} ifelse >> /PUT pdfmark
+
+% This code attempts to set the /N (number of components) key for the ICC colour space.
+% To do this it checks the ColorConversionStrategy or the device ProcessColorModel if
+% ColorConversionStrategy is not set.
+% This is not 100% reliable. A better solution is for the user to edit this and replace
+% the code between the ---8<--- lines with a simple declaration like:
+% /N 3
+% where the value of N is the number of components from the profile defined in /ICCProfile above.
+% Note, if you don't set ColorConversionStrategy, the output will likely be invalid anyway.
+ [{icc_PDFX} <<
+% ----------8<--------------8<-------------8<--------------8<----------
+ systemdict /ColorConversionStrategy known {
+ systemdict /ColorConversionStrategy get cvn dup /Gray eq {
+ pop /N 1 false
+ }{
+ dup /RGB eq {
+ (RGB is not a valid ColorConversionStrategy for PDF/X output)=
+ /ColorConversionStrategycvx /rangecheck signalerror
+ }{
+ /CMYK eq {
+ /N 4 false
+ }{
+ (ColorConversionStrategy not a device space, falling back to ProcessColorModel, output may not be valid PDF/X.)=
+ true
+ } ifelse
+ } ifelse
+ } ifelse
+ } {
+ (ColorConversionStrategy not set, falling back to ProcessColorModel, output may not be valid PDF/X.)=
+ true
+ } ifelse
+
+ {
+ currentpagedevice /ProcessColorModel get
+ dup /DeviceGray eq {
+ pop /N 1
+ }{
+ dup /DeviceRGB eq {
+ (RGB is not a valid ProcessColorModel for PDF/X output)=
+ /ColorConversionStrategycvx /rangecheck signalerror
+ }{
+ dup /DeviceCMYK eq {
+ pop /N 4
+ } {
+ (ProcessColorModel not a device space.)=
+ /ProcessColorModel cvx /rangecheck signalerror
+ } ifelse
+ } ifelse
+ } ifelse
+ } if
+% ----------8<--------------8<-------------8<--------------8<----------
+ >> /PUT pdfmark
[{icc_PDFX} ICCProfile (r) file /PUT pdfmark
} if