Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 848
A554551N Avatar asked Oct 27 '25 15:10

A554551N


1 Answers

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).

like image 144
davidkonrad Avatar answered Oct 29 '25 07:10

davidkonrad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!