You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
It didn't take too long to figure this out, but it would be helpful to have an example of how to use the execute command. For example, pointing out that the args is an array of strings that should be ordered just like the pdftk CLI.
Example:
PDFTK.execute(["/path/to/in.pdf","commandToExecute"],function(err,stdout,stderr){// stdout is a default output unless output file path is specified in args array// stdout is a Node Buffer (https://nodejs.org/api/buffer.html)console.log(stdout.toString('utf8'));}
BTW the command I'll primarily be using is dump_data_fields which I will use to parse the field values of a PDF file. I'm parsing the values using the SO answers here: http://stackoverflow.com/questions/30362686/parsing-a-colon-separated-string-into-json-in-node-javascript. I'm storing PDFs using Collection FS using the filesystem storage option (cfs:filesystem). So far it works, so I'm super appreciative of this package. Thanks!!!
The text was updated successfully, but these errors were encountered:
I know this is old, but your comment was very helpful. I have been able to use dump_data_fields on a PDF and parse the results (using the SO link you provided). Problem is, I have the parsed results on the server, and I'd like to pass those back to the client, and it won't work synchronously. Meaning, I can't get the values back to the client because the server is still processing them when the function returns the callback. I have tried, and failed, to use futures. This is what I have so far:
`
var future = new Future();
PDFTK.execute([file,"dump_data_fields"],function(err,stdout,stderr) {
// stdout is a default output unless output file path is specified in args array
// stdout is a Node Buffer (https://nodejs.org/api/buffer.html)
console.log("ERR", err);
console.log("STDOUT", stdout);
console.log("STDERR", stderr);
var input = stdout.toString('utf8').trim();
// Parse the data into an array
var fields = [];
var field_strings = input.split(/[\r\n]*---[\r\n]*/);
for (var i = 0; i < field_strings.length; i++) {
if (field_strings[i] == '') { // Skip blank field at beginning
continue;
}
var obj = {};
var props_strings = field_strings[i].split('\n');
for (var j = 0; j < props_strings.length; j++) {
var keyvalue = props_strings[j].split(':');
obj[keyvalue[0]] = keyvalue[1].trim();
}
fields.push(obj);
}
console.log(fields);
future.return(fields);
});
Hi,
It didn't take too long to figure this out, but it would be helpful to have an example of how to use the
execute
command. For example, pointing out that theargs
is an array of strings that should be ordered just like the pdftk CLI.Example:
BTW the command I'll primarily be using is
dump_data_fields
which I will use to parse the field values of a PDF file. I'm parsing the values using the SO answers here: http://stackoverflow.com/questions/30362686/parsing-a-colon-separated-string-into-json-in-node-javascript. I'm storing PDFs using Collection FS using the filesystem storage option (cfs:filesystem). So far it works, so I'm super appreciative of this package. Thanks!!!The text was updated successfully, but these errors were encountered: