1

IDE: VS 2022 | .NET 6.0

I'm looking for free .NET library to convert string html to .pdf file. In the web I found PDFSharp, but I have error with it (desc below)

I tried:

nugets: HtmlRenderer.PdfSharp and PDFSharp

I must try PDFsharp combine with other nuget, because PDFsharp does not currently include code to parse HTML files.

code:


using PdfSharp;
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;


public class GenerateApiController : Controller
{
//(...)

public IActionResult GeneratePdf(Guid guid)
   {

     DateTime dateNow = DateTime.Now;

     string html = $"<div align=right><font size=\"4\"> {dateNow}</div>" +
       "<br><br><br>";

     PdfDocument pdfDocument = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PageSize.A4);

     pdfDocument.Save(@"C:\Users\MIPA\Pictures\PDF_SKR\myoo.pdf");

     return Ok();

   }
}

the error occurs when trying to call the method = does not enter the method = I dont have error while compiling, only when trying to call a method

error:

Internal Server Error

FileNotFoundException: Could not load file or assembly 'HtmlRenderer, Version=1.5.0.6, Culture=neutral, PublicKeyToken=null'. The specified file could not be found.

In VS 2022 in diagnostic I have message - HtmlRenderer.PdfSharp:

Warning: Package 'HtmlRenderer.PdfSharp 1.5.0.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.

If you have other ideas / nuggets, please help

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jun 22, 2022 at 12:24

1 Answer 1

1

You can try Syncfusion’s Essential .NET PDF library.

https://www.syncfusion.com/document-processing/pdf-framework/net enter image description here

The whole suite of controls is available for free (commercial applications also) through the community license program if you qualify. The community license is the full product with no limitations or watermarks.

https://www.syncfusion.com/products/communitylicense

Note: I work for Syncfusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.