The sizes in inches of the images are:

image 2 - 9.125 x 5.01
image 4 - 0.52 x 0.43

Those dimensions are correct in the PDF. What dimensions do you get in your
tools?

----- Original Message ----- 
From: "Domenick Lacertosa" <[EMAIL PROTECTED]>
To: <itext-questions@lists.sourceforge.net>
Sent: Wednesday, January 12, 2005 8:16 PM
Subject: RE: [iText-questions] Problems Trying to Preserve Image Size when
Inserting Images in a PDF Document


Let me back up a step, and I'll try to clear up the confusion by
starting from the beginning.  First, completely throw out anything that
has to do with 5.bmp.  There is no dpi information for that image.

I created 2 images in Photoshop:

http://www.atlanticshore.com/lowagie/2.bmp
657x361 @ 72 dpi

http://www.atlanticshore.com/lowagie/4.bmp
156x129 @ 300 dpi

I create a com.lowagie.text.Image (called myImage) from those files.
Then, the following is executed:

myImage.scalePercent(getScalePercent(myImage.getDpiX()),
getScalePercent(myImage.getDpiY()));

And the getScalePercent method is below:

private static float getScalePercent(int dpi) {
        if (dpi > 0)
            return ((72f / (float)dpi) * 100f);

        return 100f;
}

After those images are added to the document, neither of them appear to
be the same size in the pdf document as the actual image on disk.  The
first one appears too big, and the second one appears too small.

For each image, the myImage.getDpiX is returning the correct dpi, the
myImage.getDpiY is returning the correct dpi, Photoshop shows the dpi
correctly, and viewing the image properties in Windows shows the correct
dpi.

I am convinced that the dpi is set correctly for the images.  Any other
ideas?

- Dom



-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 12, 2005 2:47 PM
To: Domenick Lacertosa; itext-questions@lists.sourceforge.net
Subject: Re: [iText-questions] Problems Trying to Preserve Image Size
when Inserting Images in a PDF Document


The confusion goes on. The scaling is correct as far as the pdf goes.
The dpis you are supplying are wrong. If it works for image 5 why
wouldn't it work for the others?

----- Original Message ----- 
From: "Domenick Lacertosa" <[EMAIL PROTECTED]>
To: <itext-questions@lists.sourceforge.net>
Sent: Wednesday, January 12, 2005 7:30 PM
Subject: RE: [iText-questions] Problems Trying to Preserve Image Size
when Inserting Images in a PDF Document


I understand there is some confusion.  To remove the confusion, with the
2 images where the DPI is available and correct (2.bmp - 71dpi and 4.bmp
- 299 dpi), the function below:

private static float getScalePercent(int dpi) {
        if (dpi > 0)
            return ((72f / (float)dpi) * 100f);

        return 100f;
}

causes results where the first image (2.bmp) is about 33% bigger than it
should be after scaling, and the second image (4.bmp) comes out about
1/4 of the size it should be after scaling.  Without scaling them, the
sizes are incorrect as well.  From all of the documentation that I have
read, the above function should work fine, but it doesn't seem to.  Any
ideas why, or am I missing something conceptually?

Thanks again,
Dom


-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 12, 2005 2:19 PM
To: Domenick Lacertosa; itext-questions@lists.sourceforge.net
Subject: Re: [iText-questions] Problems Trying to Preserve Image Size
when Inserting Images in a PDF Document


There's a confusion here somewhere. If the dpi inside the image don't
match the image size there's nothing iText can do.

----- Original Message ----- 
From: "Domenick Lacertosa" <[EMAIL PROTECTED]>
To: <itext-questions@lists.sourceforge.net>
Sent: Wednesday, January 12, 2005 6:09 PM
Subject: RE: [iText-questions] Problems Trying to Preserve Image Size
when Inserting Images in a PDF Document


