Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 以角度打印多个文件_Javascript_Angular_Printjs - Fatal编程技术网

Javascript 以角度打印多个文件

Javascript 以角度打印多个文件,javascript,angular,printjs,Javascript,Angular,Printjs,我有多个blob,我正在从中创建blob URL,并使用库显示浏览器的打印预览屏幕 我有 async printDocuments(): Promise<any> { const _files: { fileName: string, blob: any }[] = await this._getFiles(); _files.forEach((_fileInfo, index) => { const blobUrl = URL.createOb

我有多个blob,我正在从中创建blob URL,并使用库显示浏览器的打印预览屏幕

我有

async printDocuments(): Promise<any> {
    const _files: { fileName: string, blob: any }[] = await this._getFiles();
    _files.forEach((_fileInfo, index) => {
        const blobUrl = URL.createObjectURL(_fileInfo.blob);
        printJS(blobUrl);
    });
}
但现在它正在显现

core.js:4196 ERROR Error: Uncaught (in promise): TypeError: params.printable.charAt is not a function
TypeError: params.printable.charAt is not a function

onPrintDialogClose
对我来说很有效

这就是我所做的

async printDocuments(): Promise<any> {
     const _files: { fileName: string, blob: any }[] = await this._getFiles();
     if (_files && _files.length > 0) {
            this._printDocument(_files, 0);
     }
}

private _printDocument(files: { fileName: string, blob: any }[], index: number): void {
    const blobUrl = URL.createObjectURL(files[index].blob);
    printJS({
        printable: blobUrl,
        type: "pdf",
        onPrintDialogClose: () => {
            index = index + 1;
            if (index < files.length) {
                this._printDocument(files, index);
            }
        }
    });
}

尝试使用库
onPrintDialogClose
,仅在完成第一个打印作业后触发下一个打印作业。浏览器可能会忽略其他作业,因为它们是在处理第一个作业之前触发的@crabbly,更新了问题,你能帮忙吗
async printDocuments(): Promise<any> {
     const _files: { fileName: string, blob: any }[] = await this._getFiles();
     if (_files && _files.length > 0) {
            this._printDocument(_files, 0);
     }
}

private _printDocument(files: { fileName: string, blob: any }[], index: number): void {
    const blobUrl = URL.createObjectURL(files[index].blob);
    printJS({
        printable: blobUrl,
        type: "pdf",
        onPrintDialogClose: () => {
            index = index + 1;
            if (index < files.length) {
                this._printDocument(files, index);
            }
        }
    });
}
// fix : printjs issue #495
const handler = () => {
    // Make sure the event only happens once.
    window.removeEventListener("mouseover", handler);

    // function that you want to execute for onPrintDialogClose
    onCloseCallback();

    // Remove iframe from the DOM, by default 'printJS'
    const iframe = document.getElementById("printJS");

    if (iframe) {
        iframe.remove();
    }
    };
setTimeout(() => { window.addEventListener("mouseover", handler); }, 1000);