Skip to content

Instantly share code, notes, and snippets.

@lateshift
Created September 15, 2022 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lateshift/9f6eddea44aac981a5dcbee2d8318c58 to your computer and use it in GitHub Desktop.
Save lateshift/9f6eddea44aac981a5dcbee2d8318c58 to your computer and use it in GitHub Desktop.
Generate a table
var doc = new pdf.Document({
font: fonts.Helvetica,
properties: {
title: "Tabelle",
author: "Jens C",
subject: "Tabelle",
producer: "Tabelle",
creator: "Jens C."
}
});
doc.footer()
.pageNumber(function(curr, total) { return curr + ' / ' + total }, { textAlign: 'center' })
var cell = doc.cell({ paddingBottom: 0.5*pdf.cm })
cell.text('Tabellentest', { fontSize: 16, font: fonts.HelveticaBold })
doc.cell({ paddingBottom: 1*pdf.cm }).text()
.add('Tables work.')
var pageHeadline1 = doc.cell({ paddingBottom: 0.5*pdf.cm })
pageHeadline1.text('A table:', { fontSize: 14, font: fonts.HelveticaBold })
// Table
var table = doc.table({
widths: [
null,
null,
null,
null,
null,
null,
null,
],
borderHorizontalWidths: function(i) { return i < 2 ? 1 : 0.1 },
borderWidth: 0.5,
padding: 5
})
var tr = table.header({ font: fonts.HelveticaBold})
tr.cell('H1', { textAlign: "center", backgroundColor: "#f1f1f1" })
tr.cell('H2', { textAlign: "center" , backgroundColor: "#f1f1f1"})
tr.cell('H3', { textAlign: "center" , backgroundColor: "#f1f1f1"})
tr.cell('H4', { textAlign: "center" , backgroundColor: "#f1f1f1"})
tr.cell('H5', { textAlign: "center" , backgroundColor: "#f1f1f1"})
tr.cell('H6', { textAlign: "center" , backgroundColor: "#f1f1f1"})
tr.cell('H7', { textAlign: "center" , backgroundColor: "#f1f1f1"})
for (var i = 0;i < 10;i++) {
var row = table.row()
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
row.cell(`h${i}`, { textAlign: "center" })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment