Blame view

public/assets/addons/fastflow/plugins/jsPDF-master/src/modules/autoprint.js 1.71 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  /** @license
   * jsPDF Autoprint Plugin
   *
   * Licensed under the MIT License.
   * http://opensource.org/licenses/mit-license
   */
  
  import { jsPDF } from "../jspdf.js";
  
  /**
   * @name autoprint
   * @module
   */
  (function(jsPDFAPI) {
    "use strict";
  
    /**
     * Makes the PDF automatically open the print-Dialog when opened in a PDF-viewer.
     *
     * @name autoPrint
     * @function
     * @param {Object} options (optional) Set the attribute variant to 'non-conform' (default) or 'javascript' to activate different methods of automatic printing when opening in a PDF-viewer .
     * @returns {jsPDF}
     * @example
     * var doc = new jsPDF();
     * doc.text(10, 10, 'This is a test');
     * doc.autoPrint({variant: 'non-conform'});
     * doc.save('autoprint.pdf');
     */
    jsPDFAPI.autoPrint = function(options) {
      "use strict";
      var refAutoPrintTag;
      options = options || {};
      options.variant = options.variant || "non-conform";
  
      switch (options.variant) {
        case "javascript":
          //https://github.com/Rob--W/pdf.js/commit/c676ecb5a0f54677b9f3340c3ef2cf42225453bb
          this.addJS("print({});");
          break;
        case "non-conform":
        default:
          this.internal.events.subscribe("postPutResources", function() {
            refAutoPrintTag = this.internal.newObject();
            this.internal.out("<<");
            this.internal.out("/S /Named");
            this.internal.out("/Type /Action");
            this.internal.out("/N /Print");
            this.internal.out(">>");
            this.internal.out("endobj");
          });
  
          this.internal.events.subscribe("putCatalog", function() {
            this.internal.out("/OpenAction " + refAutoPrintTag + " 0 R");
          });
          break;
      }
      return this;
    };
  })(jsPDF.API);