Subject: ImportHtmlText - PDF "quality" Date: 2012-08-07 04:53:11 From: Patrik Lithner Source: importhtmltext-pdf-quality ----------------------------------------------------------------------
---------------------------------------------------------------------- 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
- //Create a PDF document
- PdfDocument doc = new PdfDocument(PdfDocumentConformanceLevel.None);
- PdfUnitConvertor convertor = new PdfUnitConvertor();
- doc.PageSettings.SetMargins(15, 30, 15, 40);
- doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
- doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0;
- doc.PageSettings.Size = PdfPageSize.A4;
- PdfMetafileLayoutSettings format = new PdfMetafileLayoutSettings();
- format.Layout = PdfLayoutType.Paginate;
- format.Break = PdfLayoutBreakType.FitElement;
- format.SplitTextLines = false;
- format.SplitImages = false;
- PdfPage newPage = doc.Pages.Add();
- float width = -1;
- float height = -1;
- AspectRatio dimension = AspectRatio.KeepWidth;
- height = convertor.ConvertToPixels(newPage.GetClientSize().Height, PdfGraphicsUnit.Point);
- width = convertor.ConvertToPixels(newPage.GetClientSize().Width, PdfGraphicsUnit.Point);
- Html2PdfOptions options = new Html2PdfOptions();
- options.EnableJavaScript = true;
- options.AutoDetectPageBreak = false;
- options.EnableHyperlinks = false;
- options.Width = (int)width;
- options.Height = (int)height;
- options.SplitTextLines = true;
- options.AspectRatio = dimension;
- var url = "testpage.aspx";
- var sb = new StringBuilder();
- var writer = new StringWriter(sb);
- HttpContext.Current.Server.Execute(url, writer, false);
- var html = sb.ToString().Replace("charset=utf-8", "");
- doc.ImportHtmlText(html, options);
- // Rendering HtmlText
- doc.Save(finalFilename)
- doc.Close();