Subject: ImportHtmlText -  PDF "quality"
Date: 2012-08-07 04:53:11
From: Patrik Lithner
Source: importhtmltext-pdf-quality
----------------------------------------------------------------------

 

Hi!
I am having some trouble with the rendered PDF.  If i use a Windows Server 2008 with IE9 all works great, but on Server 2003 with IE 7 the text and images are rendered with really bad quality.
Are this a know issue?
 
I am using the following code to render the PDF.
 
  1. //Create a PDF document
  2. PdfDocument doc = new PdfDocument(PdfDocumentConformanceLevel.None);
  3.  
  4. PdfUnitConvertor convertor = new PdfUnitConvertor();
  5. doc.PageSettings.SetMargins(15, 30, 15, 40);
  6. doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
  7. doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0;
  8. doc.PageSettings.Size = PdfPageSize.A4;
  9.  
  10. PdfMetafileLayoutSettings format = new PdfMetafileLayoutSettings();
  11. format.Layout = PdfLayoutType.Paginate;
  12. format.Break = PdfLayoutBreakType.FitElement;
  13. format.SplitTextLines = false;
  14. format.SplitImages = false;
  15.  
  16. PdfPage newPage = doc.Pages.Add();
  17. float width = -1;
  18. float height = -1;
  19. AspectRatio dimension = AspectRatio.KeepWidth;
  20. height = convertor.ConvertToPixels(newPage.GetClientSize().Height, PdfGraphicsUnit.Point);
  21. width = convertor.ConvertToPixels(newPage.GetClientSize().Width, PdfGraphicsUnit.Point);
  22.  
  23. Html2PdfOptions options = new Html2PdfOptions();
  24. options.EnableJavaScript = true;
  25. options.AutoDetectPageBreak = false;
  26. options.EnableHyperlinks = false;
  27. options.Width = (int)width;
  28. options.Height = (int)height;
  29. options.SplitTextLines = true;
  30. options.AspectRatio = dimension;
  31.  
  32. var url = "testpage.aspx";
  33. var sb = new StringBuilder();
  34. var writer = new StringWriter(sb);
  35. HttpContext.Current.Server.Execute(url, writer, false);
  36. var html = sb.ToString().Replace("charset=utf-8", "");
  37. doc.ImportHtmlText(html, options);
  38. // Rendering HtmlText
  39. doc.Save(finalFilename)
  40. doc.Close();  
---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index