Get page from pdf and save it in image file using itext

There is a pdf file, and I want to import the second page as an image and save it in a jpeg file. Is it possible and how to do this?

This is the code as I import the page:

Document document = new Document(); File file = File.createTempFile("", ""); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); final int backPage = 2; PdfReader reader = new PdfReader(pdf.getAbsolutePath()); PdfImportedPage importedPage = writer.getImportedPage(reader, backPage); com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(importedPage); 

Now I get an instance of image , but I don't know how to write it to a jpeg file.

+4
source share
2 answers

Appears (according to 1T3XT BVBA ), you can save only the iText image from the PDF page, not the bitmap. You can store it everywhere if you later use it on another PDF page ... otherwise you will have to use a tool like JPedal:

http://www.idrsolutions.com/convert-pdf-to-images/

=====================================

EDIT: maybe PDFBox can do this for you too !:

http://pdfbox.apache.org/commandlineutilities/PDFToImage.html

http://gal-levinsky.blogspot.it/2011/11/convert-pdf-to-image-via-pdfbox.html

+2
source

Image.getInstance (importedPage) does not allow (as you might assume) to designate the page as some kind of raster map, but simply creates a wrapper object to make it easier to add the imported page to another PDF file.

iText is not a PDF rendering tool, especially not an old version of com.lowagie. You can look at different products, for example. JPedal

+4
source

Source: https://habr.com/ru/post/1440300/


All Articles