Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with text after a table when on same page #21

Open
cchance27 opened this issue Aug 14, 2018 · 14 comments
Open

Issue with text after a table when on same page #21

cchance27 opened this issue Aug 14, 2018 · 14 comments

Comments

@cchance27
Copy link

cchance27 commented Aug 14, 2018

Trying to figure out whats going on but if i do the following i get a huge out of memory crash every time.

    doc.pipe(require('fs').createWriteStream('output.pdf'))
    doc.image('logo.PNG', (doc.page.width / 2) - 88, (doc.page.height / 3) - 100)
    doc.font('DaxOT.ttf')
    doc.fontSize('32').text("Report", 0, 0.4 * (doc.page.height - doc.heightOfString("Report", { width: doc.page.width, align: 'center' })), { width: doc.page.width, align: 'center' })
    doc.fontSize('12').text(`${require('moment')(new Date(startTime)).format("MM/DD/YYYY")} - ${require('moment')(new Date(endTime)).format("MM/DD/YYYY")}`, { width: doc.page.width, align: 'center' })

    let table = new PdfTable(doc, { bottomMargin: 20 })
    table.addColumns(columns)
    
    doc.addPage()
    doc.fontSize('16').fillColor('black').text("Top 10 Downlink Congestion")
    doc.fontSize('10')
    table.addBody(overallStats.sort((s) => s.congestDL).reverse().splice(0,10))

    doc.fontSize('16').fillColor('black').text("Top 10 Downlink Congestion")

as soon as that last line hits, memory shoots to nearly 4g and the app crashes, here's the odd thing... if I throw a "doc.addPage()" above the text line at the end it doesn't crash.

@cchance27 cchance27 changed the title Odd issue with multiple tables and text Issue with text after a table when on same page Aug 14, 2018
@tafel
Copy link
Contributor

tafel commented Aug 14, 2018

Could you provide a complete script with datas so I can test that? Using this works well for me:

let doc = new PdfDocument()

doc.fontSize('32').text("Report", 0, 0.4 * (doc.page.height - doc.heightOfString("Report", { width: doc.page.width, align: 'center' })), { width: doc.page.width, align: 'center' })

doc.fontSize('16').fillColor('black').text("Top 10 Downlink Congestion")
doc.fontSize('10')
let table = getTable(doc) // return same table as in README.md
table.addBody(getData()) // return same data as in README.md

doc.fontSize('16').fillColor('black').text("Top 10 Downlink Congestion")

doc.pipe(res);
doc.end();

@sullrich85
Copy link

When I add some text under the table it will show the hole text in the last column... how can I fix that?

@tafel
Copy link
Contributor

tafel commented May 22, 2019

Did you try doc.moveDown() after adding the table body?

@sullrich85
Copy link

yes I tried this but still the same problem?

@tafel
Copy link
Contributor

tafel commented May 22, 2019

Could you provide a link to your PDF with current state and desired state, so I can check what's happening?

@sullrich85
Copy link

no sorry I cant provide you a link like this. but maybe the code

@tafel
Copy link
Contributor

tafel commented May 22, 2019

Since I don't see this problem with README code, it's hard to figure out what is your problem without any screenshot or PDF. You can post your code and maybe it will help understand.

@Spandana-Gajangi
Copy link

@sullrich85 have you tried doc.moveDown() or doc.moveDown()
If you have not tried doc.moveDown(), try now

@sullrich85
Copy link

yes i tried it already... doesnt work... look 5 comments before

@sullrich85
Copy link

i made a new table under the existing and put inside only one row and column its not the best way but it works

@Spandana-Gajangi
Copy link

@sullrich85 post your code here, one of us will help you to find the issue

@sullrich85
Copy link

sullrich85 commented May 24, 2019

    const pdf = new PDFDocument({ autoFirstPage: false, size: 'A4', layout: 'landscape' }),
        table = new PdfTable(pdf, { buttomMargin: 30 });
    table.addPlugin(new (require('voilab-pdf-table/plugins/fitcolumn'))({
        column: 'column1' + 'column2',
    })).setColumnsDefaults({
        align: 'center',
        valign: 'center',
        lineGap: 3.1,
    }).addColumns([
        {
            id: 'column1',
            header: 'column1',
            width: 100,
            align: 'left',
            renderer: (tb, data) => {
                return moment(data.date).format('LL');
            },
        },
        {
            id: 'column2',
            header: 'column2',
            width: 100,
        },
    ]).onPageAdded(tb => (tb.addHeader()));

    pdf.addPage();

    pdf.text(`some text`, { align: 'center' });
    pdf.moveDown().text(`some text`, { align: 'center' });
    pdf.moveDown();

    table.addBody(worklog.sort((a , b) => moment(a.date).valueOf() - moment(b.date).valueOf()));

    // The following Text is in the last column but should under the table
    pdf.moveDown().text(`some text`, { align: 'center' });

    pdf.pipe(fs.createWriteStream(fileUrl));
    pdf.end();

@sonyseng
Copy link

    const pdf = new PDFDocument({ autoFirstPage: false, size: 'A4', layout: 'landscape' }),
        table = new PdfTable(pdf, { buttomMargin: 30 });
    table.addPlugin(new (require('voilab-pdf-table/plugins/fitcolumn'))({
        column: 'column1' + 'column2',
    })).setColumnsDefaults({
        align: 'center',
        valign: 'center',
        lineGap: 3.1,
    }).addColumns([
        {
            id: 'column1',
            header: 'column1',
            width: 100,
            align: 'left',
            renderer: (tb, data) => {
                return moment(data.date).format('LL');
            },
        },
        {
            id: 'column2',
            header: 'column2',
            width: 100,
        },
    ]).onPageAdded(tb => (tb.addHeader()));

    pdf.addPage();

    pdf.text(`some text`, { align: 'center' });
    pdf.moveDown().text(`some text`, { align: 'center' });
    pdf.moveDown();

    table.addBody(worklog.sort((a , b) => moment(a.date).valueOf() - moment(b.date).valueOf()));

    // The following Text is in the last column but should under the table
    pdf.moveDown().text(`some text`, { align: 'center' });

    pdf.pipe(fs.createWriteStream(fileUrl));
    pdf.end();

@sullrich85, I had the same issue with the example from the README. Looks like an issue with the doc.x not being reset. After the table .addBody, I added doc.x = 0 // Or whatever your margins are to fix

@fadhilsurya
Copy link

fadhilsurya commented Mar 17, 2020

solve the issue turns out you have to reset the x by using doc.x = (0, or what ever value that you want)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants