npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@datafire/pdfgeneratorapi

v3.0.0

Published

DataFire integration for PDF Generator API

Downloads

14

Readme

@datafire/pdfgeneratorapi

Client library for PDF Generator API

Installation and Usage

npm install --save @datafire/pdfgeneratorapi
let pdfgeneratorapi = require('@datafire/pdfgeneratorapi').create({
  JSONWebTokenAuth: ""
});

.then(data => {
  console.log(data);
});

Description

Introduction

PDF Generator API allows you easily generate transactional PDF documents and reduce the development and support costs by enabling your users to create and manage their document templates using a browser-based drag-and-drop document editor.

The PDF Generator API features a web API architecture, allowing you to code in the language of your choice. This API supports the JSON media type, and uses UTF-8 character encoding.

You can find our previous API documentation page with references to Simple and Signature authentication here.

Base URL

The base URL for all the API endpoints is https://us1.pdfgeneratorapi.com/api/v3

For example

  • https://us1.pdfgeneratorapi.com/api/v3/templates
  • https://us1.pdfgeneratorapi.com/api/v3/workspaces
  • https://us1.pdfgeneratorapi.com/api/v3/templates/123123

Editor

PDF Generator API comes with a powerful drag & drop editor that allows to create any kind of document templates, from barcode labels to invoices, quotes and reports. You can find tutorials and videos from our Support Portal.

Definitions

Organization

Organization is a group of workspaces owned by your account.

Workspace

Workspace contains templates. Each workspace has access to their own templates and organization default templates.

Master Workspace

Master Workspace is the main/default workspace of your Organization. The Master Workspace identifier is the email you signed up with.

Default Template

Default template is a template that is available for all workspaces by default. You can set the template access type under Page Setup. If template has "Organization" access then your users can use them from the "New" menu in the Editor.

Data Field

Data Field is a placeholder for the specific data in your JSON data set. In this example JSON you can access the buyer name using Data Field {paymentDetails::buyerName}. The separator between depth levels is :: (two colons). When designing the template you don’t have to know every Data Field, our editor automatically extracts all the available fields from your data set and provides an easy way to insert them into the template.

{
    "documentNumber": 1,
    "paymentDetails": {
        "method": "Credit Card",
        "buyerName": "John Smith"
    },
    "items": [
        {
            "id": 1,
            "name": "Item one"
        }
    ]
}

Authentication

The PDF Generator API uses JSON Web Tokens (JWT) to authenticate all API requests. These tokens offer a method to establish secure server-to-server authentication by transferring a compact JSON object with a signed payload of your account’s API Key and Secret. When authenticating to the PDF Generator API, a JWT should be generated uniquely by a server-side application and included as a Bearer Token in the header of each request.

Legacy Simple and Signature authentication

You can find our legacy documentation for Simple and Signature authentication here.

Accessing your API Key and Secret

You can find your API Key and API Secret from the Account Settings page after you login to PDF Generator API here.

Creating a JWT

JSON Web Tokens are composed of three sections: a header, a payload (containing a claim set), and a signature. The header and payload are JSON objects, which are serialized to UTF-8 bytes, then encoded using base64url encoding.

The JWT's header, payload, and signature are concatenated with periods (.). As a result, a JWT typically takes the following form:

{Base64url encoded header}.{Base64url encoded payload}.{Base64url encoded signature}

We recommend and support libraries provided on jwt.io. While other libraries can create JWT, these recommended libraries are the most robust.

Header

Property alg defines which signing algorithm is being used. PDF Generator API users HS256. Property typ defines the type of token and it is always JWT.

{
  "alg": "HS256",
  "typ": "JWT"
}

Payload

The second part of the token is the payload, which contains the claims or the pieces of information being passed about the user and any metadata required. It is mandatory to specify the following claims:

  • issuer (iss): Your API key
  • subject (sub): Workspace identifier
  • expiration time (exp): Timestamp (unix epoch time) until the token is valid. It is highly recommended to set the exp timestamp for a short period, i.e. a matter of seconds. This way, if a token is intercepted or shared, the token will only be valid for a short period of time.
{
  "iss": "ad54aaff89ffdfeff178bb8a8f359b29fcb20edb56250b9f584aa2cb0162ed4a",
  "sub": "[email protected]",
  "exp": 1586112639
}

Signature

To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that. The signature is used to verify the message wasn't changed along the way, and, in the case of tokens signed with a private key, it can also verify that the sender of the JWT is who it says it is.

HMACSHA256(
    base64UrlEncode(header) + "." +
    base64UrlEncode(payload),
    API_SECRET)

Putting all together

