From 1b7075ecca5639e69c1a56d929c81850a5815a1c Mon Sep 17 00:00:00 2001 From: Tilman Date: Tue, 18 Dec 2018 18:05:40 +0100 Subject: [PATCH] SimpleTable with QR code --- cardcreator/.classpath | 24 +----------- cardcreator/pom.xml | 26 ++++++++++--- .../src/tutorial/chapter01/SimpleTable.java | 37 +++++++++++++++++++ 3 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 cardcreator/src/tutorial/chapter01/SimpleTable.java diff --git a/cardcreator/.classpath b/cardcreator/.classpath index 9fc2de7..9c5bd87 100644 --- a/cardcreator/.classpath +++ b/cardcreator/.classpath @@ -1,29 +1,9 @@ - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/cardcreator/pom.xml b/cardcreator/pom.xml index 92aef0b..9ce0719 100644 --- a/cardcreator/pom.xml +++ b/cardcreator/pom.xml @@ -1,6 +1,22 @@ - - 4.0.0 - de.tilman - cardcreator - 0.0.1-SNAPSHOT + + 4.0.0 + de.tilman + cardcreator + 0.0.1-SNAPSHOT + + + + org.slf4j + slf4j-log4j12 + 1.7.18 + + + com.itextpdf + itext7-core + 7.1.4 + pom + + \ No newline at end of file diff --git a/cardcreator/src/tutorial/chapter01/SimpleTable.java b/cardcreator/src/tutorial/chapter01/SimpleTable.java new file mode 100644 index 0000000..865f87e --- /dev/null +++ b/cardcreator/src/tutorial/chapter01/SimpleTable.java @@ -0,0 +1,37 @@ +package tutorial.chapter01; + +import java.io.File; + +import com.itextpdf.barcodes.BarcodeQRCode; +import com.itextpdf.kernel.pdf.PdfDocument; +import com.itextpdf.kernel.pdf.PdfWriter; +import com.itextpdf.layout.Document; +import com.itextpdf.layout.element.Image; +import com.itextpdf.layout.element.Table; + +public class SimpleTable { + public static final String DEST = "results/simple_table.pdf"; + + public static void main(String[] args) throws Exception { + File file = new File(DEST); + file.getParentFile().mkdirs(); + new SimpleTable().manipulatePdf(DEST); + } + + protected void manipulatePdf(String dest) throws Exception { + PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); + Document doc = new Document(pdfDoc); + + Table table = new Table(9); + for (int i = 0; i < 17; i++) { + table.addCell("hi"); + } + + BarcodeQRCode barcodeQRCode = new BarcodeQRCode("spotify:album:1X2HXE2lAqdmD8VjiBX8Tn"); + table.addCell(new Image(barcodeQRCode.createFormXObject(pdfDoc))); + + doc.add(table); + + doc.close(); + } +} \ No newline at end of file