Skip to content

Commit

Permalink
Merge pull request #41 from anperez78/master
Browse files Browse the repository at this point in the history
Adding path for temporary FDF files
  • Loading branch information
johntayl authored Oct 7, 2016
2 parents d0a9f01 + 7e45c63 commit 90797d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@
});
},

fillFormWithFlatten: function( sourceFile, destinationFile, fieldValues, shouldFlatten, callback ) {
fillFormWithOptions: function( sourceFile, destinationFile, fieldValues, shouldFlatten, tempFDFPath, callback ) {

//Generate the data from the field values.
var tempFDF = "data" + (new Date().getTime()) + ".fdf",
var tempFDFFile = "data" + (new Date().getTime()) + ".fdf",
tempFDF = (typeof tempFDFPath !== "undefined"? tempFDFPath + '/' + tempFDFFile: tempFDFFile),
formData = fdf.generator( fieldValues, tempFDF );

var args = [sourceFile, "fill_form", tempFDF, "output", destinationFile];
Expand All @@ -133,6 +134,10 @@
} );
},

fillFormWithFlatten: function( sourceFile, destinationFile, fieldValues, shouldFlatten, callback ) {
this.fillFormWithOptions( sourceFile, destinationFile, fieldValues, shouldFlatten, undefined, callback);
},

fillForm: function( sourceFile, destinationFile, fieldValues, callback) {
this.fillFormWithFlatten( sourceFile, destinationFile, fieldValues, true, callback);
}
Expand Down
12 changes: 11 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ describe('pdfFiller Tests', function(){
});
});

it('should create an completely filled PDF that is read-only and with an specific temporary folder for FDF files', function(done) {
this.timeout(15000);
pdfFiller.fillFormWithOptions( source2PDF, dest2PDF, _data, true, './', function(err) {
pdfFiller.generateFieldJson(dest2PDF, null, function(err, fdfData) {
fdfData.length.should.equal(0);
done();
});
});
});

it('should create an unflattened PDF with unfilled fields remaining', function(done) {
this.timeout(15000);
var source3PDF = source2PDF;
var dest3PDF = "test/test_complete3.pdf";
var _data2 = {
var _data2 = {
"first_name": "Jerry",
};
pdfFiller.fillFormWithFlatten( source3PDF, dest3PDF, _data2, false, function(err) {
Expand Down

0 comments on commit 90797d1

Please sign in to comment.