read text from *.txt-files and save it to variables

Post Reply
bkromer
Newbie
Posts: 3
Joined: Thu Jul 11, 2019 10:41 am

read text from *.txt-files and save it to variables

Post by bkromer » Thu Jul 11, 2019 11:02 am

Hello there,

I convert the incoming pdf with callasToolbox to *.txt-files. In the next step, I want to extract the text from these files and save it to a variable, so that I could have a regex search ran on this and find specific Numbers that fit my patterns.
Image

My code so far:
const fs = require('fs')
fs.readFile('Input.txt', 'utf-8', (err, data) => {
if (err) throw err;
console.log(data);

My Question is in wich variable or such do I need to save the data in, to use it afterwards?

Thanks in Advance,
Ben

jan_suhr
Advanced member
Posts: 238
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: read text from *.txt-files and save it to variables

Post by jan_suhr » Thu Jul 11, 2019 11:13 am

There is an app that fix that for you.

https://www.enfocus.com/en/appstore/pro ... t-from-pdf
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

bkromer
Newbie
Posts: 3
Joined: Thu Jul 11, 2019 10:41 am

Re: read text from *.txt-files and save it to variables

Post by bkromer » Thu Jul 11, 2019 2:08 pm

Okay, that's Plan B 8-) but first I wanna try doing it on my own. Does someone have any hints for me, Code snippets etc on how to do this?

Padawan
Member
Posts: 194
Joined: Mon Jun 12, 2017 8:48 pm

Re: read text from *.txt-files and save it to variables

Post by Padawan » Thu Jul 11, 2019 5:19 pm

Your sample looks very node.js-ish. Switch javascript looks a bit different.

I always start from the samples in the documentation:
https://www.enfocus.com/manuals/Develop ... class.html

The Static Text I/O functions are the easiest

bkromer
Newbie
Posts: 3
Joined: Thu Jul 11, 2019 10:41 am

Re: read text from *.txt-files and save it to variables

Post by bkromer » Thu Jul 18, 2019 10:30 am

Thanks for the link.
Buuuut I still dont get it.

In my flow i want to rename my PDF-File with specific Metadata Fields. I got the Email.Body(Text) Object and i want to pick a specific part of this string with regex and rename the pdf file like so.
The thing i dont understand is how to pass this string.
Imagehttps://imgur.com/S0RP0hC

I tried Imagehttps://imgur.com/KnsVqXI

Thanks in Advance
lg Ben

Padawan
Member
Posts: 194
Joined: Mon Jun 12, 2017 8:48 pm

Re: read text from *.txt-files and save it to variables

Post by Padawan » Thu Jul 18, 2019 8:19 pm

Ok, some things are off:
You are using a script expression, so you don't need the job arrived entry point. You can just write your code, store the output in a variable and in the last line type the variable name with a semicolon.


Job.getvariableasstring() expects a switch variable as string, so that's not going to work

It's better to just end with
re[1];


Regular expressions in Switch can behave differently then regular expressions in node.js, it is useful to check the enfocus documentation on what they support. For example, something only the g and i flags are supported, m is not
https://www.enfocus.com/manuals/Develop ... egexp.html
.

There is not a true debugger with breakpoints, but you can use job.log() and s.log() like you would use console.log() in other environments. Difference is that logs don't go to console, but to switch messages. There are different types of logs, which makes the syntax differently
job.log(-1, "this is a debug message") ;
job.log(1, "this is a normal message") ;
job.log(3, "this is an error message") ;

Post Reply