You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Kevin Tabary (JIRA)" <ji...@apache.org> on 2017/12/15 10:22:00 UTC

[jira] [Created] (PDFBOX-4037) Appending an image to an already existing PDF does not preserve image size

Kevin Tabary created PDFBOX-4037:
------------------------------------

             Summary: Appending an image to an already existing PDF does not preserve image size
                 Key: PDFBOX-4037
                 URL: https://issues.apache.org/jira/browse/PDFBOX-4037
             Project: PDFBox
          Issue Type: Bug
    Affects Versions: 2.0.8
            Reporter: Kevin Tabary
         Attachments: after_rendering.PNG, signature.png

Given an already existing document on which I want to append a small image at position (0;0) on the first page, when saving the PDF, the image appears somehow bigger than its original size.
Please find below the code I am using:

{code}
	public void mergePdfWithImages(MultipartFile pdf, MultipartFile image) throws Exception {
		PDDocument pdfDocument = PDDocument.load(pdf.getInputStream());
		PDPage pdfPage = pdfDocument.getPage(0);
		PDImageXObject pdfImage = PDImageXObject.createFromByteArray(pdfDocument, image.getBytes(), null);
		PDPageContentStream pageContentStream = new PDPageContentStream(pdfDocument, pdfPage, PDPageContentStream.AppendMode.APPEND, true, true);
		pageContentStream.drawImage(pdfImage, 0, 0);
		pageContentStream.close();
		pdfDocument.save("C:\\Data\\result.pdf");
		pdfDocument.close();
	}
{code}

I tried to set the flag compress / resetContext to any combination of true/false without any success. Please find the image (signature.png) I am using as well as the comparison after the PDF is rendered (afrer_rendering.png): the image appended on it is clearly bigger than its original size, is there any way to  preserve original size ?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org