Python调用Ghostscript转PDF/A遇验证失败,求合规方案及版本指定方法
PDF转PDF/A的验证问题与版本指定疑问
我尝试通过Python子进程执行Ghostscript命令,将PDF文件转换为PDF/A归档格式,但生成的文件无法通过验证。当前使用的Ghostscript命令如下:
gs -dPDFA=3 -dBATCH -dNOPAUSE -dNOSAFER -sColorConversionStrategy=UseDeviceIndependentColor -sDEVICE=pdfwrite -dPDFACompatibilityPolicy=3 -dPDFACompatibilityLevel=3u -sOutputFile=dummypdfa.pdf dummy.pdf
虽然成功生成了dummypdfa.pdf,但该文件无法通过在线验证工具的检测。我刚接触Ghostscript,希望得到无需依赖REST API封装的转换方案。
补充:ICC配置文件对应的前缀代码
我使用的sRGB.icc配置文件对应的前缀PostScript代码如下:
%! % This is a sample prefix file for creating a PDF/A document. % 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 : [ /Title (Title) % Customise /DOCINFO pdfmark % Define an ICC profile : /ICCProfile (D:/scripts/2024/upwork/PDF2PDF-A/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} << %% ----------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 }{ (\tColorConversionStrategy not a device space, falling back to ProcessColorModel, output may not be valid PDF/A.\n)= true } ifelse } ifelse } ifelse } { (\tColorConversionStrategy not set, falling back to ProcessColorModel, output may not be valid PDF/A.\n)= true } ifelse { currentpagedevice /ProcessColorModel get dup /DeviceGray eq { pop /N 1 }{ dup /DeviceRGB eq { pop /N 3 }{ dup /DeviceCMYK eq { pop /N 4 } { (\tProcessColorModel not a device space.)= /ProcessColorModel cvx /rangecheck signalerror } ifelse } ifelse } ifelse } if %% ----------8<--------------8<-------------8<--------------8<---------- >> /PUT pdfmark [ {icc_PDFA} {ICCProfile (r) file} stopped { (\n\tFailed to open the supplied ICCProfile for reading. This may be due to\n) print (\t an incorrect filename or a failure to add --permit-file-read=<profile>\n) print (\t to the command line. This PostScript program needs to open the file\n) print (\t and you must explicitly grant it permission to do so.\n\n) print (\tPDF/A processing aborted, output may not be a PDF/A file.\n\n) print cleartomark } { /PUT pdfmark % Define the output intent dictionary : [/_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 >> /PUT pdfmark [{Catalog} << /OutputIntents [ {OutputIntent_PDFA} ] >> /PUT pdfmark } ifelse
额外疑问
是否可以通过Ghostscript指定转换为不同版本的PDF/A?比如PDF/A-1a、2a、2b、2u、3u这类具体版本?
内容的提问来源于stack exchange,提问作者John Kiruba
相关产品推荐
相关产品推荐

