I am using iTextSharp to print a PDF document. Everything is going fine until I print the company logo.
At first, I noticed that the logo was of poor quality, but after testing with several images, I understand that iTextSharp did not render it well. The test I did to say was to print the PDF using my code, and then edit the document using Acrobat 8.0, and I drew an image. Then they printed two documents and saw a noticeable difference. My question is, if anyone knows if this could be due to a zoom problem, when I cannot tell iTextSharp how it should display the image or is a limitation of iTextSharp.
The code for rendering the image is as follows:
Dim para As Paragraph = New Paragraph para.Alignment = Image.RIGHT_ALIGN para.Add(text) Dim imageFile As String = String.Format("{0}{1}", GetAppSetting("UploadDirectory"), myCompany.LogoUrl) Dim thisImage As Image = Image.GetInstance(imageFile) thisImage.Alignment = Image.LEFT_ALIGN para.Add(thisImage)
Printed Images: alt text http://img710.imageshack.us/img710/4199/sshot2y.png
Image printed directly using iTextSharp
alt text http://img231.imageshack.us/img231/3610/sshot1z.png
Image edited and printed using Acrobat 8
EDIT: These logo images are downloaded from the download page, where the user downloads everything that the logo wants, and I scaled this image using the following code:
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newImage) graph.CompositingMode = Drawing.Drawing2D.CompositingMode.SourceOver graph.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality graph.InterpolationMode = Drawing.Drawing2D.InterpolationMode.Bicubic graph.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality graph.PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.HighQuality graph.DrawImage(newImage, 0, 0, newWidth, newHeight) graph.Dispose() graph = Nothing
This led to a loss of information from the original image, so when printing in pdf format, this loss of information was very noticeable, because iTextSharp somehow drew more than it was, regardless of how I scale. Therefore, I tried to save the image since it was originally, preventing the user from loading images larger than 200 KB and resizing the image so that I could maintain aspect ratio and use this resizing with the iTextSharp Image object before printing it. This solved my problem with a low quality printed image for these larger images, but as a result of the PDF document having a page break or just not fitting the page, it is strange because the image looks good in size but it behaves as if it is larger, This is a screen capture of a new image: alt text http://img38.imageshack.us/img38/5756/sshot3tc.png
EDIT 2:
When checking the iTextSharp image that is sent for printing, when scaling with ScaleAbsolute it does not show any changes, so the page is broken. But it is shown correctly how the image was successfully scaled, but there was no background βpaperβ. The code used is as follows:
Dim imageFile As String = String.Format("{0}{1}", GetAppSetting("UploadDirectory"), myCompany.LogoUrl)
Dim thisImage As Image = Image.GetInstance (imageFile) thisImage.Alignment = Image.LEFT_ALIGN
Dim newWidth As Integer = myCompany.LogoWidth Dim newHeight As Integer = myCompany.LogoHeight ResizeImageToMaxValues(newWidth, newHeight) thisImage.ScaleAbsolute(newWidth, newHeight) para.Add(thisImage) pdf.PdfDocument.Add(para)
The ResizeImage () method changes the size and height in relation to the format and saves the maximum width and maximum height limits.
Please let me know if I need to provide more information. Thanks