Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using itext to convert tiff document

282 views
Skip to first unread message

adgo...@gmail.com

unread,
Jun 20, 2007, 3:38:01 AM6/20/07
to
Hi,
I am using the code from the Lowagie sample, but the resulting pdf has
a much large top margin then the original tiff. Is there a way I can
get the pdf to look like the original tiff? I've tried adjusting the
scaleToFit, pagemargins & scalePercent, to no avail.

Code:
try {
Image img = TiffImage.getTiffImage(ra, c + 1);
if (img != null) {
System.out.println("page " + (c + 1));
if (img.getScaledWidth() > 500 ||
img.getScaledHeight() > 700) {
img.scaleToFit(500, 700);
}
img.setAbsolutePosition(0, 0);
document.add(new Paragraph(tiff_file + " -
page " + (c + 1)));
cb.addImage(img);
document.newPage();
++pages;
}
}
Alan

Hans-Werner Hilse

unread,
Jun 20, 2007, 8:08:22 AM6/20/07
to
Hi,

On Wed, 20 Jun 2007 00:38:01 -0700 adgo...@gmail.com wrote:

> I am using the code from the Lowagie sample, but the resulting pdf has
> a much large top margin then the original tiff. Is there a way I can
> get the pdf to look like the original tiff? I've tried adjusting the
> scaleToFit, pagemargins & scalePercent, to no avail.

You need to adjust the pagesize to the size of the Tiff -- I guess it
doesn't share the same width/height aspect, as such no scaling (except
off-aspect) would work.

I'd suggest discussing this on the iText-ML before going in to deep
here, but feel free to ask more about it -- I'll at least try to help.

-hwh

Bruno Lowagie

unread,
Jun 20, 2007, 8:57:15 AM6/20/07
to
adgo...@gmail.com wrote:
> img.scaleToFit(500, 700);

scale to fit will change the dimensions of the image,
so that it fits a rectangle with width = 500, and height = 700,
KEEPING THE X/Y RATIO OF THE ORIGINAL IMAGE.
In other words: your image could be scaled to 500x300, 200x700,...
depending on its X/Y ratio.

Based on your requirements, I'd advise you to change the page
size (so that it's identical to the size of the TIFF) instead
of scaling the image.

Have a look at the Tiff2Pdf plug-in in the toolbox to find
out how to do it:
http://itexttoolbox.svn.sourceforge.net/viewvc/itexttoolbox/main/src/com/lowagie/tools/plugins/Tiff2Pdf.java?revision=65&view=markup
br,
Bruno

Bill Segraves

unread,
Jun 20, 2007, 9:59:34 AM6/20/07
to
<adgo...@gmail.com> wrote in message
news:1182325081....@q19g2000prn.googlegroups.com...

> Hi,
> I am using the code from the Lowagie sample, but the resulting pdf has
> a much large top margin then the original tiff. Is there a way I can
> get the pdf to look like the original tiff?

One way would be for you to use the PhotoAlbum tool in the iText Toolbox.
PhotoAlbum will produce a PDF that is the same size as the source image.

BTW, this author has submitted (to Bruno Lowagie) a simple modification to
PhotoAlbum that makes it accept a scale factor as an additional argument, in
hopes this modification will be included in the next revision of the
Toolbox. In addition, this author has also submitted several additional
classes for consideration for incorporation in the Toolbox, one of which,
ScaleAndTile, scales an image or PDF to a new size (original size x
scalefactor), renders the result as a PDF file, and then tiles the scaled
PDF.

Cheers,
Bill Segraves


adgo...@gmail.com

unread,
Jun 21, 2007, 12:29:12 AM6/21/07
to
On Jun 20, 4:57 am, Bruno Lowagie <bruno.lowa...@ugent.be> wrote:

> adgol...@gmail.com wrote:
> > img.scaleToFit(500, 700);
>
> scale to fit will change the dimensions of the image,
> so that it fits a rectangle with width = 500, and height = 700,
> KEEPING THE X/Y RATIO OF THE ORIGINAL IMAGE.
> In other words: your image could be scaled to 500x300, 200x700,...
> depending on its X/Y ratio.
>
> Based on your requirements, I'd advise you to change the page
> size (so that it's identical to the size of the TIFF) instead
> of scaling the image.
>
> Have a look at the Tiff2Pdf plug-in in the toolbox to find
> out how to do it:http://itexttoolbox.svn.sourceforge.net/viewvc/itexttoolbox/main/src/...
> br,
> Bruno

Thanks Bruno (& rest) I'll work on this tomorrow. The tiff file has a
width over 1100. The >500 code will always get executed.

0 new messages