PDA

View Full Version : how to convert pdf to jpg.Any code sniplet?



blue_sky
11th December 2013, 18:46
I know how to convert jpg to pdf. but how the reverse is possible?
is there any way to get the size of Pdf? any native c++/c code?
please help?

ChrisW67
12th December 2013, 04:02
There is nothing Qt to read and manipulate PDF files.
Here are some open source libraries that do various things with PDFs: Poppler and PoDoFo
Of course, Adobe offer such tools also.

Susannamoore
1st September 2014, 10:23
Hi, did you find anything else that does the pdf-to-image conversion (http://www.pqscan.com/pdf-to-image/)?
As for converting pdf to jpg (http://www.pqscan.com/convert-pdf/to-jpg.shtml), I've used an open source project a while back to turn uploaded pdfs into images for use in an online catalog. Not sure whether it helps. You may have a check.

import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;


public byte[][] convert(byte[] pdf, String format) {

Document document = new Document();
try {
document.setByteArray(pdf, 0, pdf.length, null);

} catch (PDFException ex) {
System.out.println("Error parsing PDF document " + ex);
} catch (PDFSecurityException ex) {
System.out.println("Error encryption not supported " + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error file not found " + ex);
} catch (IOException ex) {
System.out.println("Error handling PDF document " + ex);
}
byte[][] imageArray = new byte[document.getNumberOfPages()][];
// save page captures to bytearray.
float scale = 1.75f;
float rotation = 0f;

// Paint each pages content to an image and write the image to file
for (int i = 0; i < document.getNumberOfPages(); i++) {
BufferedImage image = (BufferedImage)
document.getPageImage(i,
GraphicsRenderingHints.SCREEN,
Page.BOUNDARY_CROPBOX, rotation, scale);
try {
//get the picture util object
PictureUtilLocal pum = (PictureUtilLocal) Component
.getInstance("pictureUtil");
//load image into util
pum.loadBuffered(image);

//write image in desired format
imageArray[i] = pum.imageToByteArray(format, 1f);

System.out.println("\t capturing page " + i);

} catch (IOException e) {
e.printStackTrace();
}
image.flush();
}
// clean up resources
document.dispose();
return imageArray;
}

wysota
1st September 2014, 10:26
How is this non-C++ (Java?) code related to Qt?

newsuser_help
21st July 2016, 18:36
A c++ based open source library is xpdf: http://www.foolabs.com/xpdf/ and its free UI based software: http://pdf-to-jpg-convert.en.softonic.com