Convert HTML to PDF in MVC with iTextSharp in MVC Razor

后端 未结 9 1187
情深已故
情深已故 2020-12-02 15:56

I am trying to convert HTML to PDF with iTextSharp in MVC Razor, but everything I have tried has not worked. Does anyone know how to accomplish this?

相关标签:
9条回答
  • 2020-12-02 16:53

    You should check out RazorPDF which is using iText to generate the PDF, but in a friendlier way.

    0 讨论(0)
  • 2020-12-02 16:54

    There's a detailed and step-by-step tutorial on CodeProject you might follow. It illustrates how you could serve an ASP.NET MVC View as PDF file using iTextSharp for the conversion. Bear in mind though that iTextSharp was not meant for converting HTML to PDF so it might not cope very well with complex HTML pages and CSS styles.

    0 讨论(0)
  • 2020-12-02 16:57

    Here is how you implement this solution using the Razor engine NOT with the weird <itext.. markup.

    This way you have full control over the pdf presentation using standard html output.

    The project with an example solution and source code is available here with nuget installation instructions:

    https://github.com/andyhutch77/MvcRazorToPdf

    Install-Package MvcRazorToPdf
    

    This also uses the new itextsharp licence, so does not suffer from any of the negatives mentioned in the other answers.

    0 讨论(0)
提交回复
热议问题