-
Notifications
You must be signed in to change notification settings - Fork 15
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
utils.converters.PDF2Text (new) convert PDF to text #347
Open
DavidDurman
wants to merge
2
commits into
clientIO:dev
Choose a base branch
from
DavidDurman:pdf2text
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,21 @@ | ||
'use strict'; | ||
const converters = require('../converters'); | ||
const path = require('path'); | ||
const { Readable } = require('stream'); | ||
|
||
module.exports = { | ||
|
||
async receive(context) { | ||
|
||
const { fileId, outputTextContent } = context.messages.in.content; | ||
const fileInfo = await context.getFileInfo(fileId); | ||
const newFileName = path.parse(fileInfo.filename).name + '.txt'; | ||
const textContent = await converters.pdfToText(context, fileId); | ||
const savedFile = await context.saveFileStream(newFileName, Readable.from(textContent)); | ||
const out = { ...savedFile }; | ||
if (outputTextContent) { | ||
out.textContent = (await context.loadFile(savedFile.fileId)).toString('utf8'); | ||
} | ||
return context.sendJson(out, 'out'); | ||
} | ||
}; |
This file contains 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,49 @@ | ||
{ | ||
"name": "appmixer.utils.converters.PDF2Text", | ||
"author": "Appmixer <info@appmixer.com>", | ||
"description": "Extract text from a PDF file.", | ||
"private": false, | ||
"inPorts": [ | ||
{ | ||
"name": "in", | ||
"schema": { | ||
"properties": { | ||
"fileId": { "type": "string" }, | ||
"outputTextContent": { "type": "boolean" } | ||
}, | ||
"required": [ "fileId" ] | ||
}, | ||
"inspector": { | ||
"inputs": { | ||
"fileId": { | ||
"type": "filepicker", | ||
"label": "File ID", | ||
"index": 1, | ||
"tooltip": "The ID of the PDF file to convert." | ||
}, | ||
"outputTextContent": { | ||
"type": "toggle", | ||
"defaultValue": false, | ||
"label": "Output Text Content", | ||
"index": 2, | ||
"tooltip": "By default, the actual PDF text content is not returned, allowing very large files to be processed without working with the entire file data directly. For convenience, if your PDF files are smaller than 10 MB and you want to work with the pdf text directly, you can set this option. (Note that you can use the 'Files.Load File' utility to read any file data when needed)." | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"outPorts": [ | ||
{ | ||
"name": "out", | ||
"options": [ | ||
{ "label": "File ID", "value": "fileId" }, | ||
{ "label": "File Name", "value": "fileName" }, | ||
{ "label": "File Size (Bytes)", "value": "length" }, | ||
{ "label": "File Upload Date", "value": "uploadDate" }, | ||
{ "label": "File MD5", "value": "md5" }, | ||
{ "label": "Text Content", "value": "textContent" } | ||
] | ||
} | ||
], | ||
"icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAQAAAD2e2DtAAAHyklEQVR42u3dX2hWdRzH8c+GCDq1YVPbRRFqcyiFlnqVbDlZkloMmrWyqGtJGDHyQhdRwZZU5DRcdZHKpJQCbyzTsAJJU0fqLsz/0Y1TIZ2VTN0Ww4yp27Pz73me8/v+3p/vnTd7zvm+POc83/M7z5EIIYQQQgghhBBCCCEkmYxRuSpUa6yWaaXWaI1Watl//1KpUpo9MA9ouXbpivo8qg41qJjWF+oVHfKq8QOrU3V+t/8pHfG2+beq2dfml2in982/We/62P6HdZrW/1/1vrX/Gc8u+IarHj3nU/vnqZum31HXVO1L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wVuaLq8yAyHnrLvUUUCWxzsKLBW3uRe7XAEQGNCWzw8gQP5enQ7X1moX1Pf/uYEt7dAazK2v0TepVAv62BqR8Sdqkt8i+vUOei5v8W3//0Dc7+Wa5cup6r5HWpQcVa2tlgN6hjwl86rVTNEJI3WNFWoNu9VqdKsb2upKlWrRSq3/72fEEIIIYQQQgghhBDiSv4FeV1otCGtp+0AAAAASUVORK5CYII=" | ||
} |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on this code, it seems that the entire PDF file is not loaded into memory all at once; instead, it is processed page by page. Is that correct?
However, the entire output text is stored in memory. I believe we should consider sending the output text chunks into a stream, or we should introduce a strict limit on the input size of the PDF file. With larger PDF files containing a lot of text, there's a possibility of reaching the memory limit on the instance.