簡體   English   中英

Ghostscript Multipage PDF到PNG

[英]Ghostscript Multipage PDF to 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
            };

我最終在“OutputFile”參數中添加了“%d”,以便每頁生成一個文件。 然后我只是閱讀所有文件並將它們拼接在我的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
}

如果你可以使用ImageMagick,你可以使用它的一個好命令:

montage -mode Concatenate -tile 1x -density 144 -type Grayscale input.pdf output.png

哪里

  • -density 144以dpi確定分辨率,如果需要增加它,默認值為72
  • -type Grayscale使用它,如果您的PDF沒有顏色,您將在生成的圖像中保存一些KB

首先檢查輸出設備選項; 但我不認為有這樣的選擇。

最有可能你需要自己做一些拼版,要么讓GhostScript這樣做(你必須編寫一個PostScript程序),要么用ImageMagick或類似東西拼接生成的渲染頁面。

如果您想嘗試PostScript路由(可能是最有效的),請檢查GhostScript包中包含的N-up示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM