ScaleToFit problem when image rectangle is wider than document

View: New views
4 Messages — Rating Filter:   Alert me  

ScaleToFit problem when image rectangle is wider than document

by LMM :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am adding JPGs of various sizes to the PDF I am creating.  While testing I discovered that 1 particular JPG wouldn't resize, and without throwing an error, allowed the program to complete but not save the document.

I think I've found the problem.  When the image is wider than the document the document won't print even after using ScaleToFit.  The dimensions of the rectangle never change.  I have examples of the dimensions of the document and the image before/after Scale to Fit, and the couple of lines of code from my program.

_document.PageSize.Base{Rectangle 612x792}

Image before ScaleToFit

artImage{Rectangle 809X280}
artImage.PlainHeight 280.0
artImage.PlainWidth 809.0
artImage.ScaledHeight 280.0
artImage.ScaledWidth 809.0


Image after ScaleToFit

artImage{Rectangle 809X280}
artImage.PlainHeight 179.975281
artImage.PlainWidth 520.0
artImage.ScaledHeight 179.975281
artImage.ScaledWidth 520.0


Program code

float imgHeight = 200.0f;
artImage.Alignment = Image.ALIGN_LEFT;
artImage.ScaleToFit(_document.Right - (_document.RightMargin + 20.0f), imgHeight);


Is this in fact the problem (rectangle size) and if so, is there a way around it?

Re: ScaleToFit problem when image rectangle is wider than document

by Paulo Soares :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No problem there, the rectangle is the original image size and never
changes. What changes is the the ScaledHeight and ScaledWidth. What do you
mean by "the document won't print"?

Paulo

----- Original Message -----
From: "LMM" <lmorelli3@...>
To: <itextsharp-questions@...>
Sent: Wednesday, July 23, 2008 8:36 PM
Subject: [itextsharp-questions] ScaleToFit problem when image rectangle is
wider than document



I am adding JPGs of various sizes to the PDF I am creating.  While testing I
discovered that 1 particular JPG wouldn't resize, and without throwing an
error, allowed the program to complete but not save the document.

I think I've found the problem.  When the image is wider than the document
the document won't print even after using ScaleToFit.  The dimensions of the
rectangle never change.  I have examples of the dimensions of the document
and the image before/after Scale to Fit, and the couple of lines of code
from my program.

_document.PageSize.Base{Rectangle 612x792}

Image before ScaleToFit

artImage{Rectangle 809X280}
artImage.PlainHeight 280.0
artImage.PlainWidth 809.0
artImage.ScaledHeight 280.0
artImage.ScaledWidth 809.0


Image after ScaleToFit

artImage{Rectangle 809X280}
artImage.PlainHeight 179.975281
artImage.PlainWidth 520.0
artImage.ScaledHeight 179.975281
artImage.ScaledWidth 520.0


Program code

float imgHeight = 200.0f;
artImage.Alignment = Image.ALIGN_LEFT;
artImage.ScaleToFit(_document.Right - (_document.RightMargin + 20.0f),
imgHeight);


Is this in fact the problem (rectangle size) and if so, is there a way
around it?


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: ScaleToFit problem when image rectangle is wider than document

by LMM :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I misspoke.  I am creating the document as a MemoryStream, create the document, close the document so the pageevents run, and then reopen to use PdfStamper, etc...

The program works fine, unless I have an image wider than the document.  When that happens, I get an error (Rebuild failed: Input string was not in a correct format.; Original message: PDF startxref not found.) when 'PdfReader reader = new PdfReader(pdfRead);' tries to execute.  Consequently the program jumps to my Catch, and the document never gets saved to the SQL table.

Here is some additional code:


MemoryStream ms = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, ms);

MyPageEvents pagevent = new MyPageEvents();
writer.PageEvent = pagevent;
           
document.Open();

***** add to document *****

 document.Close();

 byte[] pdfRead = ms.GetBuffer();

 PdfReader reader = new PdfReader(pdfRead);

Re: ScaleToFit problem when image rectangle is wider than document

by Paulo Soares-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If the image is wider than the page it may not be added and unless you have something else in the page it will throw a "document has no pages exception". I suspect that you are ignoring an exception.

Paulo

> -----Original Message-----
> From: itextsharp-questions-bounces@...
> [mailto:itextsharp-questions-bounces@...]
> On Behalf Of LMM
> Sent: Thursday, July 24, 2008 3:59 PM
> To: itextsharp-questions@...
> Subject: Re: [itextsharp-questions] ScaleToFit problem when
> image rectangle is wider than document
>
>
> I misspoke.  I am creating the document as a MemoryStream, create the
> document, close the document so the pageevents run, and then
> reopen to use
> PdfStamper, etc...
>
> The program works fine, unless I have an image wider than the
> document.
> When that happens, I get an error (Rebuild failed: Input
> string was not in a
> correct format.; Original message: PDF startxref not found.)
> when 'PdfReader
> reader = new PdfReader(pdfRead);' tries to execute.  Consequently the
> program jumps to my Catch, and the document never gets saved
> to the SQL
> table.
>
> Here is some additional code:
>
>
> MemoryStream ms = new MemoryStream();
> PdfWriter writer = PdfWriter.GetInstance(document, ms);
>
> MyPageEvents pagevent = new MyPageEvents();
> writer.PageEvent = pagevent;
>
> document.Open();
>
> ***** add to document *****
>
>  document.Close();
>
>  byte[] pdfRead = ms.GetBuffer();
>
>  PdfReader reader = new PdfReader(pdfRead);

Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
LightInTheBox - Buy quality products at wholesale price