List of usage examples for org.apache.pdfbox.pdmodel.common PDRectangle A5
PDRectangle A5
To view the source code for org.apache.pdfbox.pdmodel.common PDRectangle A5.
Click Source Link
From source file:ch.dowa.jassturnier.pdf.TabelSheetsPdf.java
public static void exportTabelSheets(Gang actGang, String turnierTitel, int numberOfGames) throws IOException { PdfGenerator gen = new PdfGenerator(PDRectangle.A5); String outputFileName;// w ww .jav a 2s . co m outputFileName = turnierTitel.replace(' ', '_') + "_Spielblaetter_Gang_" + actGang.getGangNr() + ".pdf"; HashMap<String, Table.TableBuilder> tableBuildersMap = new HashMap(); byte[] arrowIconBytes = ResourceLoader.getIcon("arrowIcon.png"); PDImageXObject arrowIcon = PDImageXObject.createFromByteArray(new PDDocument(), arrowIconBytes, "arrowIcon"); float thinBorderWidth = 0.3f; float thickBorderWidth = 1.3f; float rowHeight = 20f; String[] placeLables = new String[4]; placeLables[0] = ResourceLoader.readProperty("PLACE1"); placeLables[1] = ResourceLoader.readProperty("PLACE2"); placeLables[2] = ResourceLoader.readProperty("PLACE3"); placeLables[3] = ResourceLoader.readProperty("PLACE4"); for (Spiel s : actGang.getGames()) { String titel = "Gang " + String.valueOf(actGang.getGangNr()) + " - Tischnummer " + String.valueOf(s.getTischNr()); final Table.TableBuilder tableBuilder = Table.builder() .addColumnsOfWidth(gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f, gen.tabelWidth() / 10f) .fontSize(10).font(STANDART_FONT).borderColor(Color.BLACK).borderWidth(0) .textColor(Color.BLACK); // 1. Zeile tableBuilder.addRow(Row.builder().add(CellText.builder().text("").build()) .add(CellText.builder() .text(placeLables[0] + ": " + s.getTeam1().getSpieler1().getVorname() + " " + s.getTeam1().getSpieler1().getNachname()) .borderWidth(thickBorderWidth).borderWidthBottom(thinBorderWidth).span(4).build()) .add(CellText.builder() .text(placeLables[1] + ": " + s.getTeam2().getSpieler1().getVorname() + " " + s.getTeam2().getSpieler1().getNachname()) .borderWidth(thickBorderWidth).borderWidthBottom(thinBorderWidth).span(4).build()) .add(CellText.builder().text("").build()).font(STANDART_FONT).height(rowHeight).build()); // 2. Zeile tableBuilder.addRow(Row.builder().add(CellText.builder().text("").build()) .add(CellText.builder() .text(placeLables[2] + ": " + s.getTeam1().getSpieler2().getVorname() + " " + s.getTeam1().getSpieler2().getNachname()) .borderWidth(thickBorderWidth).borderWidthBottom(thinBorderWidth) .borderWidthTop(thinBorderWidth).span(4).build()) .add(CellText.builder() .text(placeLables[3] + ": " + s.getTeam2().getSpieler2().getVorname() + " " + s.getTeam2().getSpieler2().getNachname()) .borderWidth(thickBorderWidth).borderWidthTop(thinBorderWidth) .borderWidthBottom(thinBorderWidth).span(4).build()) .add(CellText.builder().text("").build()).font(STANDART_FONT).height(rowHeight).build()); for (int i = 1; i <= numberOfGames; i++) { if (i == 1) { tableBuilder.addRow(Row.builder() .add(CellText.builder().text(String.valueOf(i) + ".").borderWidth(thickBorderWidth) .borderWidthBottom(thinBorderWidth).horizontalAlignment(CENTER) .verticalAlignment(MIDDLE).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).build()) .add(CellText.builder().text("157").borderWidth(thickBorderWidth) .borderWidthBottom(thinBorderWidth).horizontalAlignment(CENTER) .verticalAlignment(MIDDLE).build()) .font(STANDART_FONT).height(rowHeight).build()); } else if (i == numberOfGames) { tableBuilder.addRow(Row.builder() .add(CellText.builder().text(String.valueOf(i) + ".").borderWidth(thickBorderWidth) .borderWidthTop(thinBorderWidth).horizontalAlignment(CENTER) .verticalAlignment(MIDDLE).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).borderWidthBottom(thickBorderWidth).build()) .add(CellText.builder().text("157").borderWidth(thickBorderWidth) .borderWidthTop(thinBorderWidth).horizontalAlignment(CENTER) .verticalAlignment(MIDDLE).build()) .font(STANDART_FONT).height(rowHeight).build()); } else { tableBuilder.addRow(Row.builder() .add(CellText.builder().text(String.valueOf(i) + ".").borderWidth(thickBorderWidth) .borderWidthTop(thinBorderWidth).borderWidthBottom(thinBorderWidth) .horizontalAlignment(CENTER).verticalAlignment(MIDDLE).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthLeft(thickBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thinBorderWidth) .borderWidthRight(thickBorderWidth).build()) .add(CellText.builder().text("157").borderWidth(thickBorderWidth) .borderWidthTop(thinBorderWidth).borderWidthBottom(thinBorderWidth) .horizontalAlignment(CENTER).verticalAlignment(MIDDLE).build()) .font(STANDART_FONT).height(rowHeight).build()); } } tableBuilder.addRow(Row.builder().add(CellText.builder().text("").build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthLeft(thinBorderWidth) .build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthLeft(thinBorderWidth) .build()) .add(CellText.builder().text("").build()).font(STANDART_FONT).height(rowHeight).build()); tableBuilder.addRow(Row.builder() .add(CellText.builder().text("+").horizontalAlignment(CENTER).verticalAlignment(MIDDLE).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").borderWidth(thickBorderWidth).borderWidthLeft(thinBorderWidth) .build()) .add(CellText.builder().text("").build()) .add(CellImage.builder().image(arrowIcon).horizontalAlignment(CENTER).verticalAlignment(MIDDLE) .maxHeight(rowHeight * 0.6f).span(2).build()) .add(CellText.builder().text("").build()).add(CellText.builder().text("").build()) .font(STANDART_FONT).height(rowHeight).build()); String pointsTotal = " " + String.valueOf(numberOfGames * 157); tableBuilder.addRow(Row.builder() .add(CellText.builder().text("=").horizontalAlignment(CENTER).verticalAlignment(MIDDLE).build()) .add(CellText.builder() .text(pointsTotal.substring(pointsTotal.length() - 4, pointsTotal.length() - 3)) .borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .horizontalAlignment(CENTER).verticalAlignment(MIDDLE).build()) .add(CellText.builder() .text(pointsTotal.substring(pointsTotal.length() - 3, pointsTotal.length() - 2)) .borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).horizontalAlignment(CENTER).verticalAlignment(MIDDLE) .build()) .add(CellText.builder() .text(pointsTotal.substring(pointsTotal.length() - 2, pointsTotal.length() - 1)) .borderWidth(thickBorderWidth).borderWidthRight(thinBorderWidth) .borderWidthLeft(thinBorderWidth).horizontalAlignment(CENTER).verticalAlignment(MIDDLE) .build()) .add(CellText.builder() .text(pointsTotal.substring(pointsTotal.length() - 1, pointsTotal.length())) .borderWidth(thickBorderWidth).horizontalAlignment(CENTER).verticalAlignment(MIDDLE) .borderWidthLeft(thinBorderWidth).build()) .add(CellText.builder().text("").build()).add(CellText.builder().text("").build()) .add(CellText.builder().text("").build()).add(CellText.builder().text("").build()) .add(CellText.builder().text("").build()).font(STANDART_FONT_BOLD).height(rowHeight).build()); tableBuildersMap.put(titel, tableBuilder); } gen.exportTemplateWithTableMultiPage(tableBuildersMap, outputFileName); }
From source file:jp.qpg.PDFPrinter.java
License:Apache License
/** * example// w w w.j a v a2s. co m * * @param args not use */ public static void main(String[] args) { Tool.logSetup(null); try (PDFPrinter printer = new PDFPrinter()) { printer.setDrawMarginLine(true).setDrawDebugPoint(true); printer.printRight("right").newLine(); printer.setFontSize(18f).printCenter("center large text").newLine().setFontSize(10.5f); printer.print("left").newLine(); printer.newPage().setPageSize(PDRectangle.A5, true); printer.print("second page"); String path = "\\temp\\PDFPrinter.pdf"; printer.saveAndClose(Files.newOutputStream(Paths.get(path))); logger.info("sample to " + path); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.fit.cssbox.render.PDFRenderer.java
License:Open Source License
/** * Constructor//w w w .j a v a 2 s . c om * * initialize the variables */ public PDFRenderer(int rootWidth, int rootHeight, OutputStream out, String pageFormat) { this.rootHeight = rootHeight; this.pathToSave = out; this.pageCount = 0; switch (pageFormat) { case "A0": this.pageFormat = PDRectangle.A0; break; case "A1": this.pageFormat = PDRectangle.A1; break; case "A2": this.pageFormat = PDRectangle.A2; break; case "A3": this.pageFormat = PDRectangle.A3; break; case "A4": this.pageFormat = PDRectangle.A4; break; case "A5": this.pageFormat = PDRectangle.A5; break; case "A6": this.pageFormat = PDRectangle.A6; break; case "LETTER": this.pageFormat = PDRectangle.LETTER; break; default: this.pageFormat = PDRectangle.A4; break; } initSettings(rootWidth); }