1 person found this helpful
You can use the exportAsText method of the Document object.
ah. thanks! pretty simple:
One other question, using just this.exportAsText(); causes a dialog to pop up where I have to manually type in the TXT file name.
I just want to export a .txt file of the same name as the .pdf in the same folder... for example, if the pdf is named "HelloWorld.pdf", I want to end up with a .txt file named "HelloWorld.txt"
Can you show me what the parameters for exportAsText() method would look like to achieve this?
this.exportAsText(true, null, WhatGoesHere?);
This requires more advanced scripting knowledge. You will need to know how
to define file-paths in JS, and also how to make them dynamic. Otherwise
each file will just write over the previous one.
I'll try and read through the API Reference, but can't I just use a relative file path... something like this.exportAsText(true, null, "\..");
I don't know the correct syntax for filepaths in JS... does it get wrapped in double quotes?
Several methods take device-independent paths as arguments. See the PDF Reference, version 1.7, for details about the device-independent path format.
Where the hell is the PDF Reference, version 1.7???
Is there a this.filename property?
Well, this (sort of) works, it'll output a .txt file in the same folder as the .pdf with a name of "MyFile.pdf.txt"
this.exportAsText(true, null, this.documentFileName + '.txt');
So, when I get the time, I'll probably just uses a String method, such as splice() or substr(), on this.documentFileName to remove the ".pdf" extension and THEN add ".txt" to that.
I'll post the code here if it works out.
For all interested:
/* Export Form Data to TXT */
var FileName_str = this.documentFileName.slice(0, this.documentFileName.indexOf("."));this.exportAsText(true, null, FileName_str + '.txt');
Even though it has nothing to do with developing in LiveCycle ES, it does have to do with LiveCycle if you are testing via its Preview option.
Previewing did not work and I expect it is because LiveCycle must be creating a temporary version of your file and not actually executing the file you are editing.
If I load my PDF in Acrobat Pro, it works!
Too bad they wouldn't document stuff like this!