public String convertPdfPagesToImages(File file, String outputImageDir)
{
PDDocument document = null;
try
{
document = PDDocument.load(file);
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page < document.getNumberOfPages(); ++page)
{
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300,ImageType.RGB);
ImageIOUtil.writeImage(bim, page+"- output.jpg", 300);
}
document.close();
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
return "";
}
- I am using above code to convert pdf pages to image. With 300 dpi. I came up with relation between x and y coordinates of pdf text and text marked in image. Xim= Xpdf*dpi/72; Yim= [Ypdf-(Hpdfpage/96)]*dpi/72; which seems to be working perfectly fine. However,not able to get relation of height and width of rectangle marked in image to that in pdf page. Could anyone help me with this? I am using pdfbox2.0.0 library.