locked
Struggling with iText Package for converting html into pdf -- RRS feed

  • Question

  • User-215451226 posted

    Hi All,

    I am stuck with this problem. I did some google and searching around various resources. To no avail. Initially I went for iTextSharp, which is also known as iText5. I followed this article -- https://www.aspsnippets.com/Articles/MVC-iTextSharp-Example-Convert-HTML-to-PDF-using-iTextSharp-in-ASPNet-MVC.aspx. This example shows usage of itext5.

    It threw several exceptions mainly in the XmlWorkerHelper portion and I found out after fair bit of searching, that itextsharp is not suited for .Net Core applications. As per recommendations - Now, I am trying to use the iText7 package now. But struggling. My code is giving several errors like conflicts between itext.Layout, iText.Kernel.Geom, Document initialization, PageSize and several others.
    I need one clean, simple code stub that just shows what exact namespaces to use, and how to put together the code that will basically convert my string html into a pdf document.
    That's all I need. I am quite struggling at the moment. My method is supposed to be basically very simple. It will take in a string html and output a pdf file format.

    I have already added these namespaces. Kindly check once --

    using iText;
    using iText.Layout;
    using iText.Kernel.Geom;

    Something like this --

    [Route("FormatPdfInvoice")]
    [HttpGet]
    public IActionResult FormatPdfInvoice([FromBody] string htmlDoc)
    {
        //something here
    
    }

    Please help me.

    Thursday, June 28, 2018 3:37 PM

All replies

  • User-474980206 posted

    Not sure they have a .net core version (don't confuse the core in their name with .net core). As its a paid product now, you should check with their sales force. as its a heavy user system.drawing, probably not. 

    If you want to use the open source version and you meet their restrictions for using the open source version (your source code is available online),  you need to set the target framework to net472 (windows only).

    Thursday, June 28, 2018 11:54 PM
  • User-525215917 posted

    If you don't have to generate complex PDF files then you can use free Rotativa.AspNetCore NuGet package to generate view based PDF-s on ASP.NET Core. More about it here: https://gunnarpeipman.com/aspnet/aspnet-core-pdf/ 

    Friday, June 29, 2018 5:00 AM
  • User-215451226 posted

    Hi,

    My div contains 2 images and some css stylings. Mostly colors and a lit bit of padding, margin related stuff. Will it be OK to use this (rotativa) package? Kindly tell me,

    Thanks,

    Friday, June 29, 2018 5:16 AM
  • User-215451226 posted

    Hi Bruce,

    Thanks for suggesting. Ok, I will cross-check with them. No in fact, the final end-product in which this portion/module is included (changing the html portion to a pdf doc) is supposed to be a sell-able software, a paid product. So I think I will go for that rotativa after all. Once I get commu. from the iText guys to be sure ie.

    Friday, June 29, 2018 2:37 PM
  • User1168443798 posted

    Hi PGChoudhury,

    Thanks for your post.

    I am afriad there i no built-in library from .NET Core to achieve converting html to pdf.

    If you get any solution by third party library like iText or rotativa, it would be appreciated if you could share us.

    Best Regards,

    Edward

    Monday, July 2, 2018 2:03 AM
  • User-215451226 posted

    I will do.
    I am working on it. Trying several things now as experimentation. Hopefully I will strike something meaningful.
    I will update you all, with what/how I found.
    Thanks,

    Tuesday, August 7, 2018 6:20 PM