Link Search Menu Expand Document

Parse From Url (Node.js) - JavaScript

Document Parser sample in JavaScript demonstrating ‘Parse From Url (Node.js)’

templateName: Multipage Table Test
templateVersion: 4
templatePriority: 0
  - Sample document with multi-page table
- name: total
  objectType: field
    fieldType: macros
    expression: TOTAL{{Spaces}}({{Number}})
    regex: true
    dataType: decimal
- name: table1
  objectType: table
      expression: Item{{Spaces}}Description{{Spaces}}Price
      regex: true
      expression: TOTAL{{Spaces}}{{Number}}
      regex: true
      expression: '{{LineStart}}{{Spaces}}(?<itemNo>{{Digits}}){{Spaces}}(?<description>{{SentenceWithSingleSpaces}}){{Spaces}}(?<price>{{Number}}){{Spaces}}(?<qty>{{Digits}}){{Spaces}}(?<extPrice>{{Number}})'
      regex: true
    - name: itemNo
      dataType: integer
    - name: description
      dataType: string
    - name: price
      dataType: decimal
    - name: qty
      dataType: integer
    - name: extPrice
      dataType: decimal
    multipage: true

/*jshint esversion: 6 */
var https = require("https");
var fs = require("fs");

// `request` module is required for file upload.
// Use "npm install request" command to install.
var request = require("request");

// The authentication key (API Key).
// Get your own by registering at
const API_KEY = "***********************************";

// Source PDF file
// You can also upload your own file into and use it as url. Check "Upload File" samples for code snippets:    
const SourceFileUrl = "";

// Destination PDF file name
const DestinationFile = "./result.json";

// Template text. Use Document Parser (,
// to create templates.
// Read template from file:
var templateText = fs.readFileSync("./MultiPageTable-template1.yml", "utf-8");

// URL for `Document Parser` API call
var query = ``;
var jsonRequestObject = {
    url: SourceFileUrl,
    template: templateText

        url: query,
        headers: { "x-api-key": API_KEY },
        method: "POST",
        json: true,
        body: jsonRequestObject
    function (error, response, body) {

        if (error) {
            return console.error("Error: ", error);

        // Parse JSON response
        let data = JSON.parse(JSON.stringify(body));

        if (data.error == false) {
            //Download generated file
            var file = fs.createWriteStream(DestinationFile);
            https.get(data.url, (response2) => {
                    .on("close", () => {
                        console.log(`Generated result file saved as "${DestinationFile}" file.`);
        else {
            // Service reported error
            console.log("Error: " + data.message);
); Web API: the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

Get your API key here!

Download Source Code (.zip)

return to the previous page explore Document Parser endpoint