pdf3json
Version:
A PDF file parser that converts PDF binaries to text based JSON, powered by porting a fork of PDF.JS to Node.js
55 lines (42 loc) • 1.56 kB
JavaScript
var nodeUtil = require("util"),
_ = require("underscore"),
PDFUnit = require('./pdfunit.js');
var PDFFill = (function PFPLineClosure() {
'use strict';
// private static
var _nextId = 1;
var _name = 'PDFFill';
// constructor
var cls = function (x, y, width, height, color) {
// private
var _id = _nextId++;
// public (every instance will have their own copy of these methods, needs to be lightweight)
this.get_id = function() { return _id; };
this.get_name = function() { return _name + _id; };
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
};
// public static
cls.get_nextId = function () {
return _name + _nextId;
};
// public (every instance will share the same method, but has no access to private fields defined in constructor)
cls.prototype.processFill = function (targetData) {
var clrId = PDFUnit.findColorIndex(this.color);
var oneFill = {x:PDFUnit.toFormX(this.x),
y:PDFUnit.toFormY(this.y),
w:PDFUnit.toFormX(this.width),
h:PDFUnit.toFormY(this.height),
clr: clrId};
//MQZ.07/29/2013: when color is not in color dictionary, set the original color (oc)
if (clrId < 0) {
oneFill = _.extend({oc: this.color}, oneFill);
}
targetData.Fills.push(oneFill);
};
return cls;
})();
module.exports = PDFFill;