Last post Aug 07, 2018 06:20 PM by PGChoudhury
Jun 28, 2018 03:37 PM|PGChoudhury|LINK
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 --
Something like this --
public IActionResult FormatPdfInvoice([FromBody] string htmlDoc)
Please help me.
Jun 28, 2018 11:54 PM|bruce (sqlwork.com)|LINK
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).
Jun 29, 2018 05:00 AM|DigiMortal|LINK
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/
Jun 29, 2018 05:16 AM|PGChoudhury|LINK
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,
Jun 29, 2018 02:37 PM|PGChoudhury|LINK
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.
Jul 02, 2018 02:03 AM|Edward Z|LINK
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.
Aug 07, 2018 06:20 PM|PGChoudhury|LINK
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.