Ghostscript 多页 PDF 转 PNG
我一直在使用 Ghostscript 从 pdf 中生成单个页面的 pdf 图像。 现在我需要能够从 pdf 中提取多个页面并生成一个长垂直图像。
我是否缺少一个可以允许这样做的论点?
到目前为止,当我调用 Ghostscript 时,我使用以下参数:
string[] args ={
"-q",
"-dQUIET",
"-dPARANOIDSAFER", // Run this command in safe mode
"-dBATCH", // Keep gs from going into interactive mode
"-dNOPAUSE", // Do not prompt and pause for each page
"-dNOPROMPT", // Disable prompts for user interaction
"-dFirstPage="+start,
"-dLastPage="+stop,
"-sDEVICE=png16m",
"-dTextAlphaBits=4",
"-dGraphicsAlphaBits=4",
"-r300x300",
// Set the input and output files
String.Format("-sOutputFile={0}", tempFile),
originalPdfFile
};
I've been using ghostscript to do pdf to image generation of a single page from the pdf. Now I need to be able to pull multiple pages from the pdf and produce a long vertical image.
Is there an argument that I'm missing that would allow this?
So far I'm using the following arguments when I call out to ghostscript:
string[] args ={
"-q",
"-dQUIET",
"-dPARANOIDSAFER", // Run this command in safe mode
"-dBATCH", // Keep gs from going into interactive mode
"-dNOPAUSE", // Do not prompt and pause for each page
"-dNOPROMPT", // Disable prompts for user interaction
"-dFirstPage="+start,
"-dLastPage="+stop,
"-sDEVICE=png16m",
"-dTextAlphaBits=4",
"-dGraphicsAlphaBits=4",
"-r300x300",
// Set the input and output files
String.Format("-sOutputFile={0}", tempFile),
originalPdfFile
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终将“%d”添加到“OutputFile”参数中,以便它每页生成一个文件。 然后我读取所有文件并将它们用我的 C# 代码拼接在一起,如下所示:
I ended up adding "%d" to the "OutputFile" parameter so that it would generate one file per page. Then I just read up all of the files and stitched them together in my c# code like so:
如果您可以使用 ImageMagick,则可以使用它的一个好命令:
其中
-密度 144
确定以 dpi 为单位的分辨率,如果需要,请增加它,默认值为 72-type Grayscale
使用如果您的 PDF 没有颜色,您将在生成的图像中节省一些 KBIf you can use ImageMagick, you could use one of its good commands:
where
-density 144
determins resolution in dpi, increase it if needed, default is 72-type Grayscale
use it if your PDF has no colors, you'll save some KBs in the resulting image首先检查输出设备选项; 但我认为没有其他选择。
最有可能的是,您需要自己进行一些拼版,要么让 GhostScript 来做(您必须编写 PostScript 程序),要么用 ImageMagick 或类似的东西缝合生成的渲染页面。
如果您想尝试 PostScript 路线(可能是最有效的),请检查 GhostScript 包中包含的 N-up 示例。
First check the output device options; but I don't think there's an option for that.
Most probably you'll need to do some imposition yourself, either make GhostScript do it (you'll have to write a PostScript program), or stitch the resulting rendered pages with ImageMagick or something similar.
If you want to try the PostScript route (likely to be the most efficient), check the N-up examples included in the GhostScript package.