简体   繁体   中英

Why are some images cropped in pdfs?

Itextpdf crops some images when they are added to a Pdf document.

I have written a demo showing the problem ( https://github.com/buda-base/buda-iiif-server/blob/master/src/test/java/io/bdrc/iiif/PDFBugDemo.java ) using the following pom and the this image: ( https://github.com/buda-base/buda-iiif-server/blob/master/src/test/resources/test.tif )

The demo code produces two different files from the same image using itext7 and Apache PdfBox. The expected output is that which is produced by PdfBox. Itext7 obviously crops the original image. This doesn't occur all the times and I suspect a specific issue with tif files.

Files are here for Itext7 ( https://drive.google.com/open?id=16oUhSnhbW4QWiYn2aFPsKp3xA0__yd3B ) and for the pdfBox( https://drive.google.com/open?id=1My_-EM27VARKDBgM5tMig7FkYlTWtflG )

As a matter of fact the issue is coming from PDFDocument default margins values. Thanks to Tilman Hausherr I was able to solve the problem by doing the following, before adding the images to the doc/page :

PdfWriter writer = new PdfWriter("testPdfItext.pdf", new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0));
        PdfDocument pdfDocument = new PdfDocument(writer);
        Document document = new Document(pdfDocument);
        document.setMargins(0, 0, 0, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM