Hello
I found a method in the help
"getFilePath ( String DefName, String DefExt, String DefDir, String Title, int Options )",
it provides an array of selected files.
Also in the help I found the method
"getData ( )",
which produces an array of bytes (which is what I want).
Using a report, I am trying to output an array of bytes to a text file.
Script code:
function getImportFile() {
var selFile = Dialogs.getFilePath("",
"*.pdf!!Adobe Acrobat Files|*.pdf|Text Files|*.txt||",
"",
"Select file to be opened",
0)[0];
Dialogs.MsgBox("You selected: " + selFile.getName());
//the file's data is available via selFiles[i].getData() which returns the content as a byte[].
if (selFile != null) {
return selFile;
}
return null;
}
function main() {
var importFile = getImportFile();
if (importFile != null) {
var fileData = importFile.getData(); //the file's data is available via getData() which returns the content as a byte[].
oOutput = Context.createOutputObject();
oOutput.OutputTxt(fileData);
}
oOutput.WriteReport();
}
main();
When debugging this script, I check the contents of the "fileData" variable, the data is correct (see pic. "ScreenShotOfValues.jpg").
However, when outputting a text file, its content (see pic. "ScreenShotOfOutput.jpg") contains data that does not resemble the contents of a pdf file (see pic "ScreenShotOfPdfContent.jpg").
When using additional function:
function bin2string(array){
var result = "";
for(var i = 0; i < array.length; ++i){
result+= (String.fromCharCode(array[i]));
}
return result;
}
The content of the resulting text file is similar to the content of the pdf file that I opened in notepad, but after saving it as a PDF file, Adobe Reader cannot open that PDF file.
Tell me please how I can get the contents of a pdf file as an array of bytes.