Skip to content

Commit 620a92d

Browse files
committed
Merge pull request parallax#104 from mfo/feature/auto_print
Add autoprint plugin
2 parents c740a29 + 64f87dc commit 620a92d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

jspdf.plugin.autoprint.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function(jsPDFAPI) {
2+
'use strict'
3+
4+
jsPDFAPI.autoPrint = function() {
5+
'use strict'
6+
// `this` is _jsPDF object returned when jsPDF is inited (new jsPDF())
7+
// `this.internal` is a collection of useful, specific-to-raw-PDF-stream functions.
8+
// for example, `this.internal.write` function allowing you to write directly to PDF stream.
9+
// `this.line`, `this.text` etc are available directly.
10+
// so if your plugin just wraps complex series of this.line or this.text or other public API calls,
11+
// you don't need to look into `this.internal`
12+
// See _jsPDF object in jspdf.js for complete list of what's available to you.
13+
var refAutoPrintTag;
14+
15+
this.internal.events.subscribe('postPutResources', function(){
16+
refAutoPrintTag = this.internal.newObject()
17+
this.internal.write("<< /S/Named /Type/Action /N/Print >>", "endobj");
18+
})
19+
20+
this.internal.events.subscribe("putCatalog", function(){
21+
this.internal.write("/OpenAction " + refAutoPrintTag + " 0" + " R");
22+
});
23+
24+
// it is good practice to return ref to jsPDF instance to make
25+
// the calls chainable.
26+
return this;
27+
}
28+
29+
})(jsPDF.API)

0 commit comments

Comments
 (0)