pdfshift@1.0.2
This adaptor exports the following from common:
- as()
- assert()
- combine()
- cursor()
- dataPath()
- dataValue()
- dateFns
- each()
- field()
- fields()
- fn()
- fnIf()
- group()
- lastReferenceValue()
- map()
- merge()
- scrubEmojis()
- sourceValue()
- util
Functions
generatePDF
generatePDF(htmlTemplateString, [options]) ⇒ Operation
Generate a PDF from an HTML string.
Param | Type | Description |
---|---|---|
htmlTemplateString | string | A HTML string or url to convert to PDF |
[options] | PDFBodyOptions | Optional configuration for PDF generation |
This operation writes the following keys to state:
State Key | Description |
---|---|
data | The parsed response body when filename is provided, otherwise a base64-encoded string. |
Example: Generate a PDF from a HTML string
generatePDF(
`<html>
<body>
<h1>Sales Report</h1>
<p>Date: 2025-02-01</p>
<p>Total Sales: $42</p>
</body>
</html>
`);
Example: Generate a PDF with options
generatePDF(
`<html>
<body>
<h1>Sales Report</h1>
<p>Date: 2025-02-01</p>
<p>Total Sales: $42</p>
</body>
</html>
`, {
sandbox: true});
Example: Generate a PDF from a url
generatePDF('https://www.example.com/', {
sandbox: true,
encode: false,
});
Example: Generate a PDF with a filename
generatePDF('https://www.example.com/', {
sandbox: true,
filename: 'example.pdf',
});
request
request(method, path, body, options) ⇒ Operation
Make a general HTTP request to PDFShift
Param | Type | Description |
---|---|---|
method | string | HTTP method to use |
path | string | Path to resource |
body | BodyOptions | Object which will be attached to the POST body |
options | RequestOptions | Optional request options |
This operation writes the following keys to state:
State Key | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an array of all previous data objects used in the Job |
Example: Make a request to convert a HTML string to PDF
request(
'POST',
'/convert/pdf',
{ source: $.html },
);
Interfaces
BodyOptions
PDF Body Options object. See PDFShift documentation for more details.
Properties
Name | Type | Description |
---|---|---|
source | string | The HTML string or url to convert to PDF. |
sandbox | boolean | Generates PDF documents in dev mode that doesn't count in the credits. |
encode | boolean | Return the generated PDF in Base64 encoded format, instead of raw. Defaults to true . |
filename | string | Optional. Must be 7+ characters (letters, numbers, "-" or "_"). If set, the API returns a temporary S3 URL (file kept 2 days); otherwise, it returns a Base64 PDF. |
HttpState
State object
Properties
Name | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an array of all previous data objects used in the Job |
PDFBodyOptions
PDF Body Options object. See PDFShift documentation for more details.
Properties
Name | Type | Description |
---|---|---|
sandbox | boolean | Generates PDF documents in dev mode that doesn't count in the credits. |
encode | boolean | Return the generated PDF in Base64 encoded format, instead of raw. Defaults to true . |
filename | string | Optional. Must be 7+ characters (letters, numbers, "-" or "_"). If set, the API returns a temporary S3 URL (file kept 2 days); otherwise, it returns a Base64 PDF. |
RequestOptions
Options provided to the HTTP request
Properties
Name | Type | Description |
---|---|---|
body | object | string | body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request). |
errors | object | Map of errorCodes -> error messages, ie, { 404: 'Resource not found;' } . Pass false to suppress errors for this code. |
form | object | Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body. |
query | object | An object of query parameters to be encoded into the URL. |
headers | object | An object of headers to append to the request. |
parseAs | string | Parse the response body as json, text or stream. By default will use the response headers. |
timeout | number | Request timeout in ms. Default: 300 seconds. |
tls | object | TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions |