You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2018/04/02 19:01:00 UTC

[jira] [Comment Edited] (PDFBOX-4177) PDFBox seems to scale up image while it should not

    [ https://issues.apache.org/jira/browse/PDFBOX-4177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16422980#comment-16422980 ] 

Tilman Hausherr edited comment on PDFBOX-4177 at 4/2/18 7:00 PM:
-----------------------------------------------------------------

What happens is also a misunderstanding that is difficult to explain. 1 unit is 1/72 inch. So your image would look good if the PDF would be displayed at 72dpi, which is what PDFDebugger does but Adobe doesn't (and neither does the windows default viewer, but IrfanView does). If you want your image to be small at the display resolution of your screen, you'll have to transform the current transformation matrix or use the size paramaters before showing your image. See the source Code comment in ImageToPDF:
{code:java}
                // draw the image at full size at (x=20, y=20)
                contents.drawImage(pdImage, 20, 20);
                
                // to draw the image at half size at (x=20, y=20) use
                // contents.drawImage(pdImage, 20, 20, pdImage.getWidth() / 2, pdImage.getHeight() / 2); 
{code}


was (Author: tilman):
What happens is also a misunderstanding that is difficult to explain. 1 unit is 1/72 inch. So your image would look good if the PDF would be displayed at 72dpi, which is what PDFDebugger does but Adobe doesn't (and neither does the windows default viewer, but IrfanView does). If you want your image to be small at the display resolution of your screen, you'll have to transform the current tranaformation matrix before showing your image. See the source Code comment in ImageToPDF:
{code:java}
                // draw the image at full size at (x=20, y=20)
                contents.drawImage(pdImage, 20, 20);
                
                // to draw the image at half size at (x=20, y=20) use
                // contents.drawImage(pdImage, 20, 20, pdImage.getWidth() / 2, pdImage.getHeight() / 2); 
{code}

> PDFBox seems to scale up image while it should not
> --------------------------------------------------
>
>                 Key: PDFBOX-4177
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4177
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Kamil
>            Priority: Major
>         Attachments: comparison-tilman.png, comparison.png, test.jpg, test.pdf
>
>
> I have a test image (in attachment) and the following code:
> {code:java}
>   public static void main(String[] args) {
>     final String filename = "test.jpg";
>     try (
>         final PDDocument doc = new PDDocument();
>         final FileInputStream input = new FileInputStream(new File(filename));
>         final ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
>         final FileOutputStream output = new FileOutputStream("test.pdf")
>     ) {
>       final PDImageXObject jpeg = PDImageXObject.createFromByteArray(doc, IOUtils.toByteArray(input), filename);
>       final PDPage page = new PDPage(new PDRectangle(jpeg.getWidth(), jpeg.getHeight()));
>       doc.addPage(page);
>       try (final PDPageContentStream contents = new PDPageContentStream(doc, page)) {
>         contents.drawImage(jpeg, 0, 0);
>       }
>       doc.save(pdfOut);
>       pdfOut.flush();
>       IOUtils.write(pdfOut.toByteArray(), output);
>     }catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> {code}
> The image in test.pdf is double sized (and quality is worse) than in original image



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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