diff --git a/cardcreator/results/simple_table.pdf b/cardcreator/results/simple_table.pdf index 9d549e7..74ae5ed 100755 Binary files a/cardcreator/results/simple_table.pdf and b/cardcreator/results/simple_table.pdf differ diff --git a/cardcreator/src/de/tilman/cardcreator/CardCreator.java b/cardcreator/src/de/tilman/cardcreator/CardCreator.java index 0561fbe..a433759 100755 --- a/cardcreator/src/de/tilman/cardcreator/CardCreator.java +++ b/cardcreator/src/de/tilman/cardcreator/CardCreator.java @@ -34,8 +34,8 @@ import com.wrapper.spotify.requests.authorization.client_credentials.ClientCrede public class CardCreator { - public static final int slotsPerLine = 9; - public static final int cardsPerLine = 7; + public static final float mmUnit = 72f/25.4f; // see https://itextpdf.com/en/resources/faq/technical-support/itext-7/how-define-width-cell + public static final int cardsPerLine = 6; public static final String DEST = "results/simple_table.pdf"; public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180); @@ -64,7 +64,6 @@ public class CardCreator { File file = new File(DEST); file.getParentFile().mkdirs(); -// createDirectPrintPdf(DEST, sortCards(cards), true); createFoldingPdf(DEST, sortCards(cards)); } catch (IOException | SpotifyWebApiException e) { @@ -79,7 +78,7 @@ public class CardCreator { protected List fetchCardData(List links) throws SpotifyWebApiException, IOException { List cards = new LinkedList(); HashMap hints = new HashMap(); - hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-15"); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); for (String link : links) { System.out.println(link); @@ -187,19 +186,6 @@ public class CardCreator { if (line.size() > 0) lines.add(line); - if (cardsPerLine < slotsPerLine) { - for (List l : lines) { - boolean addToStart = true; - while (l.size() < slotsPerLine) { - if (addToStart) - l.add(0, null); - else - l.add(null); - addToStart = !addToStart; - } - } - } - return lines; } @@ -208,14 +194,16 @@ public class CardCreator { pdfDoc.setDefaultPageSize(PageSize.A4.rotate()); Document doc = new Document(pdfDoc); - doc.setMargins(0, 0, 0, 0); + doc.setMargins(0, 28.5f * mmUnit, 0, 28.5f * mmUnit); - UnitValue[] colWidths = new UnitValue[slotsPerLine]; + UnitValue[] colWidths = new UnitValue[cardsPerLine]; for (int i = 0; i < colWidths.length; i++) - colWidths[i] = new UnitValue(UnitValue.PERCENT, 100/slotsPerLine); + colWidths[i] = new UnitValue(UnitValue.PERCENT, 100/cardsPerLine); for (List line : lines) { + Cell oldCell = null; + Table table = new Table(colWidths); table.useAllAvailableWidth(); @@ -229,46 +217,47 @@ public class CardCreator { 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); + qrcode.setWidth(22 * mmUnit); // Cannot set margin to 0 on QR codes and they grow with the length of the content. This is an approximation. + p.setPaddingTop(22 * mmUnit - qrcode.getWidth().getValue() / 2); // mid point of QR code is 22 mm from top border p.add(qrcode); cell.add(p); p = new Paragraph(); p.setTextAlignment(TextAlignment.CENTER); - p.setPaddingTop(5 / 25.4f * 72); + p.setPaddingTop(5 * mmUnit); if (card.cover != null) { Image cover = card.cover; - cover.setWidth(30 / 25.4f * 72); + cover.setWidth(28 * mmUnit); p.add(cover); } else { - p.setPaddingBottom(30 / 25.4f * 72); + p.setPaddingBottom(28 * mmUnit); } cell.add(p); p = new Paragraph(); p.setTextAlignment(TextAlignment.CENTER); - p.setPaddingTop(5 / 25.4f * 72); + p.setPaddingTop(5 * mmUnit); p.setFontSize(8f); p.add(card.artist); cell.add(p); p = new Paragraph(); p.setTextAlignment(TextAlignment.CENTER); - p.setPaddingTop(3 / 25.4f * 72); + p.setPaddingTop(3 * mmUnit); p.setFontSize(9f); p.setBold(); p.add(card.title); cell.add(p); } + oldCell = cell; table.addCell(cell.setRotationAngle(Math.PI)); } - table.setMinHeight(105 / 25.4f * 72); - table.setMaxHeight(105 / 25.4f * 72); + table.setMinHeight(105 * mmUnit); + table.setMaxHeight(105 * mmUnit); doc.add(table); table = new Table(colWidths); @@ -284,9 +273,9 @@ public class CardCreator { 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); + qrcode.setWidth(22 * mmUnit); // Cannot set margin to 0 on QR codes and they grow with the length of the content. This is an approximation. + p.setPaddingTop(22 * mmUnit - qrcode.getWidth().getValue() / 2); // mid point of QR code is 22 mm from top border p.add(qrcode); cell.add(p); @@ -322,117 +311,13 @@ public class CardCreator { table.addCell(cell); } - table.setMinHeight(105 / 25.4f * 72); - table.setMaxHeight(105 / 25.4f * 72); + table.setMinHeight(105 * mmUnit); + table.setMaxHeight(105 * mmUnit); 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()); - - 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); - - Table firstLine = null; - - 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); - } - - table.setMinHeight(105 / 25.4f * 72); - table.setMaxHeight(105 / 25.4f * 72); - doc.add(table); - - if (generateBacksides) { - if (firstLine == null && line != lines.get(lines.size() - 1)) { - firstLine = table; - } - else { - Table tbl1 = new Table(colWidths); - tbl1.useAllAvailableWidth(); - - Table tbl2 = new Table(colWidths); - tbl2.useAllAvailableWidth(); - - for (int i = slotsPerLine - 1; i > 0 ; i--) { - if (firstLine != null) - tbl1.addCell(firstLine.getCell(0, i)); - tbl2.addCell(table.getCell(0, i)); - } - - tbl1.setMinHeight(105 / 25.4f * 72); - tbl1.setMaxHeight(105 / 25.4f * 72); - doc.add(tbl1); - - tbl2.setMinHeight(105 / 25.4f * 72); - tbl2.setMaxHeight(105 / 25.4f * 72); - doc.add(tbl2); - - firstLine = null; - } - } - } - - doc.close(); - } public static void main(String[] args) throws Exception { @@ -514,41 +399,8 @@ public class CardCreator { // ENDE Josefine - "spotify:album:1X2HXE2lAqdmD8VjiBX8Tn", - "spotify:album:5nCA2mAr3rFzk1A6LZXDYm", - "spotify:album:1Vc2BZntRGIdv3Ul8AM6cz", - "spotify:album:0H3rE11E9DrD3j2gEvQJ5R", - "spotify:album:0YSWLbCg5SpxAb2VOON3mX", - "spotify:track:7oolFzHipTMg2nL7shhdz2", - "spotify:album:2bK91wL7wsGgJJ7uD6XFYo", - "spotify:album:4umBnPXwRr7kKJ2WUVueTq", - "spotify:album:6FGyqglqi0oS3tl4SxyZxf", - "spotify:album:3iBX3uryCaJl9xWUeOBOFv", - "spotify:album:0FuEZWTzqOJ4hOlUoAJ6wY", - "spotify:album:6sTefktQuhIHCWjVYMS6h5", - "spotify:album:1OifUGnI9ziBW4cOW3DSlL", - "spotify:album:1Z2uoOl1cQPS8R3O9sFbbX", - "spotify:album:1FAupt6dQ7w849zXeJd5JB", - "spotify:album:4M74k3dfsbzLQgAKfO8GOU", - "spotify:album:1qDJ6x3PrQXq9zjZ9846eL", - "spotify:album:6FNI6BsAUrSZdpPIBxvIPK", - "spotify:album:2upvzA60OLbOW9M0QKQ0hO", - "spotify:album:66Rt4KLkF7jhSPMLi223Zv", - "spotify:album:24edFfeEP7oy8BWGatc5CQ", - "spotify:album:00XbTSVi9wVH1jYiYr2Vc9", - "spotify:album:2ZQKn9GVeJalLEuh3BvuOB", - "spotify:album:3KD5QNC2k1328SsuYFIjiq", - "spotify:album:6g5MSdVTrKY3f1ZzsqUhXw", - "spotify:album:3ixBUKtl7HtxSZECC3YnNb", - "spotify:album:6GUPPV35zx22eO4g9tctKN", - "spotify:album:49GuQzqAa08WMB8fjtEBj4", - "spotify:album:0Pg0kbjNl7PC22ghcSqKih", - "spotify:album:6JvQHhP638FrhhNrfvc5m0", - "spotify:album:721jCM2jOWLTF90qAXsm4j", - "spotify:album:6psaeRRArzDxstvowFPIsD", - "spotify:album:36sbLOkQp8WdgyOnMsySo1", - "spotify:album:6AdTIgvKhY5knelEsDWJx8", - "spotify:album:6ef5sf2fJI8KYZdTbOBLSp", + "https://ih1.redbubble.net/image.859117621.1102/ra,unisex_tshirt,x2200,101010:01c5ca27c6,front-c,267,146,1000,1000-bg,f8f8f8.u6.jpg|German: ÄäÖöÜüß, Russian: ЯБГДЖЙ, Polish: ŁĄŻĘĆŃŚŹ, Japanese: Kanji: てすと (te-su-to), Hankaku: アイウエオカキクケコサシスセソタチツテ", + "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Radio_Teddy_Logo.svg/1200px-Radio_Teddy_Logo.svg.png|Radio Teddy|http://streamtdy.ir-media-tec.com/live/mp3-128/web/play.mp3", "NAS/share/Astrid Lindgren - Die Kinder aus der Krachmacherstraße", "NAS/share/Astrid Lindgren - Lotta zieht um", "NAS/share/Astrid Lindgren - Michel bringt die Welt in Ordnung", @@ -665,7 +517,41 @@ public class CardCreator { "NAS/share/Wir Kinder vom Kleistpark - machen Musik", "NAS/share/Wunderbar, der Herbst ist da", // "https://www.medienkompetenzportal-nrw.de/fileadmin/medienkompetenzportal-nrw/inhalte/MPA/EdM/2018-05/KiRaKa_Logo.jpg|KiRaKa|http://www.wdr.de/wdrlive/media/kiraka.m3u", - "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Radio_Teddy_Logo.svg/1200px-Radio_Teddy_Logo.svg.png|Radio Teddy|http://streamtdy.ir-media-tec.com/live/mp3-128/web/play.mp3", + "spotify:album:1X2HXE2lAqdmD8VjiBX8Tn", + "spotify:album:5nCA2mAr3rFzk1A6LZXDYm", + "spotify:album:1Vc2BZntRGIdv3Ul8AM6cz", + "spotify:album:0H3rE11E9DrD3j2gEvQJ5R", + "spotify:album:0YSWLbCg5SpxAb2VOON3mX", + "spotify:track:7oolFzHipTMg2nL7shhdz2", + "spotify:album:2bK91wL7wsGgJJ7uD6XFYo", + "spotify:album:4umBnPXwRr7kKJ2WUVueTq", + "spotify:album:6FGyqglqi0oS3tl4SxyZxf", + "spotify:album:3iBX3uryCaJl9xWUeOBOFv", + "spotify:album:0FuEZWTzqOJ4hOlUoAJ6wY", + "spotify:album:6sTefktQuhIHCWjVYMS6h5", + "spotify:album:1OifUGnI9ziBW4cOW3DSlL", + "spotify:album:1Z2uoOl1cQPS8R3O9sFbbX", + "spotify:album:1FAupt6dQ7w849zXeJd5JB", + "spotify:album:4M74k3dfsbzLQgAKfO8GOU", + "spotify:album:1qDJ6x3PrQXq9zjZ9846eL", + "spotify:album:6FNI6BsAUrSZdpPIBxvIPK", + "spotify:album:2upvzA60OLbOW9M0QKQ0hO", + "spotify:album:66Rt4KLkF7jhSPMLi223Zv", + "spotify:album:24edFfeEP7oy8BWGatc5CQ", + "spotify:album:00XbTSVi9wVH1jYiYr2Vc9", + "spotify:album:2ZQKn9GVeJalLEuh3BvuOB", + "spotify:album:3KD5QNC2k1328SsuYFIjiq", + "spotify:album:6g5MSdVTrKY3f1ZzsqUhXw", + "spotify:album:3ixBUKtl7HtxSZECC3YnNb", + "spotify:album:6GUPPV35zx22eO4g9tctKN", + "spotify:album:49GuQzqAa08WMB8fjtEBj4", + "spotify:album:0Pg0kbjNl7PC22ghcSqKih", + "spotify:album:6JvQHhP638FrhhNrfvc5m0", + "spotify:album:721jCM2jOWLTF90qAXsm4j", + "spotify:album:6psaeRRArzDxstvowFPIsD", + "spotify:album:36sbLOkQp8WdgyOnMsySo1", + "spotify:album:6AdTIgvKhY5knelEsDWJx8", + "spotify:album:6ef5sf2fJI8KYZdTbOBLSp", "spotify:album:6ZsR4Vx24b1E1PkiGSUQSE", // Die kleine Hexe "spotify:album:4py7EzeOO7Q95mPS52b7hE", // Hotzenplotz 3 "spotify:album:17k9w5N035qsJF1UTAhnfi", // Hotzenplotz 4 @@ -686,7 +572,7 @@ public class CardCreator { "spotify:album:7tfjSYq5aWFwKlYWRzmPMc", // Das kleine Gespenst "spotify:album:4kGTkO7CP063Bk0j14829K", // Der Räuber Hotzenplotz und die Mondrakete "spotify:album:4tzPsEeFw4kR42NE4NqJvX", // Immer lustig in Bullerbü - "spotify:album:1zuWVjkOPIK5OHFnlgDQcf" // Die Häschenschule + "spotify:album:1zuWVjkOPIK5OHFnlgDQcf" // Die Häschenschule */ ); new CardCreator(links);