我一直在使用 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
};
我最终将“%d”添加到“OutputFile”参数中,以便它每页生成一个文件。然后我读取所有文件并将它们用我的 C# 代码拼接在一起,如下所示:
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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)