Convert Pdf file pages to Images with itextsharp

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

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

Have any idea how to convert each page in image file

回答1:

iText/iTextSharp can generate and/or modify existing PDFs but they do not perform any rendering which is what you are looking for. I would recommend checking out Ghostscript or some other library that knows how to actually render a PDF.



回答2:

you can use ImageMagick convert pdf to image

convert -density 300 "d:\1.pdf" -scale @1500000 "d:\a.jpg"

and split pdf can use itextsharp

here is the code from others.

void SplitePDF(string filepath)     {         iTextSharp.text.pdf.PdfReader reader = null;         int currentPage = 1;         int pageCount = 0;         //string filepath_New = filepath + "\\PDFDestination\\";          System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();         //byte[] arrayofPassword = encoding.GetBytes(ExistingFilePassword);         reader = new iTextSharp.text.pdf.PdfReader(filepath);         reader.RemoveUnusedObjects();         pageCount = reader.NumberOfPages;         string ext = System.IO.Path.GetExtension(filepath);         for (int i = 1; i 


回答3:

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]); } 


回答4:

you can extract Image from PDF and save as JPG here is the sample code you need Itext Sharp

 public IEnumerable ExtractImagesFromPDF(string sourcePdf)     {         // NOTE:  This will only get the first image it finds per page.         var pdf = new PdfReader(sourcePdf);         var raf = new RandomAccessFileOrArray(sourcePdf);          try         {             for (int pageNum = 1; pageNum 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!