pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ram Kumar <ra...@tbitsglobal.com>
Subject PDFBOX 2.0.0 : PDF to Image conversion issue in JAVA 7
Date Thu, 03 May 2018 07:03:58 GMT
Dear All,

I want to convert a PDF page to the image file. The text is missing when I
convert a PDF page to image using java.
Please help me to resolve this issue.


The sample file enclosed in attachments and code is as follows -

public void pdfToImageConvertorUsingPdfBox(String inputPdfPath) throws
Exception {
File sourceFile = new File(inputPdfPath);
String formatName = "png";
if (sourceFile.exists()) {
PDDocument document = PDDocument.load(sourceFile);
PDFRenderer pdfRenderer = new PDFRenderer(document);
int count = document.getNumberOfPages();

for (int i = 0; i < count; i++) {
BufferedImage image = pdfRenderer.renderImageWithDPI(i, 200, ImageType.RGB);
String output = FilenameUtils.removeExtension(inputPdfPath) + "_" + (i + 1)
+ "." + formatName;
ImageIO.write(image, formatName, new File(output));
}
document.close();
} else {
logger.error(sourceFile.getName() + " File not exists");
}
}


Best Regards,
Ram Kumar

Mime
View raw message