When using that updated getScalePercent() method that you wrote below,
only the last image is coming up the correct size.  For that last image
(image 5) the dpi information is not available for some reason, but I
know it is 96, which is why I hard coded the 96 in the call to
getScalePercent for image 5.  The first image now displays is about 25%
bigger than it actually is, and the second one is about 1/3 of the size
it should be.  I am still having problems understanding how it should
work.  Thanks in advance.

 -----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 12, 2005 12:58 PM
To: Domenick Lacertosa; itext-questions@lists.sourceforge.net
Subject: RE: [iText-questions] Problems Trying to Preserve Image Size
when Inserting Images in a PDF Document



I don't see any problem with it if you set the dpi calculation
as:

    private static float getScalePercent(int dpi) {
        if (dpi > 0)
            return ((72f / (float)dpi) * 100f);

        return 100f;
    }

Note the 5.bmp doesn't have any dpi information in it.
If the size is not correct you should look for the problem in the
scanner or in the printer or the options in the print dialog.


  _____

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Domenick Lacertosa
Sent: Wednesday, January 12, 2005 5:16 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] Problems Trying to Preserve
Image Size when Inserting Images in a PDF Document


I am trying to insert images into a pdf document, while
trying to preserve the size of the image.  I would like the image to
display in the pdf (while viewing at 100%) to match the exact size of
the original image.  I am using dpi's to calculate the scalepercent, but
my calculation seems incorrect.  Can anyone explain to me how to
preserve the exact size of the image while viewing the pdf.  Thanks in
advance.

My code is below.  To execute, change the pathForIO
string variable, and download the following files and place them in that
directory:

http://www.atlanticshore.com/lowagie/2.bmp
657x361 @ 71 dpi

http://www.atlanticshore.com/lowagie/4.bmp
156x129 @ 299 dpi

http://www.atlanticshore.com/lowagie/5.bmp
700x420 @ 96 dpi

The resultant pdf is placed in the aforementioned
directory, and should display each image inserted at 100%, followed by
the same image inserted using the getScalePercent() method.  Thanks in
advance for any help, because I don't understand why I even need to
perform different calculations based on a specific dpi.  It seems that 1
generic function should take the dpi and return the correct
scalepercent.  The first 2 images work fine, but the 3rd is way off.

package Temp;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.FileOutputStream;

public class LowagieTestImages {


    public LowagieTestImages() {
    }

    public static void main(String[] args) {
        try {

        String pathForIO = "c:\\documents and
settings\\dlacertosa\\desktop";
        System.out.println("Begin.");

        Document document = new Document();
        FileOutputStream fos = new
FileOutputStream(pathForIO + "\\testPDF.pdf");
        PdfWriter pdfWriter =
PdfWriter.getInstance(document, fos);
        document.open();

        Image image2 = Image.getInstance(pathForIO + "\\2.bmp");
        Image image4 = Image.getInstance(pathForIO + "\\4.bmp");
        Image image5 = Image.getInstance(pathForIO + "\\5.bmp");


        document.add(new Paragraph("Image 2 has dpiX of
" + image2.getDpiX() + " and dpiY of " + image2.getDpiY()));
        document.add(image2);

image2.scalePercent(getScalePercent(image2.getDpiX()),
getScalePercent(image2.getDpiY()));
        document.add(image2);
        document.newPage();

        document.add(new Paragraph("Image 4 has dpiX of
" + image4.getDpiX() + " and dpiY of " + image4.getDpiY()));
        document.add(image4);

image4.scalePercent(getScalePercent(image4.getDpiX()),
getScalePercent(image4.getDpiY()));
        document.add(image4);
        document.newPage();

        document.add(new Paragraph("Image 5 has dpiX of
" + image5.getDpiX() + " and dpiY of " + image5.getDpiY()));
        document.add(image5);
        image5.scalePercent(getScalePercent(96),
getScalePercent(96));
        document.add(image5);

        document.close();

        System.out.println("Finished.");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static float getScalePercent(int dpi) {
        if (dpi <= 72)
            return ((72f / (float)dpi) * 100f) * .76f;

        return (1f - (72f / (float)dpi)) * 100f;
    }

}

Thanks again,
Dom




-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to