Skip to content

Commit e42c819

Browse files
committed
pdforge init
1 parent 375489e commit e42c819

File tree

4 files changed

+249
-5
lines changed

4 files changed

+249
-5
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import pdforge from "../../pdforge.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "pdforge-generate-pdf-from-html",
6+
name: "Generate PDF from HTML",
7+
description: "Generate a PDF document from HTML content. [See the documentation](https://docs.pdforge.com)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
pdforge,
12+
html: {
13+
propDefinition: [
14+
pdforge,
15+
"html",
16+
],
17+
},
18+
pdfParams: {
19+
propDefinition: [
20+
pdforge,
21+
"pdfParams",
22+
],
23+
optional: true,
24+
},
25+
convertToImage: {
26+
propDefinition: [
27+
pdforge,
28+
"convertToImage",
29+
],
30+
optional: true,
31+
},
32+
s3bucket: {
33+
propDefinition: [
34+
pdforge,
35+
"s3bucket",
36+
],
37+
optional: true,
38+
},
39+
s3key: {
40+
propDefinition: [
41+
pdforge,
42+
"s3key",
43+
],
44+
optional: true,
45+
},
46+
webhook: {
47+
propDefinition: [
48+
pdforge,
49+
"webhook",
50+
],
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.pdforge.generatePDFfromHTML({
56+
html: this.html,
57+
pdfParams: this.pdfParams,
58+
convertToImage: this.convertToImage,
59+
s3bucket: this.s3bucket,
60+
s3key: this.s3key,
61+
webhook: this.webhook,
62+
});
63+
64+
const summary = this.webhook
65+
? `PDF generation initiated with request ID: ${response.requestId}.`
66+
: `PDF generated successfully. Download it using signed URL: ${response.signedUrl}.`;
67+
68+
$.export("$summary", summary);
69+
return response;
70+
},
71+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import pdforge from "../../pdforge.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "pdforge-generate-pdf-from-template",
6+
name: "Generate PDF from Template",
7+
description: "Generate a document from a selected template. [See the documentation](https://docs.pdforge.com/pdfs-from-templates/synchronous-request)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
pdforge,
12+
templateId: {
13+
propDefinition: [
14+
pdforge,
15+
"templateId",
16+
],
17+
},
18+
data: {
19+
propDefinition: [
20+
pdforge,
21+
"data",
22+
],
23+
optional: true,
24+
},
25+
convertToImage: {
26+
propDefinition: [
27+
pdforge,
28+
"convertToImage",
29+
],
30+
optional: true,
31+
},
32+
s3bucket: {
33+
propDefinition: [
34+
pdforge,
35+
"s3bucket",
36+
],
37+
optional: true,
38+
},
39+
s3key: {
40+
propDefinition: [
41+
pdforge,
42+
"s3key",
43+
],
44+
optional: true,
45+
},
46+
webhook: {
47+
propDefinition: [
48+
pdforge,
49+
"webhook",
50+
],
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.pdforge.generateDocumentFromTemplate({
56+
templateId: this.templateId,
57+
data: this.data,
58+
convertToImage: this.convertToImage,
59+
s3bucket: this.s3bucket,
60+
s3key: this.s3key,
61+
webhook: this.webhook,
62+
});
63+
64+
if (this.webhook) {
65+
$.export("$summary", "Asynchronous request initiated. Await the webhook callback for completion.");
66+
} else {
67+
$.export("$summary", `PDF generated successfully from template ID: ${this.templateId}`);
68+
}
69+
70+
return response;
71+
},
72+
};

components/pdforge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

components/pdforge/pdforge.app.mjs

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,112 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "pdforge",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
templateId: {
8+
type: "string",
9+
label: "Template ID",
10+
description: "The ID of the template from which to generate the document",
11+
},
12+
data: {
13+
type: "object",
14+
label: "Data",
15+
description: "The object containing the variables for your PDF template",
16+
optional: true,
17+
},
18+
convertToImage: {
19+
type: "boolean",
20+
label: "Convert to Image",
21+
description: "Whether to convert the PDF to a PNG image",
22+
optional: true,
23+
default: false,
24+
},
25+
s3bucket: {
26+
type: "string",
27+
label: "S3 Bucket",
28+
description: "The ID of the active S3 connection to store the generated file on",
29+
optional: true,
30+
},
31+
s3key: {
32+
type: "string",
33+
label: "S3 Key",
34+
description: "The path and filename without extension for saving the file in the S3 bucket",
35+
optional: true,
36+
},
37+
webhook: {
38+
type: "string",
39+
label: "Webhook URL",
40+
description: "The URL of your webhook endpoint",
41+
optional: true,
42+
},
43+
html: {
44+
type: "string",
45+
label: "HTML",
46+
description: "The HTML content you want to render as PDF",
47+
},
48+
pdfParams: {
49+
type: "object",
50+
label: "PDF Parameters",
51+
description: "PDF parameters to customize the output",
52+
optional: true,
53+
},
54+
},
555
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
56+
_baseUrl() {
57+
return "https://api.pdforge.com/v1";
58+
},
59+
async _makeRequest(opts = {}) {
60+
const {
61+
$ = this, method = "POST", path, headers, ...otherOpts
62+
} = opts;
63+
return axios($, {
64+
...otherOpts,
65+
method,
66+
url: this._baseUrl() + path,
67+
headers: {
68+
...headers,
69+
Authorization: `Bearer ${this.$auth.apiToken}`,
70+
},
71+
});
72+
},
73+
async generateDocumentFromTemplate(opts = {}) {
74+
const {
75+
templateId, data, convertToImage, s3bucket, s3key, webhook,
76+
} = opts;
77+
const path = webhook
78+
? "/pdf/async"
79+
: "/pdf/sync";
80+
return this._makeRequest({
81+
path,
82+
data: {
83+
templateId,
84+
data,
85+
convertToImage,
86+
s3_bucket: s3bucket,
87+
s3_key: s3key,
88+
webhook,
89+
},
90+
});
91+
},
92+
async generatePDFfromHTML(opts = {}) {
93+
const {
94+
html, pdfParams, convertToImage, s3bucket, s3key, webhook,
95+
} = opts;
96+
const path = webhook
97+
? "/html-to-pdf/async"
98+
: "/html-to-pdf/sync";
99+
return this._makeRequest({
100+
path,
101+
data: {
102+
html,
103+
pdfParams,
104+
convertToImage,
105+
s3_bucket: s3bucket,
106+
s3_key: s3key,
107+
webhook,
108+
},
109+
});
9110
},
10111
},
11112
};

0 commit comments

Comments
 (0)