Hi, 

 

We are trying to use iText Library for converting Fax TIFF images to
PDF. We are observing that with the following code snippet, the output
PDF page size matches the input TIFF page size but the image within the
PDF is shrunk by approx 1/4inch when compared to the input TIFF File. 

 

For example if the input TIFF file was 8.47in x 9.1in with a X DPI=204
and Y DPI = 196 with a printed image of 6in x 7in then the output PDF
produced has a page size of 8.47in x 9.1in (so far good) but the printed
image is shrunk to 6in x 6.75 in. 

 

What may be the possible reason for this shrinkage? How can this be
corrected? 

 

 

Code snip >>>>>

        if(inputFileName != null && inputFileName.length()!=0 ){^M

            Document document = new Document(PageSize.LETTER);^M

            FileOutputStream fop = null;^M

            PdfWriter writer = null;^M

            RandomAccessFileOrArray ra = null;^M

            try {^M

                int numOfPages = 0;^M

                float heightInInches = 0;^M

                float widthInInches = 0;^M

                float xPoints = 0;^M

                float yPoints = 0;^M

                ^M

                fop = new FileOutputStream(outFileName);^M

                writer = PdfWriter.getInstance(document,fop);^M

                document.open();^M

                PdfContentByte cb = writer.getDirectContent();^M

                ra = new RandomAccessFileOrArray(inputFileName);^M

                numOfPages = TiffImage.getNumberOfPages(ra);^M

                for (int page = 0; page < numOfPages; ++page) {^M

                    Image img = TiffImage.getTiffImage(ra, page + 1);^M

                    if (img != null) {^M

                        heightInInches =
img.getHeight()/img.getDpiY();^M

                        widthInInches = img.getWidth()/img.getDpiX();^M

                        //iText uses a 72 points per inch scale. ^M

                        xPoints = widthInInches*72;^M

                        yPoints = heightInInches*72;^M

                        document.setPageSize(new Rectangle(xPoints,
yPoints));^M

                        document.setMargins(0, 0, 0, 0);^M

                        document.newPage();^M

                        img.scaleToFit(xPoints,yPoints);^M

                        img.setAbsolutePosition(0,0);
^M

                        cb.addImage(img);^M

                    }^M

                }                   ^M

 

Code snip >>>>>

 

Thanks in advance....

 

 

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to