Javascript wrapper for PDF Generator API
PDFGeneratorAPI - JavaScript client for pdf-generator-api-client
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.
https://us1.pdfgeneratorapi.com/api/v4For example
* https://us1.pdfgeneratorapi.com/api/v4/templates
* https://us1.pdfgeneratorapi.com/api/v4/workspaces
* https://us1.pdfgeneratorapi.com/api/v4/templates/123123
{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"
}
]
}
`Rate limiting
Our API endpoints use IP-based rate limiting and allow you to make up to 2 requests per second and 60 requests per minute. If you make more requests, you will receive a response with HTTP code 429.Response headers contain additional values:
| Header | Description |
|--------|--------------------------------|
| X-RateLimit-Limit | Maximum requests per minute |
| X-RateLimit-Remaining | The requests remaining in the current minute |
| Retry-After | How many seconds you need to wait until you are allowed to make requests |
*
Libraries and SDKs
Postman Collection
We have created a Postman Collection so you can easily test all the API endpoints without developing and code. You can download the collection here.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.* PHP Client
* Java Client
* Ruby Client
* Python Client
* Javascript Client
We have validated the generated libraries, but let us know if you find any anomalies in the client code.
*
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.
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.
$3
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"
}
`$3
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": "demo.example@actualreports.com",
"exp": 1586112639
}
`$3
Our partners can send their unique identifier (provided by us) in JWT's partner_id claim. If the partner_id value is specified in the JWT, the organization making the request is automatically connected to the partner account.
* Partner ID (partner_id): Unique identifier provide by PDF Generator API team`
{
"iss": "ad54aaff89ffdfeff178bb8a8f359b29fcb20edb56250b9f584aa2cb0162ed4a",
"sub": "demo.example@actualreports.com",
"partner_id": "my-partner-identifier",
"exp": 1586112639
}
`$3
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)
`$3
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
`Temporary 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 __15 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.
*Error codes
| Code | Description |
|--------|--------------------------------|
| 401 | Unauthorized |
| 402 | Payment Required |
| 403 | Forbidden |
| 404 | Not Found |
| 422 | Unprocessable Entity |
| 429 | Too Many Requests |
| 500 | Internal Server Error |
401 Unauthorized
| 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 |402 Payment Required
| Description |
|-------------------------------------------------------------------------|
| Your account is suspended, please upgrade your account |403 Forbidden
| 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. |404 Entity not found
| Description |
|-------------------------------------------------------------------------|
| Entity not found |
| Resource not found |
| None of the templates is available for the workspace. |422 Unprocessable Entity
| Description |
|-------------------------------------------------------------------------|
| Unable to parse JSON, please check formatting |
| Required parameter missing |
| Required parameter missing: template definition not defined |
| Required parameter missing: template not defined |429 Too Many Requests
| Description |
|-------------------------------------------------------------------------|
| You can make up to 2 requests per second and 60 requests per minute. | *
This SDK is automatically generated by the OpenAPI Generator project:
- API version: 4.0.12
- Package version: 4.0.12
- Generator version: 7.11.0
- Build package: org.openapitools.codegen.languages.JavascriptClientCodegen
For more information, please visit https://support.pdfgeneratorapi.com
Installation
$3
#### npm
To publish the library as a npm, please follow the procedure in "Publishing npm packages".
Then install it via:
`shell
npm install pdf-generator-api-client --save
`Finally, you need to build the module:
`shell
npm run build
`##### Local development
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:`shell
npm install
`Next, link it globally in npm with the following, also from
JAVASCRIPT_CLIENT_DIR:`shell
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:
`shell
npm link /path/to/
`Finally, you need to build the module:
`shell
npm run build
`#### git
If the library is hosted at a git repository, e.g.https://github.com/pdfgeneratorapi/javascript-client
then install it via:
`shell
npm install pdfgeneratorapi/javascript-client --save
`$3
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):`shell
browserify main.js > bundle.js
`Then include bundle.js in the HTML pages.
$3
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:
`javascript
module: {
rules: [
{
parser: {
amd: false
}
}
]
}
`Getting Started
Please follow the installation instruction and execute the following JS code:
`javascript
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.ConversionApi()
var convert_html2_pdf_request = new PDFGeneratorAPI.ConvertHTML2PDFRequest(); // {ConvertHTML2PDFRequest}
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
api.convertHTML2PDF(convert_html2_pdf_request, callback);
``All URIs are relative to https://us1.pdfgeneratorapi.com/api/v4
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
PDFGeneratorAPI.ConversionApi | convertHTML2PDF | POST /conversion/html2pdf | HTML to PDF
PDFGeneratorAPI.ConversionApi | convertURL2PDF | POST /conversion/url2pdf | URL to PDF
PDFGeneratorAPI.DocumentsApi | deleteDocument | DELETE /documents/{publicId} | Delete document
PDFGeneratorAPI.DocumentsApi | generateDocument | POST /documents/generate | Generate document
PDFGeneratorAPI.DocumentsApi | generateDocumentAsynchronous | POST /documents/generate/async | Generate document (async)
PDFGeneratorAPI.DocumentsApi | generateDocumentBatch | POST /documents/generate/batch | Generate document (batch)
PDFGeneratorAPI.DocumentsApi | generateDocumentBatchAsynchronous | POST /documents/generate/batch/async | Generate document (batch + async)
PDFGeneratorAPI.DocumentsApi | getDocument | GET /documents/{publicId} | Get document
PDFGeneratorAPI.DocumentsApi | getDocuments | GET /documents | Get documents
PDFGeneratorAPI.FormsApi | createFrom | POST /forms | Create form
PDFGeneratorAPI.FormsApi | deleteForm | DELETE /forms/{formId} | Delete form
PDFGeneratorAPI.FormsApi | getForm | GET /forms/{formId} | Get form
PDFGeneratorAPI.FormsApi | getForms | GET /forms | Get forms
PDFGeneratorAPI.FormsApi | shareForm | POST /forms/{formId}/share | Share form
PDFGeneratorAPI.FormsApi | updateForm | PUT /forms/{formId} | Update form
PDFGeneratorAPI.MiscApi | getStatus | GET /status | Get Service Status
PDFGeneratorAPI.ServicesApi | addWatermark | POST /pdfservices/watermark | Add watermark
PDFGeneratorAPI.ServicesApi | decryptDocument | POST /pdfservices/decrypt | Decrypt document
PDFGeneratorAPI.ServicesApi | encryptDocument | POST /pdfservices/encrypt | Encrypt document
PDFGeneratorAPI.ServicesApi | extractFormFields | POST /pdfservices/form/fields | Extract form fields
PDFGeneratorAPI.ServicesApi | fillFormFields | POST /pdfservices/form/fill | Fill form fields
PDFGeneratorAPI.ServicesApi | optimizeDocument | POST /pdfservices/optimize | Optimize document
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 | getTemplate | GET /templates/{templateId} | Get template
PDFGeneratorAPI.TemplatesApi | getTemplateData | GET /templates/{templateId}/data | Get template data fields
PDFGeneratorAPI.TemplatesApi | getTemplates | GET /templates | Get templates
PDFGeneratorAPI.TemplatesApi | openEditor | POST /templates/{templateId}/editor | Open editor
PDFGeneratorAPI.TemplatesApi | updateTemplate | PUT /templates/{templateId} | Update template
PDFGeneratorAPI.TemplatesApi | validateTemplate | POST /templates/validate | Validate template
PDFGeneratorAPI.WorkspacesApi | createWorkspace | POST /workspaces | Create workspace
PDFGeneratorAPI.WorkspacesApi | deleteWorkspace | DELETE /workspaces/{workspaceIdentifier} | Delete workspace
PDFGeneratorAPI.WorkspacesApi | getWorkspace | GET /workspaces/{workspaceIdentifier} | Get workspace
PDFGeneratorAPI.WorkspacesApi | getWorkspaces | GET /workspaces | Get workspaces
- PDFGeneratorAPI.AddWatermark201Response
- PDFGeneratorAPI.AddWatermark201ResponseMeta
- PDFGeneratorAPI.AddWatermark401Response
- PDFGeneratorAPI.AddWatermark402Response
- PDFGeneratorAPI.AddWatermark403Response
- PDFGeneratorAPI.AddWatermark404Response
- PDFGeneratorAPI.AddWatermark422Response
- PDFGeneratorAPI.AddWatermark429Response
- PDFGeneratorAPI.AddWatermark500Response
- PDFGeneratorAPI.AddWatermarkRequest
- PDFGeneratorAPI.AsyncOutputParam
- PDFGeneratorAPI.CallbackParam
- PDFGeneratorAPI.Component
- PDFGeneratorAPI.ConvertHTML2PDFRequest
- PDFGeneratorAPI.ConvertURL2PDFRequest
- PDFGeneratorAPI.CopyTemplateRequest
- PDFGeneratorAPI.CreateFrom201Response
- PDFGeneratorAPI.CreateTemplate201Response
- PDFGeneratorAPI.CreateWorkspace201Response
- PDFGeneratorAPI.CreateWorkspaceRequest
- PDFGeneratorAPI.DataBatchInner
- PDFGeneratorAPI.Document
- PDFGeneratorAPI.EncryptAndDecryptBase64
- PDFGeneratorAPI.EncryptAndDecryptUrl
- PDFGeneratorAPI.EncryptDocumentRequest
- PDFGeneratorAPI.ExtractFormFields200Response
- PDFGeneratorAPI.ExtractFormFields200ResponseResponseValue
- PDFGeneratorAPI.ExtractFormFields200ResponseResponseValueDefault
- PDFGeneratorAPI.ExtractFormFields200ResponseResponseValueValue
- PDFGeneratorAPI.ExtractFormFieldsRequest
- PDFGeneratorAPI.FillFormFieldsRequest
- PDFGeneratorAPI.FormActionDownload
- PDFGeneratorAPI.FormActionStore
- PDFGeneratorAPI.FormConfiguration
- PDFGeneratorAPI.FormConfigurationNew
- PDFGeneratorAPI.FormConfigurationNewActionsInner
- PDFGeneratorAPI.FormFieldsBase64
- PDFGeneratorAPI.FormFieldsInner
- PDFGeneratorAPI.FormFieldsUrl
- PDFGeneratorAPI.FormFillBase64
- PDFGeneratorAPI.FormFillUrl
- PDFGeneratorAPI.FormatParam
- PDFGeneratorAPI.GenerateDocumentAsynchronous201Response
- PDFGeneratorAPI.GenerateDocumentAsynchronous201ResponseResponse
- PDFGeneratorAPI.GenerateDocumentAsynchronousRequest
- PDFGeneratorAPI.GenerateDocumentBatchAsynchronousRequest
- PDFGeneratorAPI.GenerateDocumentBatchRequest
- PDFGeneratorAPI.GenerateDocumentRequest
- PDFGeneratorAPI.GetDocument200Response
- PDFGeneratorAPI.GetDocument200ResponseMeta
- PDFGeneratorAPI.GetDocuments200Response
- PDFGeneratorAPI.GetForms200Response
- PDFGeneratorAPI.GetStatus200Response
- PDFGeneratorAPI.GetTemplateData200Response
- PDFGeneratorAPI.GetTemplates200Response
- PDFGeneratorAPI.GetWorkspaces200Response
- PDFGeneratorAPI.InlineObject
- PDFGeneratorAPI.InlineObjectResponse
- PDFGeneratorAPI.OpenEditor200Response
- PDFGeneratorAPI.OpenEditorRequest
- PDFGeneratorAPI.OpenEditorRequestData
- PDFGeneratorAPI.OptimizeBase64
- PDFGeneratorAPI.OptimizeDocument201Response
- PDFGeneratorAPI.OptimizeDocument201ResponseMeta
- PDFGeneratorAPI.OptimizeDocument201ResponseMetaStats
- PDFGeneratorAPI.OptimizeDocumentRequest
- PDFGeneratorAPI.OptimizeUrl
- PDFGeneratorAPI.OutputParam
- PDFGeneratorAPI.PaginationMeta
- PDFGeneratorAPI.ShareForm201Response
- PDFGeneratorAPI.ShareForm201ResponseMeta
- PDFGeneratorAPI.Template
- PDFGeneratorAPI.TemplateDefinition
- PDFGeneratorAPI.TemplateDefinitionDataSettings
- PDFGeneratorAPI.TemplateDefinitionEditor
- PDFGeneratorAPI.TemplateDefinitionNew
- PDFGeneratorAPI.TemplateDefinitionNewDataSettings
- PDFGeneratorAPI.TemplateDefinitionNewEditor
- PDFGeneratorAPI.TemplateDefinitionNewLayout
- PDFGeneratorAPI.TemplateDefinitionNewLayoutMargins
- PDFGeneratorAPI.TemplateDefinitionNewLayoutRepeatLayout
- PDFGeneratorAPI.TemplateDefinitionNewPagesInner
- PDFGeneratorAPI.TemplateDefinitionNewPagesInnerMargins
- PDFGeneratorAPI.TemplateDefinitionPagesInner
- PDFGeneratorAPI.TemplateParam
- PDFGeneratorAPI.TemplateParamData
- PDFGeneratorAPI.ValidateTemplate200Response
- PDFGeneratorAPI.ValidateTemplate200ResponseResponse
- PDFGeneratorAPI.WatermarkBase64
- PDFGeneratorAPI.WatermarkFileUrlWatermark
- PDFGeneratorAPI.WatermarkImage
- PDFGeneratorAPI.WatermarkImageContentBase64
- PDFGeneratorAPI.WatermarkImageContentUrl
- PDFGeneratorAPI.WatermarkPosition
- PDFGeneratorAPI.WatermarkText
- PDFGeneratorAPI.Workspace
Authentication schemes defined for the API:
- Type: Bearer authentication (JWT)