DocRaptor

Documentation

HTML-to-PDF with Node

Test API Key: YOUR_API_KEY_HERE

Code Examples

Generating PDFs with Node.js is as easy as making an HTTP request. The Node.js code below is a functional example of a basic PDF creation.

Installation

Install the request module for easy HTTP request management.

$ npm install request

Basic Usage

var request = require('request');
var fs = require('fs');
var content = "<html><body>TEST!</body></html>";

config = {
  url: 'https://docraptor.com/docs',
  encoding: null, //IMPORTANT! This produces a binary body response instead of text
  headers: {
    'Content-Type': 'application/json'
  },
  json: {
    user_credentials: "YOUR_API_KEY_HERE",
    doc: {
      document_content: content,
      type: "pdf",
      test: true,
      // prince_options: {
      //   media:   "screen",          // use screen styles instead of print styles
      //   baseurl: "http://hello.com" // URL to use for generating absolute URLs for assets from relative URLs
      // }
    }
  }
};

request.post(config, function(err, response, body) {
  fs.writeFile('doc_raptor_sample.pdf', body, "binary", function(writeErr) {
    console.log('Saved!');
  });
});

Next Steps

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