Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to convert html string to Pdf

umar-ulabs opened this issue · comments

How to convert html as string to pdf instead of from ConvertUri?
Thanks

I know it is not the answer you want, but a workaround is to create a Temp file .html and pass the path as a parameter. Because I think, the chrome.exe machine receives the path and exports the .pdf as a file, and not as base64 or something else. You can create a Temp folder and add the .html files on it and receive the .pdf files from the converter. After your code execution, delete the temp folder.

I find it ironic that wrappers for WkHtmlToPdf can take HTML to convert to a PDF, but page header and footer must be URLs. While ChromeHtmlToPdf as a wrapper for Chrome will only accept Urls to convert to PDFs, but header and footer must be HTML.

commented

Well it is possible to use html but I just did not program it that way.

Based off of your understanding, would attempting something like that require additional implementation on top of ChromeHtmlToPdf, or would it require changes internally to the ChromeHtmlToPdf wrapper, in the form of something like a PR/fork?
I was looking briefly at the code the other day, and my first guess was to maybe load a blank page, and then call something via the websocket to dynamically inject HTML into the DOM?

commented

I was looking briefly at the code the other day, and my first guess was to maybe load a blank page, and then call something via the websocket to dynamically inject HTML into the DOM?

I was exactly thinking about doing something like that. It will require some changes in the wrapper since we need an option to pass the HTML from the front to the end and inject it into Chrome.

commented

I just made a start to implement this --> 9650a1a need to look into it this evening or this weekend to see how to make this all work.

https://github.com/westy92/html-pdf-chrome/blob/master/src/index.ts uses setDocumentContent so the implementation you have should work fine.

commented

I try to look into it this weekend, at the moment I have little time due to work related things.

commented

I just released a new nuget package for this.

https://www.nuget.org/packages/ChromeHtmlToPdf