PDFbox- not able to write images in pdf | Community
Skip to main content
varuns46785756
New Participant
March 4, 2016
Solved

PDFbox- not able to write images in pdf

  • March 4, 2016
  • 9 replies
  • 6149 views

Hi,

I am using PDFbox for generating pdf by my webpage, I have images in my webpage and I am trying to download the all images as a pdf file(single), but I am not able to write the images in pdf , I am getting corrupted pdf file.

I am storing all the image path in json and getting path from json one by one

Please let me know how can i convert images in pdf file.

 

Regards,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by varuns46785756

thanks Kautuk,

yes this is PDFbox issue not AEM , pdfbox not supporting all the features , I have tried with itextpdf and its working fine.

 

 

Regards

9 replies

varuns46785756
varuns46785756AuthorAccepted solution
New Participant
March 31, 2016

thanks Kautuk,

yes this is PDFbox issue not AEM , pdfbox not supporting all the features , I have tried with itextpdf and its working fine.

 

 

Regards

kautuk_sahni
Employee
March 29, 2016

varuns46785756 wrote...

Hi Kautuk ,

I have tried the code, its getting incorrect image format .

 

Regards,

 


Hi Varun

I would like you to please check this with PDFBox's Support team. As it is related to PDFBox not that to AEM.

They would be in better position to help you.

Link:- https://pdfbox.apache.org/mailinglists.html

Link:- https://pdfbox.apache.org/support.html

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
varuns46785756
New Participant
March 29, 2016

Hi Kautuk ,

I have tried the code, its getting incorrect image format .

 

Regards,

varuns46785756
New Participant
March 29, 2016

Hi Scott,

code is not working outside AEM also, this pdfbox issue only.

 

 

Regards,

kautuk_sahni
Employee
March 15, 2016

Hi

As mentioned by Scott, please if code is working fine outside the AEM environment.

Please have a look at these couple of articles:-

Link:- https://stackoverflow.com/questions/35751150/print-byte-to-pdf-using-pdfbox

//

 final byte[] image = ... // your codeByteArrayInputStream bais = new ByteArrayInputStream(image);BufferedImage bim = ImageIO.read(bais);PDImageXObject pdImage = LosslessFactory.createFromImage(doc, bim);

 

Read more from the article.

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
smacdonald2008
New Participant
March 14, 2016

Does your PDFBOX code work outside of AEM? If you are having problems wiht PDFBox code - i would ask that community:

https://pdfbox.apache.org/support.html

THis sounds like a PDFBox issue - not an AEM issue. 

varuns46785756
New Participant
March 14, 2016

thanks for response,but I am getting number of images in response in ByteArrayInputStreamand trying to get the images from ByteArrayInputStream in PDF but format of the image not proper.Please check the attached code.

kautuk_sahni
Employee
March 7, 2016

Hi

Adding to what scott has mentioned,

Please refer to the article :- http://stackoverflow.com/questions/22358478/java-create-pdf-pages-from-images-using-pdfbox-library

// Create PDF pages from images using PDFBox library

PDDocument document = new PDDocument();InputStream in = new FileInputStream(someImage);BufferedImage bimg = ImageIO.read(in);float width = bimg.getWidth();float height = bimg.getHeight();PDPage page = new PDPage(new PDRectangle(width, height));document.addPage(page);PDXObjectImage img = new PDJpeg(document, new FileInputStream(someImage));PDPageContentStream contentStream = new PDPageContentStream(document, page);contentStream.drawImage(img, 0, 0);contentStream.close();in.close();document.save("test.pdf");document.close();

 

Link:- http://stackoverflow.com/questions/8521290/cant-add-an-image-to-a-pdf-using-pdfbox

// Add an image to a pdf using PDFBox

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
smacdonald2008
New Participant
March 4, 2016

I recommend trying to get PDFBOX code to work outside of AEM. This stackoverflow thread will help you: 

http://stackoverflow.com/questions/8521290/cant-add-an-image-to-a-pdf-using-pdfbox