0

When I'm trying to download a pdf file, I'm getting this error - Uncaught (in promise) Exception { name: "NS_ERROR_FAILURE", message: "", result: 2147500037...... I'm using html2canvas, third party node modules.

Following how I'm using it.

let handlePdfMultiplePages = () => {
        var container = document.getElementById("export");
        var HTML_Width = parseInt(container.offsetWidth);
        var HTML_Height = parseInt(container.offsetHeight);;
        var top_left_margin = 15;
        var PDF_Width = HTML_Width + (top_left_margin * 2);
        var PDF_Height = 900;
        var canvas_image_width = HTML_Width;
        var canvas_image_height = HTML_Height;
        var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1;
        var fileName = "est_" + props.estimate.estimationTitle + "_" + props.estimate.clientName
        html2canvas(container, { allowTaint: true })
            .then(function (canvas) {
                
                canvas.getContext('2d');
                var imgData = canvas.toDataURL("image/jpeg", 1.0);
                var imgData = canvas.toDataURL("image/jpeg", 1.0);
                var pdf = new jsPDF('portrait', 'px', [PDF_Width, PDF_Height]);
                pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height);
                for (var i = 1; i <= totalPDFPages; i++) {
                    pdf.addPage();
                    pdf.addImage(imgData, 'JPG', top_left_margin, (-(PDF_Height * i) + (top_left_margin * 4)), canvas_image_width, canvas_image_height);
                }
                pdf.save(fileName);
                pdf.closePopup(props);
                props.hideScreenLoader();
            });
    }
    const getExportString = () => {
          
        if ((props.userSessionData.exportInProgressShow || props.userSessionData.exportReadyShow) && props.estimate) {
            return (<div><Modal
                open={props.userSessionData.exportReadyShow} modalHeading='Export is Ready' modalLabel=''
                preventCloseOnClickOutside={true}
                secondaryButtonText="Cancel"
                primaryButtonText="Download PDF"
                onSecondarySubmit={() => {
                    props.exportPopupReset();
                }}
                onRequestSubmit={() => {
                    props.exportPopupReset();
                    props.showScreenLoader()
                    handlePdfMultiplePages()
                }}
                onRequestClose={() => {
                    props.exportPopupReset();
                }}
                onClose={() => {
                    props.exportPopupReset();
                }}

            >

                <div id="exportPdfContainer"  >
                    <Export {...props}   />
                </div>
            </Modal>

                {getExportInProgressPopup()}
                {ExportModelString()}
            </div>
            )
        }

I tried to modified html2canvas. but still pdf is not getting downloaded in Firefox on Mac system.

0 Answers0