Closed Taakn closed 8 years ago
I'll look into it
@whitef0x0 thanks it's a separate issue but could you change the callback in fillForm so that it returns the standard function(error, return)
? That way we can use wrapAsync to use the synchronous version of the function ?
The function would look something like that (0 for failure, 1 for success):
fillForm: function(sourceFile, destinationFile, fieldValues, flatten, callback) {
//Generate the data from the field values.
var tempFDF = "data" + (new Date().getTime()) + ".fdf",
formData = fdf.generator(fieldValues, tempFDF);
child_process.exec("pdftk " + sourceFile + " fill_form " + tempFDF + " output " + destinationFile + (flatten ? " flatten" : ""), function(error, stdout, stderr) {
if (error) {
//console.log('exec error: ' + error);
return callback(error, 0);
}
//Delete the temporary fdf file.
fs.unlink(tempFDF, function(err) {
if (err) {
return callback(err, 0);
}
// console.log( 'Sucessfully deleted temp file ' + tempFDF );
return callback(undefined, 1);
});
});
}
};
And to use the synchronous version we can have:
pdfFiller.fillFormSync = Meteor.wrapAsync(pdfFiller.fillForm.bind(pdfFiller));
var ret = 0;
try {
ret = pdfFiller.fillFormSync(sourcePDF, destinationPDF, data);
} catch (e) {
}
if (ret == 0) {
// Failed do whatever
} else {
// success do whatever
}
I've put in a pull request #34 to make flatten parameter to pass into fillForm()
@johntayl this should be closed
Hello,
Once I fill out my pdf form with pdffiller (and everything works great), the form becomes a read-only pdf document. My understanding after testing is because you include by default the
flatten
option in your command"pdftk " + sourceFile + " fill_form " + tempFDF + " output " + destinationFile + " flatten"
.Would it be possible to include flatten as an optional input parameter in the
fillForm
function?Thanks so much