Folding mode

This commit is contained in:
2019-02-15 19:30:20 +01:00
parent eafdc26744
commit dc783c77bd
@@ -35,7 +35,6 @@ public class CardCreator {
public static final int slotsPerLine = 9; public static final int slotsPerLine = 9;
public static final int cardsPerLine = 7; public static final int cardsPerLine = 7;
public static final boolean generateBacksides = true;
public static final String DEST = "results/simple_table.pdf"; public static final String DEST = "results/simple_table.pdf";
public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180); public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
@@ -64,7 +63,8 @@ public class CardCreator {
File file = new File(DEST); File file = new File(DEST);
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
createPdf(DEST, sortCards(cards)); // createDirectPrintPdf(DEST, sortCards(cards), true);
createFoldingPdf(DEST, sortCards(cards));
} catch (IOException | SpotifyWebApiException e) { } catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage()); 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/sftp:host=qudio.local,user=volumio/data/INTERNAL"
// "/run/user/1000/gvfs/smb-share:server=cubon,share=hidrive/Media/Audio" // "/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"; 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); File f = new File(path);
if (f.exists()) { if (f.exists()) {
@@ -164,7 +163,134 @@ public class CardCreator {
return lines; return lines;
} }
protected void createPdf(String dest, List<List<Card>> lines) throws Exception { protected void createFoldingPdf(String dest, List<List<Card>> 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<Card> 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<List<Card>> lines, boolean generateBacksides) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
pdfDoc.setDefaultPageSize(PageSize.A4.rotate()); pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
@@ -228,7 +354,7 @@ public class CardCreator {
cell.add(p); cell.add(p);
} }
table.addCell(cell); // cell.setRotationAngle(Math.PI) table.addCell(cell);
} }
table.setMinHeight(105 / 25.4f * 72); table.setMinHeight(105 / 25.4f * 72);
@@ -325,7 +451,17 @@ public class CardCreator {
"/INTERNAL/Pettersson und Findus - Pettersson zeltet", "/INTERNAL/Pettersson und Findus - Pettersson zeltet",
"/INTERNAL/Post für den Tiger (Väter sprechen Janosch - Folge 2 Günther Jauch)", "/INTERNAL/Post für den Tiger (Väter sprechen Janosch - Folge 2 Günther Jauch)",
"/INTERNAL/Rabe Socke - Alles Gefunden", "/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); new CardCreator(links);