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,
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Hi Scott,
code is not working outside AEM also, this pdfbox issue only.
Regards,
Views
Replies
Total Likes
Hi Kautuk ,
I have tried the code, its getting incorrect image format .
Regards,
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies