Печать нескольких файлов в angular - PullRequest
0 голосов
/ 05 августа 2020

У меня есть несколько BLOB-объектов, из которых я создаю URL-адреса BLOB-объектов и использую print- js библиотеку для отображения экрана предварительного просмотра в браузере.

, но здесь отображается диалоговое окно предварительного просмотра печати только для первого файла.

Как я могу распечатать все документы, объединяя или открывая множественную печать windows.

Я пробовал использовать это

printJS({
    printable: _files[0].blob,
    type: "pdf",
    onPrintDialogClose: () => {
      console.log("nex");
    }
});

но теперь отображается

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

1 Ответ

1 голос
/ 11 августа 2020

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);
            }
        }
    });
}

Вот документация

Спасибо @crabbly

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...