You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andreas Lehmkuehler <an...@lehmi.de> on 2012/09/16 17:37:56 UTC

Re: Problem with multiple images on a page

Hi,

Am 02.08.2012 20:30, schrieb Stefano Linguerri:
> I'm new to PdfBox,
>
> I'm having trouble adding multiple images on a PDPage
PDFBOX-1394 [1] addresses and solves this issue.


BR
Andreas Lehmkühler

[1] https://issues.apache.org/jira/browse/PDFBOX-1394


> This is the method that adds images:
> [...]
>   private void addImage(PDDocument document, PDPage page, String
> imageName, int x, int y) throws IOException {
>          System.out.println("Image Name: " + imageName);
>
>          PDXObjectImage image = new PDJpeg(document, new
> FileInputStream(imageName));
>          PDPageContentStream contentStream = new
> PDPageContentStream(document, page, true, false);
>          int oldWidth = 200;
>          int oldHeight = 300;
>          int newWidth = 150;
>          int newHeight = (newWidth * oldHeight) / oldWidth;
>          image.setHeight(newHeight);
>          image.setWidth(newWidth);
>          contentStream.drawImage(image, x, y);
>          contentStream.close();
>      }
> [...]t
>
> even if the image name changes only the first image is repeatedly drawn on page.
>
> and If I move the line:
>         PDXObjectImage image = new PDJpeg(document, new
> FileInputStream(imageName));
> after
>         PDPageContentStream contentStream = new
> PDPageContentStream(document, page, true, false);
>
> the resulting page is blank.
>
> thanks in advance,
> Stefano
>