You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ram Kumar <ra...@tbitsglobal.com> on 2018/05/03 07:03:58 UTC

PDFBOX 2.0.0 : PDF to Image conversion issue in JAVA 7

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

Re: PDFBOX 2.0.0 : PDF to Image conversion issue in JAVA 7

Posted by Tilman Hausherr <TH...@t-online.de>.
1) The current version is 2.0.9, not 2.0.0.
2) both versions will bring an error message that you don't have the 
jbig2 decoder. If you didn't see the error message then something is 
seriously wrong with your logging
3) if you used the pdfbox-app 2.0.9 then the jbig2 decoder is included
4) if not, then read https://pdfbox.apache.org/2.0/dependencies.html
5) in the future, be careful including confidential documents. (yours 
was stuck in moderation)

Tilman


Am 03.05.2018 um 09:03 schrieb Ram Kumar:
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org