diff --git a/cardcreator/src/de/tilman/cardcreator/CardCreator.java b/cardcreator/src/de/tilman/cardcreator/CardCreator.java index 106db2f..9d22187 100644 --- a/cardcreator/src/de/tilman/cardcreator/CardCreator.java +++ b/cardcreator/src/de/tilman/cardcreator/CardCreator.java @@ -35,7 +35,6 @@ public class CardCreator { public static final int slotsPerLine = 9; public static final int cardsPerLine = 7; - public static final boolean generateBacksides = true; public static final String DEST = "results/simple_table.pdf"; public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180); @@ -64,7 +63,8 @@ public class CardCreator { File file = new File(DEST); file.getParentFile().mkdirs(); - createPdf(DEST, sortCards(cards)); +// createDirectPrintPdf(DEST, sortCards(cards), true); + createFoldingPdf(DEST, sortCards(cards)); } catch (IOException | SpotifyWebApiException e) { System.out.println("Error: " + e.getMessage()); @@ -114,7 +114,6 @@ public class CardCreator { // "/run/user/1000/gvfs/sftp:host=qudio.local,user=volumio/data/INTERNAL" // "/run/user/1000/gvfs/smb-share:server=cubon,share=hidrive/Media/Audio" String path = "/run/user/1000/gvfs/sftp:host=qudio.local,user=volumio/data" + link.substring(link.indexOf("/")) + "/cover.jpg"; - System.out.println(path); File f = new File(path); if (f.exists()) { @@ -164,7 +163,134 @@ public class CardCreator { return lines; } - protected void createPdf(String dest, List> lines) throws Exception { + protected void createFoldingPdf(String dest, List> lines) throws Exception { + PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); + pdfDoc.setDefaultPageSize(PageSize.A4.rotate()); + + Document doc = new Document(pdfDoc); + doc.setMargins(0, 0, 0, 0); + + UnitValue[] colWidths = new UnitValue[slotsPerLine]; + for (int i = 0; i < colWidths.length; i++) + colWidths[i] = new UnitValue(UnitValue.PERCENT, 100/slotsPerLine); + + for (List line : lines) { + + Table table = new Table(colWidths); + table.useAllAvailableWidth(); + + for (Card card : line) { + + Cell cell = new Cell(); + cell.setBorder(new SolidBorder(ColorConstants.GRAY, 0.5f, 0.5f)); + cell.setPadding(0); + + if (card != null) { + + Paragraph p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(43.62f); // top padding is 15.387 mm + Image qrcode = new Image(card.qrcode.createFormXObject(pdfDoc)); + qrcode.setWidth(10 / 25.4f * 72); + p.add(qrcode); + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(5 / 25.4f * 72); + if (card.cover != null) { + Image cover = card.cover; + cover.setWidth(30 / 25.4f * 72); + p.add(cover); + } + else { + p.setPaddingBottom(30 / 25.4f * 72); + } + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(5 / 25.4f * 72); + p.setFontSize(8f); + p.add(card.artist); + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(3 / 25.4f * 72); + p.setFontSize(9f); + p.setBold(); + p.add(card.title); + cell.add(p); + } + + table.addCell(cell.setRotationAngle(Math.PI)); + } + + table.setMinHeight(105 / 25.4f * 72); + table.setMaxHeight(105 / 25.4f * 72); + doc.add(table); + + table = new Table(colWidths); + table.useAllAvailableWidth(); + + for (Card card : line) { + + Cell cell = new Cell(); + cell.setBorder(new SolidBorder(ColorConstants.GRAY, 0.5f, 0.5f)); + cell.setPadding(0); + + if (card != null) { + + Paragraph p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(43.62f); // top padding is 15.387 mm + Image qrcode = new Image(card.qrcode.createFormXObject(pdfDoc)); + qrcode.setWidth(10 / 25.4f * 72); + p.add(qrcode); + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(5 / 25.4f * 72); + if (card.cover != null) { + Image cover = card.cover; + cover.setWidth(30 / 25.4f * 72); + p.add(cover); + } + else { + p.setPaddingBottom(30 / 25.4f * 72); + } + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(5 / 25.4f * 72); + p.setFontSize(8f); + p.add(card.artist); + cell.add(p); + + p = new Paragraph(); + p.setTextAlignment(TextAlignment.CENTER); + p.setPaddingTop(3 / 25.4f * 72); + p.setFontSize(9f); + p.setBold(); + p.add(card.title); + cell.add(p); + } + + table.addCell(cell); + } + + table.setMinHeight(105 / 25.4f * 72); + table.setMaxHeight(105 / 25.4f * 72); + doc.add(table); + } + + doc.close(); + } + + protected void createDirectPrintPdf(String dest, List> lines, boolean generateBacksides) throws Exception { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); pdfDoc.setDefaultPageSize(PageSize.A4.rotate()); @@ -228,7 +354,7 @@ public class CardCreator { cell.add(p); } - table.addCell(cell); // cell.setRotationAngle(Math.PI) + table.addCell(cell); } table.setMinHeight(105 / 25.4f * 72); @@ -325,7 +451,17 @@ public class CardCreator { "/INTERNAL/Pettersson und Findus - Pettersson zeltet", "/INTERNAL/Post für den Tiger (Väter sprechen Janosch - Folge 2 Günther Jauch)", "/INTERNAL/Rabe Socke - Alles Gefunden", - "/INTERNAL/Rabe Socke - Alles Rabenstark!" + "/INTERNAL/Rabe Socke - Alles Rabenstark!", + "/INTERNAL/Die drei Fragezeichen Kids/01 - Panik im Paradies", + "/INTERNAL/Die drei Fragezeichen Kids/02 - Radio Rocky Beach", + "/INTERNAL/Die drei Fragezeichen Kids/03 - Invasion der Fliegen", + "/INTERNAL/Die drei Fragezeichen Kids/04 - Chaos vor der Kamera", + "/INTERNAL/Die drei Fragezeichen Kids/05 - Flucht in die Zukunft", + "/INTERNAL/Die drei Fragezeichen Kids/06 - Gefahr im Gruselgarten", + "/INTERNAL/Die drei Fragezeichen Kids/07 - Gruft der Piraten", + "/INTERNAL/Die drei Fragezeichen Kids/08 - Nacht unter Wölfen", + "/INTERNAL/Die drei Fragezeichen Kids/09 - SOS über den Wolken", + "/INTERNAL/Die drei Fragezeichen Kids/10 - Spuk in Rocky Beach" ); new CardCreator(links);