To prepare the conversion from HTML to PDF, we will need the software itself and its plugin . (I provided links to my fork of nginx, as I made some changes that I haven't yet pushed to the original repository. You can also use .)
To convert HTML to PDF from a file
location =/html_to_pdf_from_file {
html2pdf on; # enable pdf filter
}To convert HTML to PDF from text
location =/html_to_pdf_from_text {
html2pdf on; # enabling pdf filter
return 200 "<p style="background-color: #c11">Hello, World!</p>"; # returning HTML
}To convert HTML to PDF from a proxy
location =/html_to_pdf_from_proxy {
html2pdf on; # enable pdf filter
proxy_pass something_that_returns_html; # redirect to where HTML is returned
}as a result, when accessing these locations, a PDF generated from the HTML will be returned instead (using ).
This is certainly not the best generator; I tried a couple before it but found errors in them and .
Source: habr.com
