Hi Hugh,

this is a working solution for Java. You just have to convert it to C#.

if (img != null) {
        // scale if too big to fit on page
        if (img.getScaledWidth() > PageSize.A4.getWidth() || 
img.getScaledHeight() > PageSize.A4.getHeight()) {
 
                // if images have a different resolution (dpi value) for x 
and y the scaling considers it
                if(img.getDpiX() != 0 && img.getDpiY() != 0 && 
img.getDpiX() != img.getDpiY()){
                    img.scalePercent(100);
                        float percentX = (PageSize.A4.getWidth() * 100) / 
img.getScaledWidth();
                        float percentY = ( (PageSize.A4.getHeight() * 100) 
/ img.getScaledHeight() );
                        img.scalePercent(percentX, percentY);
                        img.setWidthPercentage(0);  
                }else{
                        // scaling the image if DPI values for x and y are 
the same 
                        // no customized scaling i.e. different values for 
x and y necessary
                        img.scaleToFit(PageSize.A4.getWidth(), PageSize.A4
.getHeight());
                }
        }
        .......// add scaled image to whereever you want it
}

Best regards
Benjamin



Von:    Gerold Krommer <gerold.krom...@rrdgds.at>
An:     Post all your questions about iText here 
<itext-questions@lists.sourceforge.net>
Datum:  13.12.2011 10:34
Betreff:        Re: [iText-questions] Converting Fax Tiff to PDF



204x196 dpi is the standard resolution for fax images here in Europe. The 
values are perfectly plausible and the unequal resolution in horizontal 
and vertical resolution is the cause 
of a lot of grief with many viewers
 
Kind regards,
 
/Gerold
 
 
Von: Hugh McLaughlin [mailto:h...@kmcnetwork.com] 
Gesendet: Dienstag, 13. Dezember 2011 03:44
An: Post all your questions about iText here
Betreff: Re: [iText-questions] Converting Fax Tiff to PDF
 
Thanks again for the response.  I’ve looked through the documentation and 
tried the following:
 
Dim img = iTextSharp.text.pdf.codec.TiffImage.GetTiffImage(tifArray, 
pageno)
 
Dim xValue As String = img.DpiX.ToString
 
Dim yValue As String = img.DpiY.ToString
 
I converted to string just to see what it returned.  However, it returned 
an x value of 204 and a y value of 196 which seems abnormally low and out 
of proportion.  I think I’m barking up the wrong tree but I didn’t find 
anything else that looked like it would return a dpi.
 
From: Paulo Soares [mailto:psoa...@glintt.com] 
Sent: Monday, December 12, 2011 2:00 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Converting Fax Tiff to PDF
 
You'll have to scale in both axis with different values. Use 
iTextSharp.text.pdf.codec.TiffImage. This will return an 
iTextSharp.text.Image with the right X and Y dpi information.
 
Paulo
 

From: Hugh McLaughlin [mailto:h...@kmcnetwork.com] 
Sent: Monday, December 12, 2011 5:33 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Converting Fax Tiff to PDF
Are you saying do without the line that scales the image?
 
From: Paulo Soares [mailto:psoa...@glintt.com] 
Sent: Monday, December 12, 2011 12:39 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Converting Fax Tiff to PDF
 
Load the image directly from the tiff or you'll lose the dpi information.
 
Paulo
 

From: Hugh McLaughlin [mailto:h...@kmcnetwork.com] 
Sent: Monday, December 12, 2011 5:15 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] Converting Fax Tiff to PDF
Hello Everyone and thanks for your help in advance.  I am developing an 
application with iTextSharp to transform inbound faxes to PDF files. 
However, when converted to PDF files, some of the faxes do not display 
properly, for example they appear shortened on the page and out of correct 
resolution.  All of the text appears, but squashed on the page.  It 
appears that my code does not properly account for various dpi settings of 
the inbound faxes, but I am unsure how to account for this.  Here is my 
code:
 
        ' creation of the document with a certain size and certain margins 
 
        Dim document As New 
iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0)
 
        ' creation of the different writers 
        Dim writer As iTextSharp.text.pdf.PdfWriter = 
iTextSharp.text.pdf.PdfWriter.GetInstance(document, New 
System.IO.FileStream(DestinationFile, System.IO.FileMode.Create))
 
        ' load the tiff image and count the total pages 
        Dim bm As New System.Drawing.Bitmap(SourceFile)
        Dim total As Integer = 
bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)
 
        document.Open()
        Dim cb As iTextSharp.text.pdf.PdfContentByte = 
writer.DirectContent
        For k As Integer = 0 To total - 1
 bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k)
            Dim img As iTextSharp.text.Image = 
iTextSharp.text.Image.GetInstance(bm, 
System.Drawing.Imaging.ImageFormat.Bmp)
            ' scale the image to fit in the page 
            img.ScalePercent(72.0F / img.DpiX * 100)
            img.SetAbsolutePosition(0, 0)
            cb.AddImage(img)
            document.NewPage()
        Next
        document.Close()
 
Any help would be greatly appreciated.
------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and 
improve service delivery. Take 5 minutes to use this Systems Optimization 
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a 
reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php





____________________________________________________________________

Viessmann IT Service GmbH
Geschäftsführer: Dirk Klöckner, Dr. Harald Dörnbach
Sitz der Gesellschaft: Allendorf (Eder) - Registergericht: 
AG Marburg (Lahn) - HRB 5324 - USt-IdNr.: DE258558424
____________________________________________________________________
------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and 
improve service delivery. Take 5 minutes to use this Systems Optimization 
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to