Skip to main content
varuns46785756
Level 5
Mar 4, 2016 11:04 AM UTC
Solved

PDFbox- not able to write images in pdf

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.
varuns46785756
varuns46785756Accepted solution
Level 5
Mar 31, 2016 5:10 AM UTC

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

smacdonald2008
Level 10
Mar 4, 2016 3:18 PM UTC

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

Translate
kautuk_sahni
Level 9
Mar 7, 2016 9:09 AM UTC

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

Translate
Kautuk Sahni
varuns46785756
Level 5
Mar 14, 2016 3:38 PM UTC

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.

Translate
smacdonald2008
Level 10
Mar 14, 2016 4:32 PM UTC

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. 

Translate
kautuk_sahni
Level 9
Mar 15, 2016 4:59 AM UTC

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

Translate
Kautuk Sahni
varuns46785756
Level 5
Mar 29, 2016 4:17 AM UTC

Hi Scott,

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

 

 

Regards,

Translate
varuns46785756
Level 5
Mar 29, 2016 4:18 AM UTC

Hi Kautuk ,

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

 

Regards,

Translate
kautuk_sahni
Level 9
Mar 29, 2016 4:26 AM UTC

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

Translate
Kautuk Sahni
varuns46785756
varuns46785756AuthorAccepted solution
Level 5
Mar 31, 2016 5:10 AM UTC

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

Translate