The output is three Base64-URL strings separated by dots. The following shows a JWT that has the previous header and payload encoded, and it is signed with a secret.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhZDU0YWFmZjg5ZmZkZmVmZjE3OGJiOGE4ZjM1OWIyOWZjYjIwZWRiNTYyNTBiOWY1ODRhYTJjYjAxNjJlZDRhIiwic3ViIjoiZGVtby5leGFtcGxlQGFjdHVhbHJlcG9ydHMuY29tIn0.SxO-H7UYYYsclS8RGWO1qf0z1cB1m73wF9FLl9RCc1Q

// Base64 encoded header: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
// Base64 encoded payload: eyJpc3MiOiJhZDU0YWFmZjg5ZmZkZmVmZjE3OGJiOGE4ZjM1OWIyOWZjYjIwZWRiNTYyNTBiOWY1ODRhYTJjYjAxNjJlZDRhIiwic3ViIjoiZGVtby5leGFtcGxlQGFjdHVhbHJlcG9ydHMuY29tIn0
// Signature: SxO-H7UYYYsclS8RGWO1qf0z1cB1m73wF9FLl9RCc1Q

Testing with JWTs

You can create a temporary token in Account Settings page after you login to PDF Generator API. The generated token uses your email address as the subject (sub) value and is valid for 5 minutes. You can also use jwt.io to generate test tokens for your API calls. These test tokens should never be used in production applications.


Libraries and SDKs

Postman Collection

We have created a Postman Collection so you can easily test all the API endpoints wihtout developing and code. You can download the collection here or just click the button below.

Run in Postman

Client Libraries

All our Client Libraries are auto-generated using OpenAPI Generator which uses the OpenAPI v3 specification to automatically generate a client library in specific programming language.

We have validated the generated libraries, but let us know if you find any anomalies in the client code.


Actions

getTemplates

Returns a list of templates available for the authenticated workspace

pdfgeneratorapi.getTemplates(null, context)

Input

This action has no parameters

Output

  • output object

createTemplate

Creates a new template. If template configuration is not specified in the request body then an empty template is created. Template is placed to the workspace specified in authentication params. Template configuration must be sent in the request body.

pdfgeneratorapi.createTemplate({
  "body": {
    "name": ""
  }
}, context)

Input

Output

mergeTemplates

Allows to merge multiples template with data and returns base64 encoded document or public url to a document.

pdfgeneratorapi.mergeTemplates({
  "body": []
}, context)

Input

  • input object
    • name string: Document name, returned in the meta data.
    • format string (values: pdf, html, zip, xlsx): Document format. The zip option will return a ZIP file with PDF files.
    • output string (values: base64, url, I): Response format.
    • body required BatchData

Output

  • output object
    • meta object
      • content-type string: Document content type.
      • display_name string: Document name without the file extension.
      • encoding string: Document encoding
      • name string: Document name. This value is automatically generated if name attribute is not defined in request.
    • response string: Base64 encoded document if the output=base64 is used or URL to the document when the output=url is used.

deleteTemplate

Deletes the template from workspace

pdfgeneratorapi.deleteTemplate({
  "templateId": 0
}, context)

Input

  • input object
    • templateId required integer: Template unique identifier

Output

  • output object
    • response object
      • success boolean

getTemplate

Returns template configuration

pdfgeneratorapi.getTemplate({
  "templateId": 0
}, context)

Input

  • input object
    • templateId required integer: Template unique identifier

Output

updateTemplate

Updates template configuration. The template configuration for pages and layout must be complete as the entire configuration is replaced and not merged.

pdfgeneratorapi.updateTemplate({
  "templateId": 0,
  "body": {
    "name": ""
  }
}, context)

Input

Output

copyTemplate

Creates a copy of a template to the workspace specified in authentication parameters.

pdfgeneratorapi.copyTemplate({
  "templateId": 0
}, context)

Input

  • input object
    • templateId required integer: Template unique identifier
    • name string: Name for the copied template. If name is not specified then the original name is used.

Output

getEditorUrl

Returns an unique URL which you can use to redirect your user to the editor form your application or use the generated URL as iframe source to show the editor within your application.

pdfgeneratorapi.getEditorUrl({
  "templateId": 0,
  "body": {}
}, context)

Input

  • input object
    • templateId required integer: Template unique identifier
    • language string (values: en, et, cs, sk, ru): Specify the editor UI language. Defaults to organization editor language.
    • body required object

Output

  • output object
    • response string

mergeTemplate

Merges template with data and returns base64 encoded document or a public URL to a document. You can send json encoded data in request body or a public URL to your json file as the data parameter.

pdfgeneratorapi.mergeTemplate({
  "templateId": 0,
  "body": {}
}, context)

Input

  • input object
    • templateId required integer: Template unique identifier
    • name string: Document name, returned in the meta data.
    • format string (values: pdf, html, zip, xlsx): Document format. The zip option will return a ZIP file with PDF files.
    • output string (values: base64, url, I): Response format.
    • body required Data

