one offset is wrong
parent
5e8a8b60f3
commit
43ff762c2d
@ -0,0 +1,117 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
|
||||
/*
|
||||
PDFReference - represents a reference to another object in the PDF object heirarchy
|
||||
By Devon Govett
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var PDFObject, PDFReference, stream, zlib,
|
||||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
zlib = require('zlib');
|
||||
|
||||
stream = require('stream');
|
||||
|
||||
PDFReference = (function(superClass) {
|
||||
extend(PDFReference, superClass);
|
||||
|
||||
function PDFReference(document, id, data) {
|
||||
this.document = document;
|
||||
this.id = id;
|
||||
this.data = data != null ? data : {};
|
||||
this.finalize = bind(this.finalize, this);
|
||||
PDFReference.__super__.constructor.call(this, {
|
||||
decodeStrings: false
|
||||
});
|
||||
this.gen = 0;
|
||||
this.deflate = null;
|
||||
this.compress = false;
|
||||
this.uncompressedLength = 0;
|
||||
this.chunks = [];
|
||||
}
|
||||
|
||||
PDFReference.prototype.initDeflate = function() {
|
||||
this.data.Filter = 'FlateDecode';
|
||||
this.deflate = zlib.createDeflate();
|
||||
this.deflate.on('data', (function(_this) {
|
||||
return function(chunk) {
|
||||
console.log("got data event for ref " + _this.id + " from " + _this.toString());
|
||||
_this.chunks.push(chunk);
|
||||
return _this.data.Length += chunk.length;
|
||||
};
|
||||
})(this));
|
||||
return this.deflate.on('end', (function(_this) {
|
||||
return function() {
|
||||
console.log("got end event for ref " + _this.id + " from " + _this.toString());
|
||||
return _this.finalize();
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
PDFReference.prototype._write = function(chunk, encoding, callback) {
|
||||
var base;
|
||||
if (!Buffer.isBuffer(chunk)) {
|
||||
chunk = new Buffer(chunk + '\n', 'binary');
|
||||
}
|
||||
this.uncompressedLength += chunk.length;
|
||||
if ((base = this.data).Length == null) {
|
||||
base.Length = 0;
|
||||
}
|
||||
if (this.compress) {
|
||||
if (!this.deflate) {
|
||||
this.initDeflate();
|
||||
}
|
||||
console.log("chunk = " + chunk);
|
||||
this.deflate.write(chunk);
|
||||
console.log("wrote chunk");
|
||||
} else {
|
||||
this.chunks.push(chunk);
|
||||
this.data.Length += chunk.length;
|
||||
}
|
||||
return callback();
|
||||
};
|
||||
|
||||
PDFReference.prototype.end = function(chunk) {
|
||||
PDFReference.__super__.end.apply(this, arguments);
|
||||
if (this.deflate) {
|
||||
return this.deflate.end();
|
||||
} else {
|
||||
return this.finalize();
|
||||
}
|
||||
};
|
||||
|
||||
PDFReference.prototype.finalize = function() {
|
||||
var chunk, i, len, ref;
|
||||
this.offset = this.document._offset;
|
||||
this.document._write(this.id + " " + this.gen + " obj");
|
||||
this.document._write(PDFObject.convert(this.data));
|
||||
if (this.chunks.length) {
|
||||
this.document._write('stream');
|
||||
ref = this.chunks;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
chunk = ref[i];
|
||||
this.document._write(chunk);
|
||||
}
|
||||
this.chunks.length = 0;
|
||||
this.document._write('\nendstream');
|
||||
}
|
||||
this.document._write('endobj');
|
||||
return this.document._refEnd(this);
|
||||
};
|
||||
|
||||
PDFReference.prototype.toString = function() {
|
||||
return this.id + " " + this.gen + " R";
|
||||
};
|
||||
|
||||
return PDFReference;
|
||||
|
||||
})(stream.Writable);
|
||||
|
||||
module.exports = PDFReference;
|
||||
|
||||
PDFObject = require('./object');
|
||||
|
||||
}).call(this);
|
@ -0,0 +1,63 @@
|
||||
%PDF-1.3
|
||||
%ÿÿÿÿ
|
||||
5 0 obj
|
||||
<<
|
||||
/Parent 1 0 R
|
||||
/Resources 4 0 R
|
||||
/Contents 3 0 R
|
||||
/MediaBox [0 0 612 792]
|
||||
/Type /Page
|
||||
>>
|
||||
endobj
|
||||
4 0 obj
|
||||
<<
|
||||
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
|
||||
>>
|
||||
endobj
|
||||
3 0 obj
|
||||
<<
|
||||
/Length 18
|
||||
>>
|
||||
stream
|
||||
1 0 0 -1 0 792 cm
|
||||
|
||||
endstream
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
/Producer (PDFKit)
|
||||
/CreationDate (D:20170512220606Z)
|
||||
/Creator (PDFKit)
|
||||
>>
|
||||
endobj
|
||||
2 0 obj
|
||||
<<
|
||||
/Pages 1 0 R
|
||||
/Type /Catalog
|
||||
>>
|
||||
endobj
|
||||
1 0 obj
|
||||
<<
|
||||
/Kids [5 0 R]
|
||||
/Count 1
|
||||
/Type /Pages
|
||||
>>
|
||||
endobj
|
||||
xref
|
||||
0 7
|
||||
0000000000 65535 f
|
||||
0000000395 00000 n
|
||||
0000000346 00000 n
|
||||
0000057005 00000 n
|
||||
0000000186 00000 n
|
||||
0000000119 00000 n
|
||||
0000000254 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Info 6 0 R
|
||||
/Root 2 0 R
|
||||
/Size 7
|
||||
>>
|
||||
startxref
|
||||
452
|
||||
%%EOF
|
Loading…
Reference in New Issue