Note that there are some explanatory texts on larger screens.

plurals
  1. POiTextSharp renders image with poor quality in PDF
    text
    copied!<p>I'm using iTextSharp to print a PDF document. Everything goes ok until I have to print the company logo in it.</p> <p>First I noticed that the logo had poor quality, but after testing with several images, I realize that was the iTextSharp rendering it poorly. The test I did to say this was to print the PDF using my code and then edit the document with Acrobat 8.0 and I drew an image. Then printed the two documents and saw the noticeable difference. My question is that if anyone know if this can be due to a scaling problem where I'm failing to tell iTextSharp how it must render the image or is an iTextSharp limitation.</p> <p>The code to render the image is the following:</p> <pre><code> 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) </code></pre> <p>The printed images are the following: <a href="http://img710.imageshack.us/img710/4199/sshot2y.png">alt text http://img710.imageshack.us/img710/4199/sshot2y.png</a></p> <p>Image printed directly with iTextSharp</p> <p><a href="http://img231.imageshack.us/img231/3610/sshot1z.png">alt text http://img231.imageshack.us/img231/3610/sshot1z.png</a></p> <p>Image edited and printed with Acrobat 8</p> <p>EDIT: These logo images are loaded from an Upload page where the user uploades whatever the logo image he wants, and I was scaling that image using the following code:</p> <pre><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 </code></pre> <p>This was causing to lose info from the original image, so when printed in the pdf, that lose of info was very noticeable because, somehow, iTextSharp was drawing bigger than it was, no matter the scaling I put in there. So I tried to store the image as it was originally, preventing the user to not upload images bigger than 200K and resizing the image so I could mantain the aspect ratio, and using that resizing with the iTextSharp Image object before it was printed. This solved my problem of the image being printed with poor quality for these bigger images but caused the pdf document to have a page break or just not fit in the page, weird thing because the picture looks good in size but it behaves like it was bigger. This is a screen capture of the new image: <a href="http://img38.imageshack.us/img38/5756/sshot3tc.png">alt text http://img38.imageshack.us/img38/5756/sshot3tc.png</a></p> <p><strong>EDIT 2:</strong></p> <p>When inspecting the iTextSharp Image that is sent to be printed, it shows no changes after the scaling using ScaleAbsolute, that's why the page breaks. But is shown correctly, like the image was successfully scaled, but the background "paper" wasn't. The code used so far is the following:</p> <pre><code> Dim imageFile As String = String.Format("{0}{1}", GetAppSetting("UploadDirectory"), myCompany.LogoUrl) </code></pre> <p>Dim thisImage As Image = Image.GetInstance(imageFile) thisImage.Alignment = Image.LEFT_ALIGN</p> <pre><code> 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) </code></pre> <p>The method ResizeImage() do the resizing of the width and height respecting the aspect ratio and keeping in a max width and a max height limits.</p> <p>Please let me know if I need to provide more info. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload