Subject: ImportHtml
Date: 2012-08-24 07:44:32
From: Patrik Lithner
Source: importhtml
----------------------------------------------------------------------

Hi!

I am using ImportHtml to create a pdf file from html. The output in the pdf is an image. How can i make it render as text? I need too be able to copy text from the pdf.

 Currently using the code below.

Best regards

Patrik

 

  1. public void CreatePDF(string htmlSource, string pdfFilename, out bool success)  
  2.        {  
  3.            success = false;  
  4.            string pdfurl = string.Empty;  
  5.            try  
  6.            {                                  
  7.                PdfDocument doc = new PdfDocument(PdfDocumentConformanceLevel.None);  
  8.                PdfUnitConvertor convertor = new PdfUnitConvertor();  
  9.                doc.PageSettings.SetMargins(15, 30, 15, 40);  
  10.                doc.PageSettings.Orientation = PdfPageOrientation.Portrait;  
  11.                doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0;  
  12.                doc.PageSettings.Size = PdfPageSize.A4;  
  13.   
  14.                PdfPage newPage = doc.Pages.Add();  
  15.   
  16.                float width = -1;  
  17.                float height = -1;  
  18.   
  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 = false;  
  25.                options.AutoDetectPageBreak = false;  
  26.                options.EnableHyperlinks = true;  
  27.                options.Width = (int)width;  
  28.                options.Height = (int)height;  
  29.                options.SplitTextLines = true;  
  30.                options.AspectRatio = dimension;  
  31.   
  32.                doc.ImportHtml(htmlSource, options);  
  33.                doc.Save(pdfFilename);  
  34.                doc.Close();  
  35.            }  
  36.            catch (Exception ex)  
  37.            {  
  38.                string message = string.Format("[Error in CreatePdf] pdfurl: {0}", pdfurl);  
  39.                Response.Write("error: " + ex.Message);  
  40.            }  
  41.        } 
---------------------------------------------------------------------- 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