Ghostscript Multipage PDF to PNG

后端 未结 3 1164
礼貌的吻别
礼貌的吻别 2021-02-01 21:28

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

相关标签:
3条回答
  • 2021-02-01 21:56

    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.

    0 讨论(0)
  • 2021-02-01 22:07

    If you can use ImageMagick, you could use one of its good commands:

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

    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
    0 讨论(0)
  • 2021-02-01 22:09

    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
    }
    
    0 讨论(0)
提交回复
热议问题