Hello,
I have multiple pdf files like lec1.pdf, lec2.pdf etc.
I want to read it’s contents one by one and store it.
I passed intial path to workflows using parameter
Like
Filepath:. C:\data\notes\lec
As its passed as parameter we can access it using Filepath
I want to make this Filepath as
C:\data\notes\lec0.pdf
C:\data\notes\lec1.pdf
C:\data\notes\lec2.pdf
I used the loop and modified javascript and created a variable pathfile in modified javascript which store path like
C:\data\notes\lec0 and so on.
But problem is we can’t provide this variable into
Pdf text step.
Only variable passed to workflow are accessible when we press the CTRL+ SPACE. Fields name doesn’t appear.
You can use the ‘Get File Names’ plugin to read all the pdf files from a defined directory (configurable in the plugin), and this plugin would return you with all the details (filename, type,path,size,extension,uri etc) about the files in multiple variables which are directly accessible in the next step of workflow. You can use the ‘filename’ variable to access the complete file path with its name and extension.
To process these files one by one, create a separate workflow (Workflow_2) which would read the contents of one pdf file. Then connect the the ‘Get File Names’ to a ‘Workflow Executor’ (to execute the Workflow_2) in Workflow_1. This way, Workflow_2 will execute every pdf one by one. Please refer below sample screenshots.
Get File Names configuration to read only pdf files from a directory.
I tried But unable to write and append into single file. After reading and writing the first pdf(lec0.pdf) it provides error In WorkFlow Executor.
Please Check Snapshot and WF.in the attchement.
If I read only then its working Fine (shows correct path in Alert OF Modifed javascript step)
but when I want to write in file it WF executor gives ErrorWF_GetFilesName.psw (16.3 KB) WF_ReadMutiPDF.psw (20.8 KB)
Here’s a guide on how to read multiple PDF files and store their contents, addressing the issue with accessing JavaScript variables in the PDF text step:
1. Ensure Correct Variable Scope:
If JavaScript variable is not accessible: Double-check that it’s declared and assigned a value correctly within a scope accessible to the PDF text step.
Consider using a workflow variable: If sharing across multiple steps is necessary, store the path in a workflow variable instead of a JavaScript variable.
2. Utilize a Loop for File Iteration:
Implement a suitable loop: Use a “For each” loop, “While” loop, or a custom JavaScript loop to iterate through the PDF files.
Set path within loop: Inside the loop, construct the complete file path (base path + file number + “.pdf”) and assign it to either a workflow variable or a JavaScript variable accessible to the PDF text step.
3. Dynamically Provide File Path to PDF Text Step:
Within loop: Use the dynamically generated file path to provide the input to the PDF text step.
Workflow variable: If using a workflow variable, directly reference it in the PDF text step’s settings.
JavaScript variable: If using a JavaScript variable, employ a method supported by your workflow system to pass its value to the step (e.g., using an expression language or a dedicated mechanism for interaction between JavaScript and workflow steps).
4. Store Extracted Text:
Choose a storage method: Decide where to store the extracted text, such as:
Workflow variables
External files
Databases
Apply appropriate actions: Implement the necessary actions within the loop to store the text accordingly.
Additional Considerations:
Variable naming: Adhere to your workflow system’s naming conventions to avoid conflicts.
File paths: Ensure correct path formatting for your operating system.
JavaScript errors: Review any JavaScript code for errors that might prevent variable visibility.
Workflow documentation: Consult your workflow system’s documentation for specific guidance on variable usage and step interaction.
If you can provide more details about your specific workflow system and steps, I can offer more tailored advice.