DocRaptor Home

How to Make a PDF or Excel Document

Examples & Agents by Programming Languages > Making Documents with 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: '',
  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: "" // URL to use for generating absolute URLs for assets from relative URLs
      // }
};, function(err, response, body) {
  fs.writeFile('doc_raptor_sample.pdf', body, "binary", function(writeErr) {

Ready to get started? Try DocRaptor for free with unlimited test documents.