Nginx Recipes: Converting HTML to PDF

To prepare the conversion from HTML to PDF, we will need the software itself nginx and its plugin html2pdf. (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 the finished way.)

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 the generator from wt).

This is certainly not the best generator; I tried a couple before it but found errors in them htmldoc and wkhtmltopdf.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster