如何使用ghostscript将PDF转换为PDF/A或PDF/X?
有没有办法使用 Ghostscript 将 PDF 转换为 PDF/A 或 PDF/X?我知道它可以用来将PDF转换为图像,但我不知道它是否可以用来转换PDF/A。我应该使用什么参数?
Is there a way to use ghostscript to convert PDF to PDF/A or PDF/X? I know it can be used to convert PDF to images, but I don't know if it can be used to convert PDF/A. What parameters should I use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要使用 Ghostscript 将非 PDF/A 文件转换为 PDF/A 文件,请运行:
gs -dPDFA -dBATCH -dNOPAUSE -dUseCIEColor -sProcessColorModel=DeviceCMYK -sDEVICE=pdfwrite -dPDFACompatibilityPolicy=1 -sOutputFile=output_filename。 pdf 输入文件名.pdf
To convert a non-PDF/A file into into a PDF/A file using Ghostscript, run:
gs -dPDFA -dBATCH -dNOPAUSE -dUseCIEColor -sProcessColorModel=DeviceCMYK -sDEVICE=pdfwrite -dPDFACompatibilityPolicy=1 -sOutputFile=output_filename.pdf input_filename.pdf
希望这个答案可以帮助来自 Google 的遇到同样问题的其他人:
要从 PDF 转换为 PDFA-1b 或 PDFA-2b,您可以使用 Ghostscript。我建议你使用最新版本(今天9.19)。
安装它
**In Mac OS**, you may prefer to use [Homebrew][1]:
(更新:2023-01-23。这不再适用于带有自制程序的 Mac,因为无论我尝试过什么,高于 9.19 的版本都将坚决拒绝进行转换)
在 Linux 中, 一些发行版带来了更旧的版本(rhel7 sports 9.07)。要下载完全独立的现代单文件 Ghostscript,请直接从网站下载:(
更新:2023-01-23:坚持该版本,较新的版本将无法使用下面提供的方法。
如果上面的链接20 年后尝试时已损坏,请参阅 Ghostscript.com 并搜索下载部分下载二进制版本,不要寻找源代码,除非您知道自己在做什么。
在 Windows 中,我无法帮助您,但如果您设法安装它,并且替换文件和 gs 可执行文件的位置,则以下命令也将起作用
。
(请注意未来的编辑者) 请不要删除格式,因为这是更易读且有效的命令行)
在 Mac 中
gs-919-linux_x86_64
将只是gs
请注意
。 output_file.pdf
和input_file.pdf
必须更改为输出文件(转换后的文件)和输入文件(要转换的文件)的名称。/path/to/PDFA_def.ps
是文件PDFA_def.ps
的副本。-dPDFA=1
适用于 PDFA-1b。-dPDFA=2
如果您想要 PDFA-2b。什么是
PDFA_def.ps
?PDFA_def.ps
是 Ghostscript 用来创建 PDFA 文件的某种模板。棘手的部分是,由于某种原因,ghostcript 附带了一个无法工作的文件。您需要编辑
PDFA_def.ps
并包含有效 ICC(颜色配置文件)文件的路径。从 Adobe 下载一个好的颜色配置文件:在该 zip 中,找到一个名为
AdobeRGB1998.icc
的文件,将其放在某个位置,然后将该文件的路径放入 PDFA_def.ps 文件中 。请注意,路径应该是绝对路径,不带引号。比如:这里是PDFA_def.ps的一个版本,将
PATH_TO_YOUR_ICC_FILE
更改为你的AdobeRGB1998.icc的路径。https://gist.githubusercontent.com/welton罗德里戈/19df77833f023fbe1572168982e4b515/原始/ ea86e87379d14120d7ff26f6f235ac7eeb5f5dd5/PDFA_def.ps
Hope this answer helps others coming from Google with the same problem:
To convert from PDF to PDFA-1b or PDFA-2b, you can use Ghostscript. I suggest you use the latest version (9.19 today).
Install it
**In Mac OS**, you may prefer to use [Homebrew][1]:
(UPDATE: 2023-01-23. This no longer works in mac with homebrew, as versions newer than 9.19 will adamantly refuse to do the conversion, no matter what I've tried)
In Linux, some distros bring a much older version (rhel7 sports 9.07). To download a fully independent modern one-file-only ghostscript, download it directly from the site:
(UPDATE: 2023-01-23: stick to that version, newer versions won't work with the method presented below.
If the link above is broken when you try it 20 years from now, please refer to ghostscript.com and search for download section. Download the binary version, don't go for the source, unless you know what you are doing.
In Windows, I cannot help you, but if you manage to install it, the following commands will also work, if you substitute the location of files and gs executable.
Command line
(note to future editors, please don't remove formatting, as this is more readable, yet working command line)
In Mac
gs-919-linux_x86_64
will be simplygs
.Please note that
output_file.pdf
andinput_file.pdf
must be changed to the names of the output file (the converted file) and the input file (the file to be converted)./path/to/PDFA_def.ps
is your copy of the filePDFA_def.ps
.-dPDFA=1
is for PDFA-1b.-dPDFA=2
if you want PDFA-2b.What is
PDFA_def.ps
?PDFA_def.ps
is some sort of template ghostscript uses to create a PDFA file. The tricky part is that, for some reason, ghostcript comes with a non-working file.You'll need to edit
PDFA_def.ps
and include the path to a valid ICC (color profile) file. Download a good color profile from Adobe:Inside that zip, find a file called
AdobeRGB1998.icc
, put it somewhere and put the path to that file INSIDE you PDFA_def.ps file. Note that the path should be absolute, with no quotes. Like:Here is a version of PDFA_def.ps, change
PATH_TO_YOUR_ICC_FILE
to the path of you AdobeRGB1998.icc.https://gist.githubusercontent.com/weltonrodrigo/19df77833f023fbe1572168982e4b515/raw/ea86e87379d14120d7ff26f6f235ac7eeb5f5dd5/PDFA_def.ps
请注意,当前的答案并不完全正确。您可以定义所需的 PDF/A 级别,从而导致程序的不同行为。这是正确的:
请注意更改:
-sPDFACompatibilityPolicy
(不正确,字符串)到-dPDFACompatibilityPolicy
(正确,数字)。将其更改为更高的数字以获得其他版本。如果您不需要 DOCINFO,则
-dPDFACompatibilityPolicy=1
很好。如果您使用上述以外的选项,您很可能会得到不兼容的 PDF/A(即使有不同的说明)。
要验证 PDF/A 合规性,请使用以下之一:
verapdf output_filename.pdf
Please note that current answers are not completely correct. You can define which level of PDF/A you want, resulting in different behaviors of the program. This one is correct:
Note the changes:
-sPDFACompatibilityPolicy
(incorrect, string) to-dPDFACompatibilityPolicy
(correct, numerical digit).Change it to a higher number to get other versions.
-dPDFACompatibilityPolicy=1
is good if you don't need DOCINFO.-UseDeviceIndependentColor
to avoid validating issues.If you use options other than what is stated above, you will most likely get a non compliant PDF/A (even if it is stated differently).
To verify PDF/A compliance, use one of:
verapdf output_filename.pdf
@danio、@imgen:即使是最近发布的有关 PDF/X(标准化印前要求)和 PDF/A(标准化归档要求)生成的文档页面也相当具有误导性。 (您的链接指向 v8.63 版本。)最后,它建议使用示例
PDF*_def.ps
运行示例命令行将已经生成有效的 PDF/A 和 PDF/X 文件。但是,他们没有!
下面是示例命令之一,它本身是正确的:
输出文件将声明本身为 PDF /A(大多数 PDF 查看器会很高兴地同意这一点),但输出文件未通过所有真正的合规性测试。
修复方法很简单:您需要编辑示例
PDFA_def.ps
(对于 PDF/X:您的PDFX_def.ps
)文件以匹配您的环境。旧的文档版本中没有明确说明这些所需的编辑,并且提供的命令表明它可以开箱即用。特别是在 PDF/X 的情况下,您必须指定要使用的有效 ICC 配置文件。
另请参阅有关此内容的更新文档(当前 SVN 主干版本):
@danio, @imgen: Even recently released documentation pages on PDF/X (standardized Prepress requirements) and PDF/A (standardized Archiving requirments) generation were quite misleading. (Your link pointed to a v8.63 release.) In the end, it suggested that running the example commandlines using the sample
PDF*_def.ps
would already generated valid PDF/A and PDF/X files.But, they do not!
Here is one of the sample commands, which by itself is correct:
The output file will declare itself to be PDF/A (and most PDF viewers would happily go along with this), but the output file fails all real compliance tests.
The fix is easy: you need to edit your sample
PDFA_def.ps
(for PDF/X: yourPDFX_def.ps
) files to match your environments. These required edits were not clearly spelled out in older documentation versions, and the provided command suggested it would work out of the box.Especially in case of PDF/X you MUST specifiy a valid ICC profile to use.
See also the updated documentation (current SVN trunk version) about this:
如果您使用的是 Windows 并且想要明确创建 PDF/A-1b 文档(PDFCreator 有 PDF/A-2b 的输出选项,但没有 PDF/A-1b 的输出选项),您只需将上述 Artur 参数输入到PDFCreator 的 ui 设置没有文档名称的设置。启动 PDFCreator,选择打印机菜单,然后转至设置。现在,从左侧的设置列表中选择
'Ghostscript'
。在“其他 Ghostscript 设置”
下,输入如下:单击
“保存”
,然后使用 PDFCreator 从 MS Word 或您想要的任何其他应用程序打印某些内容 - 它将是以 PDF/A-1b 格式创建。问候,
弗里茨
If you're using Windows and want to create PDF/A-1b documents explicitely (PDFCreator has an output option for PDF/A-2b but not for PDF/A-1b), you just can enter the parameters Artur described above into the ui settings of PDFCreator without the ones for the document names. Start PDFCreator, choose the printer menu, then go to settings. Now, choose
'Ghostscript'
from the settings list on the left side. Under'additional ghostscript settings'
, enter as follows :Click on
'Save'
, then print something from MS Word or any other application you want using the PDFCreator - it will be created in PDF/A-1b.Greetings,
Fritz