DocRaptor

Documentation

HTML-to-PDF with Node

Test API Key: YOUR_API_KEY_HERE

Code Examples

Node

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

1. Install the request module for easy HTTP request management.

$ npm install request

2. Make your docs!

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
    }
  }
};

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

Converting HTML into PDF and XLS documents with Node is fast and painless with DocRaptor. Just POST to our Docs API with your HTML content and some required parameters, either as a form serialized string or a JSON object.

Below you’ll find complete examples for Node, but our API Reference Guide has all the details about the complete workings of the Docs API.

Circledoc@2x

With DocRaptor, your PDF content is HTML and its style is CSS - things you already know! Even still, it can be difficult to get your PDF to look just right. Check out our Style and Formatting Documentation for everything related getting a perfectly styled PDF!