natancabral / pdfkit-table

Helps to draw informations in simple tables using pdfkit. #server-side. Generate pdf tables with javascript (PDFKIT plugin)
MIT License
93 stars 59 forks source link

Rendering often fails #62

Open leegee opened 1 year ago

leegee commented 1 year ago

Rendering 85,000 rows, I found the first page was lovely, but the row that started page two was spread out so that each cell of that row was on a new page. That seems to happen for three records in a row.

Then, every now and again, at the end of a page, when a row contains a cell that is spread over several lines, one cell is rendered on a page by itself.

Sadly, I can't send a sample as I'm working on a sensitive commercial project.

I'll have to get Puppeteer to render the PDF for now, but hope this vague report is of some help.

image

tonprince commented 1 year ago

I have thr same issue. Any workaround?

leegee commented 1 year ago

I have thr same issue. Any workaround?

I did it by hand using Puppeteer:

import * as puppeteer from 'puppeteer';
const inlineCss = require('inline-css');

const htmlInput = '<p>something to go in the doc</p>';
const browser = await puppeteer.launch({
    headless: true,
    pipe: true,
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--headless',
        '--disable-gpu',
        '--full-memory-crash-report',
        '--unlimited-storage',
    ]
});
const page = await browser.newPage();

await page.emulateMediaType('screen');

// Just inlines a stylesheet:
const htmlCssed = await inlineCss(htmlInput, { url: "/" });

await page.setContent(htmlCssed, {
    waitUntil: ['load', 'domcontentloaded', 'networkidle0'],
    timeout: 60000,
});

let pdfStream;
try {
    // https://pptr.dev/api/puppeteer.pdfoptions
    pdfStream = await page.createPDFStream({
        timeout: 0,
        printBackground: true,
        format: 'A4',
        landscape: true,
        displayHeaderFooter: true,
        margin: {
            top: '1cm', left: '1cm', right: '1cm', bottom: '1cm'
        },
        headerTemplate: '<div></div>',
        footerTemplate: `<div style="text-align: right; width: 100%;">
            <span class="pageNumber"></span> of <span class="totalPages"></span>
        </div>`,
    });
    logger.log({ action: "PDF created pdf stream" });
} catch (e) {
    logger.error({ action: "PDF error in create pdf stream", e });
}

pdfStream
    .on('end', () => logger.log('pdfStream done'))
    .on('error', (e) => logger.error({ e, action: 'pdfReport' }))

return pdfStream;