I am trying to convert a PDF document to a PNG image in my program. But at the moment, I have encountered some image size issues. My PDF is only 200 KB, but when I convert this PDF document into a PNG image in the program, the image size becomes 3M.
I don't know why there is such a big difference in file size. And I guess that i may need to reduce image size by adding image compression capability to my program. Or any other solutions, please advise.
This article on XsPDF.com is what you looking for, check out: PDF to Png convert high size image
Answers
If you just want to extract the pictures from PDF document and then save into PNG format, you can directly integrate XsPDF image extraction function in your program. Or you can save PDF in JPEG format because jpg overs compression as opposed to png. Of course, you can also recognize the original image format and use it directly when writing to disk.
// Create a PDF converter instance by loading a local file PdfImageConverter pdfConverter = new PdfImageConverter("sample.pdf"); for (int i = 0; i < pdfConverter.PageCount; i++) { // Convert pdf to png in customized image size Image pageImage = pdfConverter.PageToImage(i, 500, 800); // Save converted image to png format pageImage.Save("Page " + i + ".png", ImageFormat.Png); }
It's not so complicated. You can control the size of rendered png image directly during conversion. XsPDF provides some parameters for image size settings, such as DPI, image width, image height, etc.
PDF is usually much smaller than rendered images. Of course, if your PDF is just a picture, then the rendered PNG size is almost the same as PDF.