Convert Pdf file pages to Images with itextsharp

后端 未结 4 1116
南方客
南方客 2020-11-30 09:48

I want to convert Pdf pages in Images using ItextSharp lib.

Have any idea how to convert each page in image file

4条回答
  •  臣服心动
    2020-11-30 10:38

    You can use Ghostscript to convert the PDF files into Images, I used the following parameters to convert the needed PDF into tiff image with multiple frames :

    gswin32c.exe   -sDEVICE=tiff12nc -dBATCH -r200 -dNOPAUSE  -sOutputFile=[Output].tiff [PDF FileName]
    

    Also you can use the -q parameter for silent mode You can get more information about its output devices from here

    After that I can easily load the tiff frames like the following

    using (FileStream stream = new FileStream(@"C:\tEMP\image_$i.tiff", FileMode.Open, FileAccess.Read, FileShare.Read))
    {
        BitmapDecoder dec = BitmapDecoder.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
        BitmapEncoder enc = BitmapEncoder.Create(dec.CodecInfo.ContainerFormat);
        enc.Frames.Add(dec.Frames[frameIndex]);
    }
    

提交回复
热议问题