[
https://issues.apache.org/jira/browse/PDFBOX-3744?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julien Keruzec updated PDFBOX-3744:
-----------------------------------
Attachment: test.pdf
> 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 displayed
> all pages with all QC 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.
> 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) 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(PAGE_HEIGHT,PAGE_WIDTH);
> pageWidthWithMargin = PAGE_HEIGHT - 20;
> pageHeightWithMargin = PAGE_WIDTH - 20;
> }
> else{
> pageFormat = new PDRectangle(PAGE_WIDTH,PAGE_HEIGHT);
> pageWidthWithMargin = PAGE_WIDTH - 20;
> pageHeightWithMargin = PAGE_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: [email protected]
For additional commands, e-mail: [email protected]