eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.17k stars 1.39k forks source link

Problem in content when generating PDF #471

Closed frabanzo closed 3 years ago

frabanzo commented 3 years ago

Hi @eKoopmans

I was experiencing some issues. Some contents are missing and it adds a margin to the left side even if I set the "margin: 0 ".

This issue was encountered when I used the bundled version URL ()

Here is the source code:

const QuotePDFTemplate = function(param) {
    return {
        init: function() {

        },

        getElementToPrint: () => {
            return document.querySelector(`.pdfProposal`);
        },

        export: () => {
            return new Promise((resolve, reject) => {
                const opts = QuotePDFTemplate.getPDFOptions();
                const elementToPrint = QuotePDFTemplate.getElementToPrint();

                html2pdf().set(opts).from(elementToPrint).save();

                resolve(200);
            })

        },

        getPDFOptions: (element) => {
            const unix = func.dateTimeUnix();
            filename = `Poultry Proposal Farm_${unix}.pdf`;

            pdfOptions = {
                margin: [0, 0],
                filename: filename,
                image: {
                    type: 'jpeg',
                    quality: 0.98
                },
                html2canvas: {
                    scale: 2,
                    logging: true,
                    dpi: 192,
                    letterRendering: true,
                },
                jsPDF: {
                    unit: 'in',
                    format: 'letter',
                    orientation: 'portrait'
                }
            };

            return pdfOptions;
        },
    }
}()

and Here's the pdf Output:

It adds some margin on the left side

image

Some headers in the table are missing.

image

This is a super amazing library and I appreciate your work. :)

I'm hoping that one of you guys will help me with this issue.

TIA.

frabanzo commented 3 years ago

Please check this issue for the answer : https://github.com/eKoopmans/html2pdf.js/issues/474