Base solution for your next web application
Open Closed

Message Service Close #11725


User avatar
0
maberry created

I am using the built in message service when initiating an html to PDF generation. The confirmation dialog does not close until the PDF has been generated. How can I force it to close after confirming so my user is not sitting there waiting for five seconds?

I am using the latest version of aspnetzero Angular and jsPDF and html2canvas to convert html to PDF.

    onGeneratePDF() {

        if (this.paymentInstaller.paymentStatus === PaymentStatusEnum.InvoiceSent) {
            this.message.confirm(
                '',
                this.l('pdfConfirmation'),
                (isConfirmed) => {
                    if (isConfirmed) {
                        this.generatePDF();
                    }
                }
            );
        }
    }


        async generatePDF() {
        const elementToPrint = this.pdfContent.nativeElement;
        this.fileName = this.invoiceNumber + '.pdf';
        const options = {
            margin: 36,
            filename: this.fileName,
            image: { type: 'jpeg', quality: 1 },
            html2canvas: { scale: 3 },
            jsPDF: { unit: 'pt', format: 'letter', orientation: 'portrait' }
        };

        let pdfData = await html2pdf().set(options).from(elementToPrint).toPdf().output('arraybuffer');

        // Convert the array buffer to a Blob
        const pdfBlob1 = new Blob([pdfData], { type: 'application/pdf' });

        this.uploadAndSave(pdfBlob1);
    }

    uploadAndSave(pdfBlob1: Blob) {
        // Convert the Uint8Array to a Blob
        const pdfBlob = new Blob([pdfBlob1], { type: 'application/pdf' });

        // Create a File object from the Blob
        const pdfFile = new File([pdfBlob], this.fileName, { type: 'application/pdf' });

        // Initialize the uploader and save the generated invoice
        this.invoiceFileUploader = this.initializeUploader(
            AppConsts.remoteServiceBaseUrl + '/GeneratedInvoices/UploadinvoiceFile',
            (fileToken) => {
                this.saveGeneratedInvoice(fileToken);
            }
        );

        this.invoiceFileUploader.clearQueue();
        this.invoiceFileUploader.addToQueue([pdfFile]);
        this.invoiceFileUploader.uploadAll();
    }


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you try calling Swal.close() as shown below ?

    if (isConfirmed) {
    	Swal.close();
    	this.generatePDF();
    }