Comparing version 0.4.4 to 0.4.5
@@ -73,3 +73,3 @@ var nodeUtil = require("util"), | ||
// constructor | ||
var cls = function (pdfPage, id, scale) { | ||
var cls = function (pdfPage, id, scale, ptiParser) { | ||
nodeEvents.EventEmitter.call(this); | ||
@@ -86,2 +86,3 @@ // private | ||
this.pdfPage = pdfPage; | ||
this.ptiParser = ptiParser; | ||
@@ -136,3 +137,2 @@ this.scale = scale || 1.0; | ||
var self = this; | ||
function pageViewDrawCallback(error) { | ||
@@ -148,5 +148,11 @@ self.renderingState = RenderingStates.FINISHED; | ||
else { | ||
nodeUtil._logN.call(self, 'page ' + (self.id + 1) + ' is rendered successfully.'); | ||
if (self.ptiParser) { | ||
var extraFields = self.ptiParser.getFields(parseInt(self.id) + 1); | ||
_.each(extraFields, _addField, self); | ||
} | ||
_.extend(self, ctx.canvas); | ||
self.stats = self.pdfPage.stats; | ||
nodeUtil._logN.call(self, 'page ' + (self.id + 1) + ' is rendered successfully.'); | ||
callback(); | ||
@@ -219,5 +225,6 @@ } | ||
cls.prototype.parsePDFData = function(arrayBuffer) { | ||
var parameters = {password: '', data: arrayBuffer}; | ||
this.pdfDocument = null; | ||
this.formImage = null; | ||
var parameters = {password: '', data: arrayBuffer}; | ||
var self = this; | ||
@@ -239,2 +246,22 @@ PDFJS.getDocument(parameters).then( | ||
cls.prototype.tryLoadFieldInfoXML = function(pdfFilePath) { | ||
var fieldInfoXMLPath = pdfFilePath.replace(".pdf", "_fieldInfo.xml"); | ||
if (!fs.existsSync(fieldInfoXMLPath)) { | ||
return; | ||
} | ||
nodeUtil._logN.call(this, "About to load fieldInfo XML : " + fieldInfoXMLPath); | ||
var PTIXmlParser = require('./ptixmlinject'); | ||
this.ptiParser = new PTIXmlParser(); | ||
this.ptiParser.parseXml(fieldInfoXMLPath, _.bind(function(err) { | ||
if (err) { | ||
nodeUtil._logN.call(this, "fieldInfo XML Error: " + JSON.stringify(err)); | ||
this.ptiParser = null; | ||
} | ||
else { | ||
nodeUtil._logN.call(this, "fieldInfo XML loaded."); | ||
} | ||
}, this)); | ||
}; | ||
cls.prototype.load = function(pdfDocument, scale) { | ||
@@ -251,7 +278,7 @@ this.pdfDocument = pdfDocument; | ||
var self = this; | ||
var pagesPromise = PDFJS.Promise.all(pagePromises); | ||
nodeUtil._logN.call(self, "PDF loaded. pagesCount = " + pagesCount); | ||
nodeUtil._logN.call(this, "PDF loaded. pagesCount = " + pagesCount); | ||
var self = this; | ||
pagesPromise.then(function(promisedPages) { | ||
@@ -301,3 +328,4 @@ self.parsePage(promisedPages, 0, 1.5); | ||
var pdfPage = promisedPages[id]; | ||
var pageParser = new PDFPageParser(pdfPage, id, scale); | ||
var pageParser = new PDFPageParser(pdfPage, id, scale, this.ptiParser); | ||
pageParser.parsePage(function() { | ||
@@ -304,0 +332,0 @@ if (!self.pageWidth) //get PDF width |
@@ -43,3 +43,3 @@ var nodeUtil = require("util"), | ||
var yDelta = Math.abs(this.y2 - this.y1); | ||
var minDelta = 3 * this.lineWidth; | ||
var minDelta = this.lineWidth; | ||
@@ -46,0 +46,0 @@ var oneLine = {x:0, y:0, w:this.lineWidth, l:0}; |
{ | ||
"name": "pdf2json", | ||
"_id": "pdf2json@0.4.4", | ||
"version": "0.4.4", | ||
"_id": "pdf2json@0.4.5", | ||
"version": "0.4.5", | ||
"description": "A PDF file parser that converts PDF binaries to text based JSON, powered by porting a fork of PDF.JS to Node.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -115,12 +115,12 @@ var nodeUtil = require("util"), | ||
cls.prototype.loadPDF = function (pdfFilePath) { | ||
var self = this; | ||
self.pdfFilePath = pdfFilePath; | ||
nodeUtil._logN.call(this, " is about to load PDF file " + pdfFilePath); | ||
this.pdfFilePath = pdfFilePath; | ||
this.PDFJS.tryLoadFieldInfoXML(pdfFilePath); | ||
if (processBinaryCache.call(this)) | ||
return; | ||
// fs.readFile(pdfFilePath, _.bind(processPDFContent, self)); | ||
fq.push({path: pdfFilePath}, _.bind(processPDFContent, self)); | ||
// fs.readFile(pdfFilePath, _.bind(processPDFContent, this)); | ||
fq.push({path: pdfFilePath}, _.bind(processPDFContent, this)); | ||
}; | ||
@@ -127,0 +127,0 @@ |
@@ -94,2 +94,4 @@ Introduction | ||
v0.4.5 added support when fields attributes information is defined in external xml file. pdf2json will always try load field attributes xml file based on file name convention (pdffilename.pdf's field XML file must be named pdffilename_fieldInfo.xml in the same directory). If found, fields info will be injected. | ||
Dictionary Reference | ||
@@ -96,0 +98,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
3261175
124
35842
622
16