DocRaptor

Documentation

HTML-to-PDF with jQuery

Test API Key: YOUR_API_KEY_HERE

Code Examples

jQuery & JavaScript

The DocRaptor JavaScript library makes it easy to create PDFs with JavaScript. The library does not require jQuery, but you can use jQuery to define your document content. When a PDF is requested, the library constructs a hidden form and submits it to the DocRaptor API. Until all modern browsers support the download link attribute, using this hidden form is the best way to generate a file download directly from JavaScript.

Warning: This code exposes your API key in your website source code. This code should not be used in a publicly-accessible location, instead try using a server-side agent such as PHP or Ruby.

Example Code


<head>
  <script src="http://docraptor.com/docraptor-1.0.0.js"></script>
  <script>
    var downloadPDF = function() {
      DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
        test: true, // test documents are free, but watermarked
        type: "pdf",
        document_content: document.querySelector('html').innerHTML, // use this page's HTML
        // document_content: "<h1>Hello world!</h1>",               // or supply HTML directly
        // document_url: "http://example.com/your-page",            // or use a URL
        // javascript: true,                                        // enable JavaScript processing
        // prince_options: {
        //   media: "screen",                                       // use screen styles instead of print styles
        // }
      })
    }
  </script>
  <style>
    @media print {
      #pdf-button {
        display: none;
      }
    }
  </style>
</head>
<body>
  <h1>Example!</h1>
  <input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</body>








With DocRaptor, it's fast and painless to convert HTML, CSS, and JavaScript into PDF and XLS documents with jQuery. Below are working jQuery examples for creating documents. Our API reference lists all the generation options and our style and formatting guide will help make it look perfect.