Generate a signature token for viewing private documents

CloudPDF is using tokens for authentication of private documents. Unless you change the security settings of a document you need to generate a token in order to access it. Your backend generates a token and on the client you will add it to the CloudPDF viewer. The viewer will send the token to the CloudPDF server which verifies if the token is valid. If the token is valid it will send the document information and the document will be visible.

import { CloudPDF } from '@cloudpdf/api';
const cloudpdf = new CloudPDF({
apiKey: 'YOUR API KEY',
cloudName: 'YOUR CLOUD NAME',
signingSecret: 'YOUR SIGNING SECRET'
});
const key = cloudPDF.getViewerToken({
id: 'your document id',
download: "Allowed",
search: false,
selection: false
}, '1h')

The first parameter of the function is an object which can have the following options:

  • id your document ID. where to find your document id?
  • download if set to "NotAllowed" the document is not downloadable. If set to "Allowed", the document is downloadable
  • search if set to false the document is not searchable
  • selection if set to false the document text is not selectable

The second parameter is the token expiry date and can have the following value:

Eg:60,"2 days","10h","7d". A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default ("120"is equal to"120ms").