![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@toosick/pdf-generator-api-client
Advanced tools
PDFGeneratorAPI - JavaScript client for pdf-generator-api-client
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.
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
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.
Organization is a group of workspaces owned by your account.
Workspace contains templates. Each workspace has access to their own templates and organization default templates.
Master Workspace is the main/default workspace of your Organization. The Master Workspace identifier is the email you signed up with.
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 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"
}
]
}
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.
You can find our legacy documentation for Simple and Signature authentication here.
You can find your API Key and API Secret from the Account Settings page after you login to PDF Generator API here.
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.
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"
}
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:
iss
): Your API keysub
): Workspace identifierexp
): 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": "demo.example@actualreports.com",
"exp": 1586112639
}
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)
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
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.
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.
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.
Code | Description |
---|---|
401 | Unauthorized |
403 | Forbidden |
404 | Not Found |
422 | Unprocessable Entity |
500 | Internal Server Error |
Description |
---|
Authentication failed: request expired |
Authentication failed: workspace missing |
Authentication failed: key missing |
Authentication failed: property 'iss' (issuer) missing in JWT |
Authentication failed: property 'sub' (subject) missing in JWT |
Authentication failed: property 'exp' (expiration time) missing in JWT |
Authentication failed: incorrect signature |
Description |
---|
Your account has exceeded the monthly document generation limit. |
Access not granted: You cannot delete master workspace via API |
Access not granted: Template is not accessible by this organization |
Your session has expired, please close and reopen the editor. |
Description |
---|
Entity not found |
Resource not found |
None of the templates is available for the workspace. |
Description |
---|
Unable to parse JSON, please check formatting |
Required parameter missing |
Required parameter missing: template definition not defined |
Required parameter missing: template not defined |
This SDK is automatically generated by the OpenAPI Generator project:
To publish the library as a npm, please follow the procedure in "Publishing npm packages".
Then install it via:
npm install pdf-generator-api-client --save
Finally, you need to build the module:
npm run build
To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json
(and this README). Let's call this JAVASCRIPT_CLIENT_DIR
. Then run:
npm install
Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR
:
npm link
To use the link you just defined in your project, switch to the directory you want to use your pdf-generator-api-client from, and run:
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>
Finally, you need to build the module:
npm run build
If the library is hosted at a git repository, e.g.https://github.com/pdfgeneratorapi/javascript-client then install it via:
npm install pdfgeneratorapi/javascript-client --save
The library also works in the browser environment via npm and browserify. After following
the above steps with Node.js and installing browserify with npm install -g browserify
,
perform the following (assuming main.js is your entry file):
browserify main.js > bundle.js
Then include bundle.js in the HTML pages.
Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:
module: {
rules: [
{
parser: {
amd: false
}
}
]
}
Please follow the installation instruction and execute the following JS code:
var PDFGeneratorAPI = require('pdf-generator-api-client');
var defaultClient = PDFGeneratorAPI.ApiClient.instance;
// Configure Bearer (JWT) access token for authorization: JSONWebTokenAuth
var JSONWebTokenAuth = defaultClient.authentications['JSONWebTokenAuth'];
JSONWebTokenAuth.accessToken = "YOUR ACCESS TOKEN"
var api = new PDFGeneratorAPI.DocumentsApi()
var template_id = 19375; // {Number} Template unique identifier
var data = new PDFGeneratorAPI.Data(); // {Data} Data used to generate the PDF. This can be JSON encoded string or a public URL to your JSON file.
var opts = {
'name': My document, // {String} Document name, returned in the meta data.
'format': pdf, // {String} Document format. The zip option will return a ZIP file with PDF files.
'output': base64 // {String} Response format. With the url option, the document is stored for 30 days and automatically deleted.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
api.mergeTemplate(template_id, data, opts, callback);
All URIs are relative to https://us1.pdfgeneratorapi.com/api/v3
Class | Method | HTTP request | Description |
---|---|---|---|
PDFGeneratorAPI.DocumentsApi | mergeTemplate | POST /templates/{templateId}/output | Generate document |
PDFGeneratorAPI.DocumentsApi | mergeTemplates | POST /templates/output | Generate document (multiple templates) |
PDFGeneratorAPI.TemplatesApi | copyTemplate | POST /templates/{templateId}/copy | Copy template |
PDFGeneratorAPI.TemplatesApi | createTemplate | POST /templates | Create template |
PDFGeneratorAPI.TemplatesApi | deleteTemplate | DELETE /templates/{templateId} | Delete template |
PDFGeneratorAPI.TemplatesApi | getEditorUrl | POST /templates/{templateId}/editor | Open editor |
PDFGeneratorAPI.TemplatesApi | getTemplate | GET /templates/{templateId} | Get template |
PDFGeneratorAPI.TemplatesApi | getTemplates | GET /templates | Get templates |
PDFGeneratorAPI.TemplatesApi | updateTemplate | PUT /templates/{templateId} | Update template |
PDFGeneratorAPI.WorkspacesApi | deleteWorkspace | DELETE /workspaces/{workspaceId} | Delete workspace |
PDFGeneratorAPI.WorkspacesApi | getWorkspace | GET /workspaces/{workspaceId} | Get workspace |
FAQs
Javascript wrapper for PDF Generator API
We found that @toosick/pdf-generator-api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.