I’m generating PDF files from my C# 4.0 windows application using iTextSharp API. I’ll be passing HTML string which will contain Rich Text and Images. My PDF file size is A4 with default margins. Noticed that when I have a large image in dimension (e.g. height=”701px” width=”935px”) , the image is not coming to PDF. Looks like, I have to scale down the image dimension which should be able to fit in the PDF A4 size. I checked this by pasting the image to a word document of A4 size, MS Word automatically scales down the image by 36% i.e. MS Word takes only 64% of the original image dimension and sets the absolute height & width.
Can someone please help to mimic similar behavior in C#?
Let me know how to automatically set an image height & width to fit in A4 PDF file.
That’s correct, iTextSharp won’t automatically size images that are too big for the document. So it’s just a matter of:
Here’s one way, see inline comments:
The only point worth noting is that
imagePathsabove is astring[]so that you can test what happens when adding a collection of images that are to big to fit in a page.Another way is to put the image in a one column, single cell PdfPTable: