You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Julien Keruzec (JIRA)" <ji...@apache.org> on 2017/04/05 12:22:41 UTC
[jira] [Commented] (PDFBOX-3744) Can't see images on PDF when using
ByteArrayOutputStream
[ https://issues.apache.org/jira/browse/PDFBOX-3744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15956762#comment-15956762 ]
Julien Keruzec commented on PDFBOX-3744:
----------------------------------------
I resolve the problem. Problem was that PDF was return in a POST HTTP request (Spring framework Rest controller), I think post was modifying the PDF somehow ...
I change it for GET request and PDF is well displayed.
Sorry for disturbance..
Regards,
> Can't see images on PDF when using ByteArrayOutputStream
> --------------------------------------------------------
>
> Key: PDFBOX-3744
> URL: https://issues.apache.org/jira/browse/PDFBOX-3744
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.5
> Environment: Windows 10 / Linux Centos 6 / Tomcat 8 / Java 8
> Reporter: Julien Keruzec
> Attachments: test.pdf
>
>
> Hello,
> I have a problem generating a PDF file with an image of a QRCode in JPEG format.
> When I generate the PDF on file system everyting is fine. PDF is displaying all pages with all QR Code images in it.
> As soon as I want to use Outputstream / InputStream my generated PDF result in a blank page and I can't see my image anymore.
> You will find an example of a PDF with no image displayed in attachement
> Same thing occured with V1.8.9 of PDFBOX.
> Here's the code I use :
> My images come from a list of InputStream
> {code:java}
> List<InputStream> images
> {code}
> {code:java}
> InputStream is = null;
> ByteArrayOutputStream os = new ByteArrayOutputStream();
> try {
> PDDocument document = new PDDocument();
> for (InputStream image : images) {
> this.addImageToPDF(document, image, width, height);
> }
> // File f = new File(System.getProperty("java.io.tmpdir") + File.pathSeparator + "test.pdf");
> // document.save(f);
> document.save(os);
> document.close();
>
> is = new ByteArrayInputStream(os.toByteArray());
> {code}
> Generation of page :
> {code:java}
> protected void addImageToPDF(PDDocument document, InputStream image, int width, int height) throws IOException {
> PDRectangle pageFormat = null;
> PDPage page = new PDPage();
> PDImageXObject ximage = null;
> ximage = JPEGFactory.createFromStream(document, image);
> if(ximage.getWidth() > ximage.getHeight()){
> pageFormat = new PDRectangle(height,width);
> pageWidthWithMargin = height - 20;
> pageHeightWithMargin = width - 20;
> }
> else{
> pageFormat = new PDRectangle(width,height);
> pageWidthWithMargin = width - 20;
> pageHeightWithMargin = height - 20;
> }
> page.setMediaBox(pageFormat);
> document.addPage(page);
> PDPageContentStream contentStream = new PDPageContentStream(document, page);
> float scale = getScale(ximage);
> contentStream.drawImage(ximage, 10, (pageHeightWithMargin+10) - ximage.getHeight()*scale,
> ximage.getWidth()*scale, ximage.getHeight()*scale);
> contentStream.close();
> }
> {code}
> Can anyone help me on this ?
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org