Output

  • output object
    • meta object
      • content-type string: Document content type.
      • display_name string: Document name without the file extension.
      • encoding string: Document encoding
      • name string: Document name. This value is automatically generated if name attribute is not defined in request.
    • response string: Base64 encoded document if the output=base64 is used or URL to the document when the output=url is used.

deleteWorkspace

Deletes the workspace

pdfgeneratorapi.deleteWorkspace({
  "workspaceId": ""
}, context)

Input

  • input object
    • workspaceId required string: Workspace identifier

Output

  • output object
    • response object
      • success boolean

getWorkspace

Returns workspace information

pdfgeneratorapi.getWorkspace({
  "workspaceId": ""
}, context)

Input

  • input object
    • workspaceId required string: Workspace identifier

Output

Definitions

BatchData

  • BatchData array
    • items object
      • data Data
      • template integer: Template id

Component

  • Component object: Template component definition
    • cls string (values: labelComponent, numberComponent, textComponent, imageComponent, dateComponent, hlineComponent, vlineComponent, tableComponent, compositeComponent, barcodeComponent, qrcodeComponent, chartComponent, rectangleComponent, headerComponent, footerComponent, checkboxComponent, radioComponent): Defines component class/type
    • dataIndex string: Defines data field for Table and Container components which are used to iterate over list of items
    • height number: Height in units
    • id string: Component id
    • left number: Position from the page left in units
    • top number: Position from the page top in units
    • value string: Component value
    • width number: Width in units
    • zindex integer: Defines the rendering order on page. Components with smaller zindex are rendered before

Data

  • Data object
    • id integer
    • name string

Template

  • Template object: Template object
    • tags array: A list of tags assigned to a template
      • items string
    • id integer: Unique identifier
    • modified string: Timestamp when the template was modified
    • name string: Template name
    • owner boolean: Indicates if the workspace is the owner of the template

TemplateDefinition

  • TemplateDefinition object
    • tags array: A list of tags assigned to a template
      • items string
    • dataSettings object: Defines filter and sort option for root data set.
      • filterBy array
        • items object
      • sortBy array
        • items object
    • editor object: Configuration preferences for the editor
      • heightMultiplier number
    • id integer: Unique identifier
    • isDraft boolean: Indicates if the template is a draft or published.
    • layout object: Defines template layout (e.g page format, margins).
      • emptyLabels integer: Defines how many pages or labels should be empty
      • format string (values: A4, letter, custom): Defines template page size
      • height number: Page height in units
      • margins object: Page margins in units
        • bottom number
        • left number
        • right number
        • top number
      • orientation string (values: portrait, landscape): Page orientation
      • repeatLayout object: Defines page size if layout is repeated on the page e.g sheet labels
        • format string (values: A4, letter, custom): Defines template page size
        • height number: Page height in units
        • width number: Page width in units
      • rotation integer (values: 0, 90, 180, 270): Page rotation in degrees
      • unit string (values: cm, in): Measure unit
      • width number: Page width in units
    • name string: Template name
    • pages array: Defines page or label size, margins and components on page or label
      • items object
        • components array
        • height number: Page height in units
        • margins object
          • bottom number: Page or label margin from bottom
          • right number: Page or label margin from right
        • width number: Page width in units

TemplateDefinitionNew

  • TemplateDefinitionNew object: Template configuration
    • tags array: A list of tags assigned to a template
      • items string
    • isDraft boolean: Indicates if the template is a draft or published.
    • layout object: Defines template layout (e.g page format, margins).
      • emptyLabels integer: Defines how many pages or labels should be empty
      • format string (values: A4, letter, custom): Defines template page size
      • height number: Page height in units
      • margins object: Page margins in units
        • bottom number
        • left number
        • right number
        • top number
      • orientation string (values: portrait, landscape): Page orientation
      • repeatLayout object: Defines page size if layout is repeated on the page e.g sheet labels
        • format string (values: A4, letter, custom): Defines template page size
        • height number: Page height in units
        • width number: Page width in units
      • rotaion integer (values: 0, 90, 180, 270): Page rotation in degrees
      • unit string (values: cm, in): Measure unit
      • width number: Page width in units
    • name required string: Template name
    • pages array: Defines page or label size, margins and components on page or label
      • items object
        • components array
        • height number: Page height in units
        • margins object
          • bottom number: Page or label margin from bottom
          • right number: Page or label margin from right
        • width number: Page width in units

Workspace

  • Workspace object
    • created_at string
    • id integer: Internal workspace id
    • identifier string: The unique workspace idenfitifer specified by your application
    • is_master_workspace boolean: True if a master workspace