Convert from HTML to PDF in CSharp VB and ASP.NET with a Free 3rd Party Library

Converting from html to pdf is not an easy task. There are some tools that can do that, but most of them cost thousands of dollars. SelectPdf offers a Community Edition (FREE) of the powerful Html To Pdf Converter for .NET that can be found in the full featured pdf library.

 
 
 
 
 
3.6 Star
(59)
52,646 times
Add to favorites
5/10/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Conversion error: Unknown error
    1 Posts | Last post July 17, 2019
    • Im facing a probleme generating a PDF, the code is executed in an AZURE AppService, it works well when it's deployed on auther IIS servers or locally.
      here is the exception i'm getting: 
      
      
      [Exception: Conversion error: Unknown error.]
      SelectPdf.HtmlToImage.ᜀ(String A_0, ᥹[]& A_1, ᥖ& A_2) +1127
      SelectPdf.HtmlToPdf.ᜀ(String A_0, String A_1, String A_2, String A_3, Boolean A_4) +6713
      SelectPdf.HtmlToPdf.ConvertUrl(String url) +72
      
      
      
      
      
  • while using ConvertHtmlString i got error "Additional information: Conversion error: Navigation timeout."
    2 Posts | Last post June 06, 2019
    • An exception of type 'System.Exception' occurred in Select.HtmlToPdf.dll but was not handled in user code
      
      Additional information: Conversion error: Navigation timeout.
    • problem fixed. it was my mistake. The header and footer URL path was incorrect in code.
  • Data transmission error 0
    7 Posts | Last post May 29, 2019
    • ConvertHtmlString has been working for a couple of years, and just a few days ago, I'm starting to see:
      
      
      
      Conversion failure. Data transfer error. Data transmission error 0
      
      
      
      Is there any further information on what "error 0" means in this context?
      I'm confused because I haven't made any significant changes to my code.
      I've also verified that the source html string does not contain any broken links/image urls.
      
      
      The full Exception is below.  THANK YOU!
      
      
      
      System.Exception: Conversion failure. Data transfer error. Data transmission error 0 at SelectPdf.HtmlToImage.ᜀ(String A_0, String A_1, String A_2, ᥹[]& A_3, ᥖ& A_4) at SelectPdf.HtmlToPdf.ᜀ(String A_0, String A_1, String A_2, String A_3, Boolean A_4) at SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString) at BAL.Exporters.ExportToPdfSelect(String htmlSrc, String filename, String customPath) in C:\Code\ProjectX\BAL\Exporters.cs:line 322 at BAL.Email.LogEmailPdfToAmazonS3andCustomerDocs(LogEntityType type, Int32 EntityID, String DocTitle, String html, String[] emailAttachments) in C:\Code\ProjectX\BAL\Email.cs:line 677
      
      
      Here is a snippet of the code:
      
                  try
                  {
                      filename = filename.ToSafeFilename();
                      HtmlToPdf converter = new HtmlToPdf();
                      converter.Options.MaxPageLoadTime = 240; //4mins
                      GlobalProperties.HtmlEngineFullPath = 
                           @"[redacted]\Select.Html.dep";
                      converter.Options.MarginBottom = 50;
                      converter.Options.MarginLeft = 50;
                      converter.Options.MarginRight = 50;
                      converter.Options.MarginTop = 50;
      
                      SelectPdf.PdfDocument doc = 
                             converter.ConvertHtmlString(htmlSrc);
                   
                      doc.Save(fn);
                      doc.Close();
                  }
                  catch(Exception ex)
                  {
                      [redacted error handling]
                  }
    • You might have updated Select.HtmlToPdf.dll to a newer version and kept the Select.Html.dep (path referenced in your code) to an older version. Make sure they are both the same version.
    • Hi.
      I'm new to SelectPdf.
      
      I'm getting a similar error, but only on core 2.0 console app.
      It seems to work in classic console app though.
      
      I'm wondering whether this is a Core 2.0 issue and that an update will be coming SelectPdf.
      
      My error message:
      
      
      Unhandled Exception: SelectPdf.HtmlToPdfException: Could not render the PDF document. The type initializer for 'SelectPdf.Lib.?' threw an exception.
         at SelectPdf.HtmlToPdf.?(String A_0, String A_1, String A_2, String A_3, Boolean A_4)
         at SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString)
    • how did you solve it? I have the same issue, I did not change anything and I started to get the same error
    • The error "The type initializer for 'SelectPdf.Lib.?' threw an exception." might happen if you reference the .NET Framework version of the dll in a .NET Core project. Use the .NET Core version: https://www.nuget.org/packages/Select.HtmlToPdf.NetCore/
    • I have the same error when I run it on the server. I use it in a .Net Core 2.2 console application and I use Select.HtmlToPdf.NetCore v19.1.0. It gives the error "Conversion failure. Data transfer error. Data transmission error 0" roughly one out of 30 email send. I checked the version of Select.HtmlToPdf.dll and it is 19.1.0 and pushed Select.Html.dep published every time and I conformed that it exists on the server folder. The thing is that I cannot reproduce it when I run it from my local (Windows 10 with 64 GB of memory). The server has .Net Core 2.2 SDK installed albeit the server has only 14 GB of memory. Do you think it has something to do with memory/resources on the server?
    • Any solution?? i have same problem with the error Conversion failure. Data transfer error. Data transmission error 0
  • Timeout only when using https
    2 Posts | Last post May 10, 2019
    • I receive a timeout error (Conversion error: Navigation timeout) whenever trying to convert a single page to pdf only when using https.  Everything works like a dream with http but blows up when we move to production and go over ssl 
    • Possible causes for Navigation timeout are listed here: https://selectpdf.com/html-to-pdf/docs/html/Troubleshooting.htm#item10
      
      Besides that, is you use newer SSL protocols (TLS 1.2), use our latest version.
  • HTML TO PDF Convertion
    1 Posts | Last post March 22, 2019
    • I am having a HTML which contain some Images and Style to place the Positions, While I am Converting using iTextSharp then My styles are not taking even its not Exactly showing as HTML.
      
      When I use this Library but I am facing same Issue please let me know
  • Rendering html to pdf results in garbage on the 2nd attempt
    1 Posts | Last post December 14, 2018
    • Hello,
      
      I'm using selectPDF to render HTML view to PDF. The rendering in done via a C# MVC ActionResult method which render the view to string and saves the PDF file to the disk.
      On dev machine it is all working fine.
      When deploy to production it renders fine on the 1st attempt. On the 2nd rendering, it returns garbage document. The CSS/JS works fine according to result but the formatting fails.
      After 10-15 minutes it is rendering ok again.
      Tried to remove font, extend wait to 20 sec, remove everything from the page up to bare minimum, same problem.
      It seems like something is not disposed correctly and only after GC it works fine again (assumption).
      I'm using the latest version with .NET 4.0
      Thanks !
  • Geting and Exception
    3 Posts | Last post November 29, 2018
    • Getting this exception @ converter.ConvertUrl():
      Conversion failure. Could not find 'Select.Html.dep'.
      
      Any ideas? Thanks
    • Please check this blog post: http://selectpdf.com/how-to-fix-conversion-failure-could-not-find-select-html-dep/
    • I Have Using Select.HtmlToPdf.NetCore dll with nuget Package manager its working fine., but publish all code in iis server then not able to get any content ....
      
      Ex : <div>Hello Friends</div> .
      i have used code like this : 
      [HttpPost]
              public string PDFBytes(string htmlfile)
              {
                  string base64 = "";            
                  try
                  {
                      string pdf_page_size = "A4";
                      PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true);
                      string pdf_orientation = "Portrait";
                      PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation),
                          pdf_orientation, true);
                      int webPageWidth = 1024;
                      int webPageHeight = 0;
      
                      // instantiate a html to pdf converter object
                      HtmlToPdf converter = new HtmlToPdf();
                      // set converter options
                      converter.Options.PdfPageSize = pageSize;
                      converter.Options.PdfPageOrientation = pdfOrientation;
                      converter.Options.WebPageWidth = webPageWidth;
                      converter.Options.WebPageHeight = webPageHeight;               
                      PdfDocument doc = converter.ConvertHtmlString(htmlfile);
                      //Conversion failure. Could not find 'Select.Html.dep'. 
                      // save pdf document
                      byte[] data = doc.Save();
                      // close pdf document
                      doc.Close();
                      base64 = Convert.ToBase64String(data);
                  }
                  catch (Exception ex)
                  {
                      throw ex;
                  }
                  return base64;
              }
      
      
  • Does it support in linux env?
    2 Posts | Last post November 12, 2018
    • Does it support in linux env
    • At the current time, SelectPdf only works on Windows.
  • ConvertHtmlString not rendering whole HTML content to pdf document - SelectPdf
    2 Posts | Last post November 12, 2018
    • Hi All,
      
      We are bringing SelectPdf into our tool development for generating PDF document from Raw HTML content.
      
      Consider, the HTML content which we have doesn't have any css/image urls. CSS is part of HTML content.
      
      We are trying to accommodate whole HTML content into single page instead going with multiple pdf pages(the way of outcome which we need). What we could see is, the API call "ConvertHtmlString" is actually not rendering the whole HTML content into pdf document which it returns back. Same time we are making PDF pages to fixed size in pixel using "PdfPageSize.Custom". The page is being generated as per custom page which we had set. But though page size is more sufficient to render the whole HTML content which we have in hand, we could see that the HTML content is partially being rendering into the page.
      
      Also please note that, page is always being filled till some point only.
      
      Is this limitation as like no of page limitation?
      
      Could anyone please suggest?
    • This is a limitation of the free community edition of SelectPdf. To be able to render the whole document, you need to use the commercial edition: https://selectpdf.com/pdf-library-for-net/
  • Reading Text from PDF using SelectPDF.NET
    1 Posts | Last post September 24, 2018
    • Hi Team,
      
      I would like to know how does the SelectPDF.NET handles any malware scripts in PDF while extracting text from a PDF? If any script is embedded in pdf will it run while fetching the text?
      
      
1 - 10 of 87 Items