-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - pdf4me #16174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - pdf4me #16174
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c459454
new components
michelle0927 f920345
pnpm-lock.yaml
michelle0927 1f2a7a5
fix prop
michelle0927 a96e084
Update components/pdf4me/common/utils.mjs
michelle0927 d3a6316
error handling
michelle0927 8abd8e6
Merge remote-tracking branch 'origin/master' into issue-16099
michelle0927 22a07d5
pnpm-lock.yaml
michelle0927 bd501eb
updates
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import pdf4me from "../../pdf4me.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
| import fs from "fs"; | ||
|
|
||
| export default { | ||
| key: "pdf4me-compress-pdf", | ||
| name: "Compress PDF", | ||
| description: "Compress a PDF file to reduce its size. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/compress-pdf/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdf4me, | ||
| filePath: { | ||
| propDefinition: [ | ||
| pdf4me, | ||
| "filePath", | ||
| ], | ||
| }, | ||
| optimizeProfile: { | ||
| type: "string", | ||
| label: "Optimize Profile", | ||
| description: "The type of compression", | ||
| options: [ | ||
| "Max", | ||
| "Web", | ||
| "Print", | ||
| "Default", | ||
| "WebMax", | ||
| "PrintMax", | ||
| "PrintGray", | ||
| "Compress", | ||
| "CompressMax", | ||
| ], | ||
| }, | ||
| filename: { | ||
| propDefinition: [ | ||
| pdf4me, | ||
| "filename", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const filename = utils.checkForExtension(this.filename, "pdf"); | ||
| const filePath = utils.normalizeFilePath(this.filePath); | ||
| const fileContent = fs.readFileSync(filePath, { | ||
| encoding: "base64", | ||
| }); | ||
|
|
||
| const response = await this.pdf4me.compressPdf({ | ||
| $, | ||
| data: { | ||
| docContent: fileContent, | ||
| docName: filename, | ||
| optimizeProfile: this.optimizeProfile, | ||
| }, | ||
| responseType: "arraybuffer", | ||
| }); | ||
|
|
||
| const filedata = utils.downloadToTmp(response, filename); | ||
|
|
||
| $.export("$summary", "Successfully compressed PDF file"); | ||
| return filedata; | ||
| }, | ||
| }; | ||
47 changes: 47 additions & 0 deletions
47
components/pdf4me/actions/convert-to-pdf/convert-to-pdf.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import pdf4me from "../../pdf4me.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
| import fs from "fs"; | ||
|
|
||
| export default { | ||
| key: "pdf4me-convert-to-pdf", | ||
| name: "Convert to PDF", | ||
| description: "Convert a document (e.g., DOCX, XLSX, PPTX) to PDF. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/convert-to-pdf/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdf4me, | ||
| filePath: { | ||
| propDefinition: [ | ||
| pdf4me, | ||
| "filePath", | ||
| ], | ||
| description: "The path to a DOCX, XLSX, or PPTX file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
| }, | ||
| filename: { | ||
| propDefinition: [ | ||
| pdf4me, | ||
| "filename", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const filePath = utils.normalizeFilePath(this.filePath); | ||
| const fileContent = fs.readFileSync(filePath, { | ||
| encoding: "base64", | ||
| }); | ||
|
|
||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const response = await this.pdf4me.convertToPdf({ | ||
| $, | ||
| data: { | ||
| docContent: fileContent, | ||
| docName: this.filename, | ||
| }, | ||
| responseType: "arraybuffer", | ||
| }); | ||
|
|
||
| const filedata = utils.downloadToTmp(response, this.filename); | ||
|
|
||
| $.export("$summary", "Successfully converted file to PDF"); | ||
| return filedata; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import pdf4me from "../../pdf4me.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
| import fs from "fs"; | ||
|
|
||
| export default { | ||
| key: "pdf4me-merge-pdfs", | ||
| name: "Merge PDF Files", | ||
| description: "Merge multiple PDF files into a single PDF. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/merge/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdf4me, | ||
| filePaths: { | ||
| type: "string[]", | ||
| label: "File Paths", | ||
| description: "An array of paths to a PDF files in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
| }, | ||
| filename: { | ||
| propDefinition: [ | ||
| pdf4me, | ||
| "filename", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const filename = utils.checkForExtension(this.filename, "pdf"); | ||
| const filePaths = this.filePaths.map((path) => utils.normalizeFilePath(path)); | ||
| const fileContents = filePaths.map((path) => fs.readFileSync(path, { | ||
| encoding: "base64", | ||
| })); | ||
|
|
||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const response = await this.pdf4me.mergePdfs({ | ||
| $, | ||
| data: { | ||
| docContent: fileContents, | ||
| docName: filename, | ||
| }, | ||
| responseType: "arraybuffer", | ||
| }); | ||
|
|
||
| const filedata = utils.downloadToTmp(response, filename); | ||
|
|
||
| $.export("$summary", "Successfully merged PDF files"); | ||
| return filedata; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import fs from "fs"; | ||
|
|
||
| function normalizeFilePath(path) { | ||
| return path.includes("tmp/") | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? path | ||
| : `/tmp/${path}`; | ||
| } | ||
|
|
||
| function checkForExtension(filename, ext = "pdf") { | ||
| return filename.includes(`.${ext}`) | ||
| ? filename | ||
| : `${filename}.${ext}`; | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function downloadToTmp(response, filename) { | ||
| const rawcontent = response.toString("base64"); | ||
| const buffer = Buffer.from(rawcontent, "base64"); | ||
| const filePath = normalizeFilePath(filename); | ||
| fs.writeFileSync(filePath, buffer); | ||
|
|
||
| return [ | ||
| filename, | ||
| filePath, | ||
| ]; | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default { | ||
| normalizeFilePath, | ||
| checkForExtension, | ||
| downloadToTmp, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/pdf4me", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream PDF4me Components", | ||
| "main": "pdf4me.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,57 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "pdf4me", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| filePath: { | ||
| type: "string", | ||
| label: "File Path", | ||
| description: "The path to a PDF file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
| }, | ||
| filename: { | ||
| type: "string", | ||
| label: "File Name", | ||
| description: "The filename to save the resulting PDF in the /tmp directory", | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.pdf4me.com/api/v2"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, | ||
| path = "/", | ||
| ...otherOpts | ||
| }) { | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| authorization: this.$auth.api_key, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| convertToPdf(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/ConvertToPdf", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| mergePdfs(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/Merge", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| compressPdf(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/Optimize", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.