Custom Static Javascript HTML to PDF

I am trying to make invoices for my static website. I am trying to convert an HTML page to a PDF page. I been doing static websites rather than Node.JS because I can’t host Node.JS websites. What have I done wrong?

What have I tried

invoices.html

<!DOCTYPE html>
<html>
  <head>
    <style>
      html,
      body {
        padding: 0;
        margin: 0;
      }
      iframe {
        width: 100%;
        height: 100%;
        border: 0;
      }
    </style>
  </head>
  <body>
    <iframe
      srcdoc="<p>Hello world!</p>"
      src="invoices.html"
      type="application/pdf"
    ></iframe>
  </body>
</html>

Result

I have gotten the "Hello World" to display but it was just in a html page rather then a PDF page.

1 thought on “Custom Static Javascript HTML to PDF”

  1. It would better to create a small PHP script to handle this process.
    Give a look at: spipu/html2pdf

    A possible solution is to add a print button, something like this:

    onclick="window.print();return false;
    

    Then add this to the <head> tag:

    type="text/css" media="print"
    
    Reply

Leave a Comment