jquerypdfdatatablespdfmake

How do I center the entire DataTable in the pdf using JQuery pdfHtml5


I'm loving using $('#tableId').DataTable() and the "pdfHtml5" button to generate a PDF. I just can't figure out how to center the information within the generated PDF.

A Table with only two columns shows up on the left of the .pdf, but would look much better if it were just centered.

I am pretty sure it's supposed to be done in the button, but have not quite figured out the last bit.

Current Example (not quite working):

extend:"pdfHtml5",
className: "btn",
text: "Export To PDF",
title: "PDF Title",
filename: "AFileName",
messageTop: "Test Message",

// And this is where I think I'm close...
customize: function(doc) {
    // doc ? = ?
}

Any thoughts?


Solution

  • Look at doc's content section. The second index is the table element. You can force left / right margins with for example

    customize: function(doc) {
      doc.content[1].margin = [ 100, 0, 100, 0 ] //left, top, right, bottom
    }
    

    This will center the table, set values according to your needs. Have looked into the docs, and there seem to be no way to automatically "center" page content. There is alignment options, but these go for text alignment within the rendered content (for example a table).