From 38b469fce598b90bd558ee4792d457da75ed189e Mon Sep 17 00:00:00 2001 From: itwadesh Date: Fri, 6 Jan 2017 15:25:54 +0530 Subject: [PATCH] - --- .gitignore | 1 + index.js | 10 ++-- node_modules/pdffiller/LICENSE.md | 2 +- node_modules/pdffiller/index.js | 85 ++++++++++++++++------------- node_modules/pdffiller/package.json | 81 +-------------------------- 5 files changed, 56 insertions(+), 123 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ + diff --git a/index.js b/index.js index 8eb2a74..c2a710a 100644 --- a/index.js +++ b/index.js @@ -14,13 +14,13 @@ var data = { "nascar": "Off" }; // This does my job -pdfFiller.fillForm(sourcePDF, destinationPDF, data, function (err) { - if (err) throw err; - console.log("In callback (we're done)."); -}); +// pdfFiller.fillForm(sourcePDF, destinationPDF, data, function (err) { +// if (err) throw err; +// console.log("In callback (we're done)."); +// }); // I want this function -pdfFiller.addWatermark(sourcePDF, watermarkPDF, destinationPDF, data, function (err) { +pdfFiller.addWatermark(sourcePDF, destinationPDF, watermarkPDF, function (err) { if (err) throw err; console.log("In callback (we're done)."); }); diff --git a/node_modules/pdffiller/LICENSE.md b/node_modules/pdffiller/LICENSE.md index 2797dd1..50daed1 100644 --- a/node_modules/pdffiller/LICENSE.md +++ b/node_modules/pdffiller/LICENSE.md @@ -1,6 +1,6 @@ MIT License (MIT) -Copyright (c) 2014-2016 John Taylor +Copyright (c) 2017 Swadesh Behera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/node_modules/pdffiller/index.js b/node_modules/pdffiller/index.js index d61e1c8..e7e6ec5 100644 --- a/node_modules/pdffiller/index.js +++ b/node_modules/pdffiller/index.js @@ -6,7 +6,7 @@ * Description: This PDF filler module takes a data set and creates a filled out * PDF file with the form fields populated. */ -(function(){ +(function () { var child_process = require('child_process'), execFile = require('child_process').execFile, fdf = require('utf8-fdf-generator'), @@ -15,12 +15,12 @@ var pdffiller = { - mapForm2PDF: function( formFields, convMap ){ + mapForm2PDF: function (formFields, convMap) { var tmpFDFData = this.convFieldJson2FDF(formFields); - tmpFDFData = _.mapKeys(tmpFDFData, function(value, key){ + tmpFDFData = _.mapKeys(tmpFDFData, function (value, key) { try { convMap[key]; - } catch(err){ + } catch (err) { return key; } @@ -30,14 +30,14 @@ return tmpFDFData; }, - convFieldJson2FDF: function(fieldJson){ + convFieldJson2FDF: function (fieldJson) { var _keys = _.pluck(fieldJson, 'title'), _values = _.pluck(fieldJson, 'fieldValue'); - _values = _.map(_values, function(val){ - if(val === true){ + _values = _.map(_values, function (val) { + if (val === true) { return 'Yes'; - }else if(val === false) { + } else if (val === false) { return 'Off'; } return val; @@ -48,36 +48,36 @@ return jsonObj; }, - generateFieldJson: function( sourceFile, nameRegex, callback){ + generateFieldJson: function (sourceFile, nameRegex, callback) { var regName = /FieldName: ([^\n]*)/, regType = /FieldType: ([A-Za-z\t .]+)/, regFlags = /FieldFlags: ([0-9\t .]+)/, fieldArray = [], currField = {}; - if(nameRegex !== null && (typeof nameRegex) == 'object' ) regName = nameRegex; + if (nameRegex !== null && (typeof nameRegex) == 'object') regName = nameRegex; - execFile( "pdftk", [sourceFile, "dump_data_fields_utf8"], function (error, stdout, stderr) { + execFile("pdftk", [sourceFile, "dump_data_fields_utf8"], function (error, stdout, stderr) { if (error) { console.log('exec error: ' + error); return callback(error, null); } fields = stdout.toString().split("---").slice(1); - fields.forEach(function(field){ + fields.forEach(function (field) { currField = {}; currField['title'] = field.match(regName)[1].trim() || ''; - if(field.match(regType)){ + if (field.match(regType)) { currField['fieldType'] = field.match(regType)[1].trim() || ''; - }else { + } else { currField['fieldType'] = ''; } - if(field.match(regFlags)){ - currField['fieldFlags'] = field.match(regFlags)[1].trim()|| ''; - }else{ + if (field.match(regFlags)) { + currField['fieldFlags'] = field.match(regFlags)[1].trim() || ''; + } else { currField['fieldFlags'] = ''; } @@ -90,14 +90,14 @@ }); }, - generateFDFTemplate: function( sourceFile, nameRegex, callback ){ - this.generateFieldJson(sourceFile, nameRegex, function(err, _form_fields){ + generateFDFTemplate: function (sourceFile, nameRegex, callback) { + this.generateFieldJson(sourceFile, nameRegex, function (err, _form_fields) { if (err) { - console.log('exec error: ' + err); - return callback(err, null); + console.log('exec error: ' + err); + return callback(err, null); } - var _keys = _.pluck(_form_fields, 'title'), - _values = _.pluck(_form_fields, 'fieldValue'), + var _keys = _.pluck(_form_fields, 'title'), + _values = _.pluck(_form_fields, 'fieldValue'), jsonObj = _.zipObject(_keys, _values); return callback(null, jsonObj); @@ -105,45 +105,54 @@ }); }, - fillFormWithOptions: function( sourceFile, destinationFile, fieldValues, shouldFlatten, tempFDFPath, callback ) { + fillFormWithOptions: function (sourceFile, destinationFile, fieldValues, shouldFlatten, tempFDFPath, callback) { //Generate the data from the field values. - var tempFDFFile = "data" + (new Date().getTime()) + ".fdf", - tempFDF = (typeof tempFDFPath !== "undefined"? tempFDFPath + '/' + tempFDFFile: tempFDFFile), - formData = fdf.generator( fieldValues, tempFDF ); + 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]; if (shouldFlatten) { args.push("flatten"); } - execFile( "pdftk", args, function (error, stdout, stderr) { + execFile("pdftk", args, function (error, stdout, stderr) { - if ( error ) { + if (error) { console.log('exec error: ' + error); return callback(error); } //Delete the temporary fdf file. - fs.unlink( tempFDF, function( err ) { + fs.unlink(tempFDF, function (err) { - if ( err ) { + if (err) { return callback(err); } // console.log( 'Sucessfully deleted temp file ' + tempFDF ); return callback(); }); - } ); + }); }, - fillFormWithFlatten: function( sourceFile, destinationFile, fieldValues, shouldFlatten, callback ) { - this.fillFormWithOptions( sourceFile, destinationFile, fieldValues, shouldFlatten, undefined, callback); + 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); + fillForm: function (sourceFile, destinationFile, fieldValues, callback) { + this.fillFormWithFlatten(sourceFile, destinationFile, fieldValues, true, callback); + }, + addWatermark: function (sourceFile, destinationFile, watermarkFile, callback) { + // pdftk multistamp output + var args = [sourceFile, "multistamp", watermarkFile, "output", destinationFile]; + execFile("pdftk", args, function (error, stdout, stderr) { + if (error) { + console.log('exec error: ' + error); + return callback(error); + } + }); } - }; module.exports = pdffiller; -}()) +} ()) diff --git a/node_modules/pdffiller/package.json b/node_modules/pdffiller/package.json index fdcd21d..b076793 100644 --- a/node_modules/pdffiller/package.json +++ b/node_modules/pdffiller/package.json @@ -1,54 +1,4 @@ { - "_args": [ - [ - { - "raw": "pdffiller", - "scope": null, - "escapedName": "pdffiller", - "name": "pdffiller", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "D:\\xxx" - ] - ], - "_from": "pdffiller@latest", - "_id": "pdffiller@0.0.8", - "_inCache": true, - "_location": "/pdffiller", - "_nodeVersion": "4.6.0", - "_npmOperationalInternal": { - "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/pdffiller-0.0.8.tgz_1475853334131_0.4887884948402643" - }, - "_npmUser": { - "name": "johntayl", - "email": "johntayl89@gmail.com" - }, - "_npmVersion": "2.15.9", - "_phantomChildren": {}, - "_requested": { - "raw": "pdffiller", - "scope": null, - "escapedName": "pdffiller", - "name": "pdffiller", - "rawSpec": "", - "spec": "latest", - "type": "tag" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/pdffiller/-/pdffiller-0.0.8.tgz", - "_shasum": "b0bf4640150c01fccb4993f8b9967de39597eb7a", - "_shrinkwrap": null, - "_spec": "pdffiller", - "_where": "D:\\xxx", - "author": { - "name": "John Taylor and David Baldwynn" - }, "dependencies": { "lodash": "~3.8.0", "utf8-fdf-generator": "0.0.3" @@ -58,12 +8,6 @@ "mocha": "~2.4.5", "should": "~6.0.1" }, - "directories": {}, - "dist": { - "shasum": "b0bf4640150c01fccb4993f8b9967de39597eb7a", - "tarball": "https://registry.npmjs.org/pdffiller/-/pdffiller-0.0.8.tgz" - }, - "gitHead": "dc344fd81d90d0434dcc253d9ee14e4328b680dd", "keywords": [ "nodejs", "pdftk", @@ -73,26 +17,5 @@ ], "license": "MIT", "main": "index.js", - "maintainers": [ - { - "name": "johntayl", - "email": "johntayl89@gmail.com" - }, - { - "name": "soitgoes", - "email": "martin.murphy@whiteboard-it.com" - }, - { - "name": "whitef0x0", - "email": "polydaic@gmail.com" - } - ], - "name": "pdffiller", - "optionalDependencies": {}, - "private": false, - "readme": "ERROR: No README data found!", - "scripts": { - "test": "mocha test/test.js" - }, - "version": "0.0.8" -} + "name": "pdffiller" +} \ No newline at end of file