autoprint.js 865 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * jsPDF Autoprint Plugin
  3. *
  4. * Licensed under the MIT License.
  5. * http://opensource.org/licenses/mit-license
  6. */
  7. /**
  8. * Makes the PDF automatically print. This works in Chrome, Firefox, Acrobat
  9. * Reader.
  10. *
  11. * @returns {jsPDF}
  12. * @name autoPrint
  13. * @example
  14. * var doc = new jsPDF()
  15. * doc.text(10, 10, 'This is a test')
  16. * doc.autoPrint()
  17. * doc.save('autoprint.pdf')
  18. */
  19. (function (jsPDFAPI) {
  20. 'use strict';
  21. jsPDFAPI.autoPrint = function () {
  22. 'use strict'
  23. var refAutoPrintTag;
  24. this.internal.events.subscribe('postPutResources', function () {
  25. refAutoPrintTag = this.internal.newObject()
  26. this.internal.write("<< /S/Named /Type/Action /N/Print >>", "endobj");
  27. });
  28. this.internal.events.subscribe("putCatalog", function () {
  29. this.internal.write("/OpenAction " + refAutoPrintTag + " 0" + " R");
  30. });
  31. return this;
  32. };
  33. })(jsPDF.API);