Comparing version 0.6.1 to 0.6.2
@@ -21,3 +21,5 @@ 'use strict'; | ||
.alias('s', 'silent') | ||
.describe('s', '(optional) when specified, will only log errors, otherwise verbose.\n'); | ||
.describe('s', '(optional) when specified, will only log errors, otherwise verbose.\n') | ||
.alias('t', 'fieldTypes') | ||
.describe('t', '(optional) when specified, will generate .fields.json that includes fields ids and types.\n'); | ||
@@ -37,2 +39,17 @@ var argv = optimist.argv; | ||
var _generateFieldsTypesFile = function(data, callback) { | ||
var pJSON = require("./pdffield").getAllFieldsTypes(data); | ||
var fieldsTypesPath = this.outputPath.replace(".json", ".fields.json"); | ||
var fieldTypesFile = this.outputFile.replace(".json", ".fields.json"); | ||
fs.writeFile(fieldsTypesPath, JSON.stringify(pJSON), function(err) { | ||
if (err) { | ||
nodeUtil.p2jwarn(this.inputFile + " => " + fieldTypesFile + " Exception: " + err); | ||
} else { | ||
nodeUtil.p2jinfo(this.inputFile + " => " + fieldTypesFile + " [" + this.outputDir + "] OK"); | ||
} | ||
_continue.call(this, callback, err); | ||
}.bind(this)); | ||
}; | ||
var _writeOneJSON = function(data, callback) { | ||
@@ -45,7 +62,14 @@ var pJSON = JSON.stringify({"formImage":data}); | ||
this.curProcessor.failedCount++; | ||
_continue.call(this, callback, err); | ||
} else { | ||
nodeUtil.p2jinfo(this.inputFile + " => " + this.outputFile + " [" + this.outputDir + "] OK"); | ||
this.curProcessor.successCount++; | ||
if (_.has(argv, 't')) {//needs to generate fields.json file | ||
_generateFieldsTypesFile.call(this, data, callback); | ||
} | ||
else { | ||
_continue.call(this, callback); | ||
} | ||
} | ||
_continue.call(this, callback, err); | ||
}.bind(this)); | ||
@@ -52,0 +76,0 @@ }; |
@@ -250,2 +250,34 @@ var nodeUtil = require("util"), | ||
//static public method to generate fieldsType object based on parser result | ||
cls.getAllFieldsTypes = function(data) { | ||
function isFieldReadOnly(field) { | ||
return (field.AM & kFBANotOverridable) ? true : false; | ||
} | ||
function getFieldBase(field) { | ||
return {id: field.id.Id, type: field.T.Name, calc: isFieldReadOnly(field), value: field.V || ""}; | ||
} | ||
var retVal = []; | ||
_.each(data.Pages, function(page) { | ||
_.each(page.Boxsets, function(boxsets) { | ||
if (boxsets.boxes.length > 1) { //radio button | ||
_.each(boxsets.boxes, function(box) { | ||
retVal.push({id: boxsets.id.Id, type: "radio", calc: isFieldReadOnly(box), value: box.id.Id}); | ||
}); | ||
} | ||
else { //checkbox | ||
retVal.push(getFieldBase(boxsets.boxes[0])); | ||
} | ||
}); | ||
_.each(page.Fields, function(field){ | ||
retVal.push(getFieldBase(field)); | ||
}); | ||
}); | ||
return retVal; | ||
}; | ||
return cls; | ||
@@ -252,0 +284,0 @@ })(); |
{ | ||
"name": "pdf2json", | ||
"_id": "pdf2json@0.6.1", | ||
"version": "0.6.1", | ||
"_id": "pdf2json@0.6.2", | ||
"version": "0.6.2", | ||
"description": "A PDF file parser that converts PDF binaries to text based JSON, powered by porting a fork of PDF.JS to Node.js", | ||
@@ -17,3 +17,3 @@ "keywords": [ | ||
"PDF canvas", | ||
"PDF.JS fork" | ||
"pdf.js fork" | ||
], | ||
@@ -20,0 +20,0 @@ "author": { |
@@ -619,2 +619,19 @@ # pdf2json | ||
v0.6.2 added "-t" command line switch to generate fields json file in addition to parsed json. The fields json file will contain one Array which contains fieldInfo object for each field, and each fieldInfo object will have 4 fields: | ||
* id: field ID | ||
* type: string name of field type, like radio, alpha, etc | ||
* calc: true if read only, otherwise false | ||
* value: initial value of the field | ||
Example of fields.json content: | ||
[ | ||
{"id":"ADDRCH","type":"alpha","calc":false,"value":"user input data"}, | ||
{"id":"FSRB","type":"radio","calc":false,"value":"Single"}, | ||
{"id":"APPROVED","type":"alpha","calc":true,"value":"Approved Form"} | ||
... | ||
] | ||
The fields.json output can be used to validate fields IDs with other data source, automation data and/or to extract data value from user submitted PDFs. | ||
## Run in a RESTful Web Service | ||
@@ -621,0 +638,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4018812
50313
645