【问题标题】:chrome extension development - printerprovider api - printer id save to pdfchrome扩展开发-printerprovider api-打印机id保存到pdf
【发布时间】:2020-11-06 12:08:50
【问题描述】:

我试图让一个扩展工作,它可以通过一个事件来获取打印的文档。我找到了printerProvider Api。之后我添加了这样的自定义打印机

chrome.printerProvider.onPrintRequested.addListener(function (job, status) {
    console.log(job,status)
});

chrome.printerProvider.onGetPrintersRequested.addListener(
    function ( resultCallback ) {
        resultCallback( [{
            id: '',
            name: 'Custom Printer',
            description: ''
        }] );
    }
);

我正在苦苦挣扎我必须填写什么 id 才能让打印对话框正常工作。我发现这个问题显示了添加网络打印机的方法。 (Google JavaScript API - Chrome.printerProvider: Printer id format)

有没有办法在不实际打印到 id 中的指定打印机的情况下获取 PrintJob,或者如果没有,是否可以打印到 pdf 并在保存后获取 PrintJob(Windows 10 添加了“Microsoft Print to PDF Printer.但我不知道它的 id")?

【问题讨论】:

    标签: google-chrome printing


    【解决方案1】:

    我找到了问题的答案。 为了能够获取 pdf 内容,您必须使用此代码

    chrome.printerProvider.onGetPrintersRequested.addListener(
        function ( resultCallback ) {
            resultCallback( [{
                id: 'customprinter',
                name: 'Custom Printer',
                description: ''
            }] );
        }
    );
    
    chrome.printerProvider.onGetCapabilityRequested.addListener(function (printerId, resultCallback) {
        console.log(printerId);
        if(printerId == 'customprinter') {
            resultCallback(capabilities);
        }
    });
    

    对于功能变量,您可以使用文档https://developers.google.com/cloud-print/docs/cdd#cdd-example中提供的示例

    当您设置功能时,将显示预览并且您可以进行打印。 在 onPrintRequested 中,您将获得打印作业。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      相关资源
      最近更新 更多