PDF Export - Customisation

PDF Export - Customisation

mattkylemattkyle Posts: 7Questions: 2Answers: 0

Hi all,

I've been able to implement the export buttons, including the one I wish to use PDF. I've been able to hide columns and add an image to the PDF, but I am really struggling to anything else.

Looking at the PDF make website is no help as I don't know how to apply/where to place the code.

The most urgent request is to set the column width on the export.

Answers

  • mattkylemattkyle Posts: 7Questions: 2Answers: 0
    edited January 2016

    Ok so I managed to fine this (my table has 5 columns):

    doc.content[1].table.widths = [ '20%', '30%', '30%', '10%', '10%'],

    It works perfectly but I don't quite understand how it's working. Few questions if someone can help:

    1) What is the [1] referring too?

    2) On the PDFMake Documentation, it has:

    content: [ { table: {widths: 'auto' '*' '200'}}

    Does this explain the content[1].table.widths format? Can this be applied for other styling, e.g. centering text, text color etc?

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    1) What is the [1] referring too?

    An element in the document definition array that Buttons creates. See the makepdf documentation for the full range of options for that array.

    Does this explain the content[1].table.widths format?

    Yes.

    Can this be applied for other styling, e.g. centering text, text color etc?

    Sure. I would suggest you add console.log( doc ) so you can inspect the document definition and modify it to suit your needs, per the makepdf documentation.

    Allan

  • jorgedebolijorgedeboli Posts: 1Questions: 0Answers: 0

    The best solutions for widhts of columns:

    extend: 'pdfHtml5',
    title: 'The title ',
    text: 'The text',
    orientation: 'landscape',
    pageSize: 'A4',
    exportOptions: {
    columns: [ 0, 1, 2, 3, 5, 6, 7 ]
    },
    customize: function ( doc ) {
    doc.content[1].table.widths = [
    '5%',
    '30%',
    '30%',
    '10%',
    '10%',
    '10%',
    '5%'
    ]
    }

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Looks good. The downside is that they are statically coded - it would be best if pdfmake automatically calculated them, but development on it appears to have stalled.

    Allan

This discussion has been closed.