How to generate PDF from HTML view after scripts and styles applied in ASP.NET MVC

前端 未结 3 816
生来不讨喜
生来不讨喜 2021-01-15 14:57

I want to generate HTML of my View to generate PDF document. It has styles and scripts applied when it opens in browser. I tried the following code but it only gives the ht

3条回答
  •  清歌不尽
    2021-01-15 15:35

    I might as well post my comment as an answer...

    Razor/ASP.Net will only generate source, not execute client-side scripts. You need to use something that emulates a web browser to turn the client-side script into a rendered PDF.

    That means it needs to understand both script and styling (i.e. just like a browser).

    There are several commercial products out there, but I have personally used Essential Objects PDF converter to generate views direct to PDF. It has a built-in Javascript engine, so looks just like it will in the browser.

    Please note these products are very complex (as they include complete Browser rendering engines), so most will required paid licences (for commercial use at least).

    Note: I am in no way associated with Essential Objects. This is purely opinion based on actual use of that product.

提交回复
热议问题