Ghostscript多页PDF转换为PNG [英] Ghostscript Multipage PDF to PNG
问题描述
我一直在使用ghostscript做pdf来从pdf生成单个页面的图像.现在,我需要能够从pdf中提取多个页面并产生一个长的垂直图像.
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?
到目前为止,当我调用ghostscript时,我正在使用以下参数:
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
};
推荐答案
我最终在"OutputFile"参数中添加了%d",以便每页生成一个文件.然后,我只是读取了所有文件,并用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:
var images =pdf.GetPreview(1,8); //All of the individual images read in one per file
using (Bitmap b = new Bitmap(images[0].Width, images.Sum(img=>img.Height))) {
using (var g = Graphics.FromImage(b)) {
for (int i = 0; i < images.Count; i++) {
g.DrawImageUnscaled(images[i], 0, images.Take(i).Sum(img=>img.Height));
}
}
//Do Stuff
}
这篇关于Ghostscript多页PDF转换为PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!