/** Draws some text on every calendar sheet. */ protected void drawDateInfo(Date day, int d, PdfContentByte directcontent) { directcontent.beginText(); directcontent.setFontAndSize(bf, 18); float x, y; x = OFFSET_LOCATION; y = OFFSET_BOTTOM + HEIGHT + 24; directcontent.showTextAligned(Element.ALIGN_LEFT, "Day " + d, x, y, 0); x = OFFSET_LEFT + WIDTH; directcontent.showTextAligned(Element.ALIGN_RIGHT, day.toString(), x, y, 0); directcontent.endText(); }
/** Draws some text on every calendar sheet. */ protected void drawInfo(PdfContentByte directcontent) { directcontent.beginText(); directcontent.setFontAndSize(bf, 18); float x, y; x = (OFFSET_LEFT + WIDTH + OFFSET_LOCATION) / 2; y = OFFSET_BOTTOM + HEIGHT + 24; directcontent.showTextAligned(Element.ALIGN_CENTER, "FOOBAR FILM FESTIVAL", x, y, 0); x = OFFSET_LOCATION + WIDTH_LOCATION / 2f - 6; y = OFFSET_BOTTOM + HEIGHT_LOCATION; directcontent.showTextAligned(Element.ALIGN_CENTER, "The Majestic", x, y, 90); y = OFFSET_BOTTOM + HEIGHT_LOCATION * 4f; directcontent.showTextAligned(Element.ALIGN_CENTER, "Googolplex", x, y, 90); y = OFFSET_BOTTOM + HEIGHT_LOCATION * 7.5f; directcontent.showTextAligned(Element.ALIGN_CENTER, "Cinema Paradiso", x, y, 90); directcontent.setFontAndSize(bf, 12); x = OFFSET_LOCATION + WIDTH_LOCATION - 6; for (int i = 0; i < LOCATIONS; i++) { y = OFFSET_BOTTOM + ((8.5f - i) * HEIGHT_LOCATION); directcontent.showTextAligned(Element.ALIGN_CENTER, locations.get(i), x, y, 90); } directcontent.setFontAndSize(bf, 6); y = OFFSET_BOTTOM + HEIGHT + 1; for (int i = 0; i < TIMESLOTS; i++) { x = OFFSET_LEFT + (i * WIDTH_TIMESLOT); directcontent.showTextAligned(Element.ALIGN_LEFT, TIME[i], x, y, 45); } directcontent.endText(); }
private static void addScrambles( PdfWriter docWriter, Document doc, ScrambleRequest scrambleRequest, String globalTitle) throws DocumentException, IOException { if (scrambleRequest.fmc) { Rectangle pageSize = doc.getPageSize(); for (int i = 0; i < scrambleRequest.scrambles.length; i++) { String scramble = scrambleRequest.scrambles[i]; PdfContentByte cb = docWriter.getDirectContent(); float LINE_THICKNESS = 0.5f; BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); int bottom = 30; int left = 35; int right = (int) (pageSize.getWidth() - left); int top = (int) (pageSize.getHeight() - bottom); int height = top - bottom; int width = right - left; int solutionBorderTop = bottom + (int) (height * .5); int scrambleBorderTop = solutionBorderTop + 40; int competitorInfoBottom = top - (int) (height * .15); int gradeBottom = competitorInfoBottom - 50; int competitorInfoLeft = right - (int) (width * .45); int rulesRight = competitorInfoLeft; int padding = 5; // Outer border cb.setLineWidth(2f); cb.moveTo(left, top); cb.lineTo(left, bottom); cb.lineTo(right, bottom); cb.lineTo(right, top); // Solution border cb.moveTo(left, solutionBorderTop); cb.lineTo(right, solutionBorderTop); // Rules bottom border cb.moveTo(left, scrambleBorderTop); cb.lineTo(rulesRight, scrambleBorderTop); // Rules right border cb.lineTo(rulesRight, gradeBottom); // Grade bottom border cb.moveTo(competitorInfoLeft, gradeBottom); cb.lineTo(right, gradeBottom); // Competitor info bottom border cb.moveTo(competitorInfoLeft, competitorInfoBottom); cb.lineTo(right, competitorInfoBottom); // Competitor info left border cb.moveTo(competitorInfoLeft, gradeBottom); cb.lineTo(competitorInfoLeft, top); // Solution lines int availableSolutionWidth = right - left; int availableSolutionHeight = scrambleBorderTop - bottom; int lineWidth = 25; // int linesX = (availableSolutionWidth/lineWidth + 1)/2; int linesX = 10; int linesY = (int) Math.ceil(1.0 * WCA_MAX_MOVES_FMC / linesX); cb.setLineWidth(LINE_THICKNESS); cb.stroke(); // int allocatedX = (2*linesX-1)*lineWidth; int excessX = availableSolutionWidth - linesX * lineWidth; int moveCount = 0; solutionLines: for (int y = 0; y < linesY; y++) { for (int x = 0; x < linesX; x++) { if (moveCount >= WCA_MAX_MOVES_FMC) { break solutionLines; } int xPos = left + x * lineWidth + (x + 1) * excessX / (linesX + 1); int yPos = solutionBorderTop - (y + 1) * availableSolutionHeight / (linesY + 1); cb.moveTo(xPos, yPos); cb.lineTo(xPos + lineWidth, yPos); moveCount++; } } float UNDERLINE_THICKNESS = 0.2f; cb.setLineWidth(UNDERLINE_THICKNESS); cb.stroke(); cb.beginText(); int availableScrambleSpace = right - left - 2 * padding; int scrambleFontSize = 20; String scrambleStr = "Scramble: " + scramble; float scrambleWidth; do { scrambleFontSize--; scrambleWidth = bf.getWidthPoint(scrambleStr, scrambleFontSize); } while (scrambleWidth > availableScrambleSpace); cb.setFontAndSize(bf, scrambleFontSize); int scrambleY = 3 + solutionBorderTop + (scrambleBorderTop - solutionBorderTop - scrambleFontSize) / 2; cb.showTextAligned(PdfContentByte.ALIGN_LEFT, scrambleStr, left + padding, scrambleY, 0); cb.endText(); int availableScrambleWidth = right - rulesRight; int availableScrambleHeight = gradeBottom - scrambleBorderTop; Dimension dim = scrambleRequest.scrambler.getPreferredSize( availableScrambleWidth - 2, availableScrambleHeight - 2); PdfTemplate tp = cb.createTemplate(dim.width, dim.height); Graphics2D g2 = new PdfGraphics2D(tp, dim.width, dim.height, new DefaultFontMapper()); try { Svg svg = scrambleRequest.scrambler.drawScramble(scramble, scrambleRequest.colorScheme); drawSvgToGraphics2D(svg, g2, dim); } catch (InvalidScrambleException e) { l.log(Level.INFO, "", e); } finally { g2.dispose(); } cb.addImage( Image.getInstance(tp), dim.width, 0, 0, dim.height, rulesRight + (availableScrambleWidth - dim.width) / 2, scrambleBorderTop + (availableScrambleHeight - dim.height) / 2); ColumnText ct = new ColumnText(cb); int fontSize = 15; int marginBottom = 10; int offsetTop = 27; boolean showScrambleCount = scrambleRequest.scrambles.length > 1; if (showScrambleCount) { offsetTop -= fontSize + 2; } cb.beginText(); cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_CENTER, globalTitle, competitorInfoLeft + (right - competitorInfoLeft) / 2, top - offsetTop, 0); offsetTop += fontSize + 2; cb.endText(); cb.beginText(); cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_CENTER, scrambleRequest.title, competitorInfoLeft + (right - competitorInfoLeft) / 2, top - offsetTop, 0); cb.endText(); if (showScrambleCount) { cb.beginText(); offsetTop += fontSize + 2; cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_CENTER, "Scramble " + (i + 1) + " of " + scrambleRequest.scrambles.length, competitorInfoLeft + (right - competitorInfoLeft) / 2, top - offsetTop, 0); cb.endText(); } offsetTop += fontSize + marginBottom; cb.beginText(); fontSize = 15; cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_LEFT, "Competitor: __________________", competitorInfoLeft + padding, top - offsetTop, 0); offsetTop += fontSize + marginBottom; cb.endText(); cb.beginText(); fontSize = 15; cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_LEFT, "WCA ID:", competitorInfoLeft + padding, top - offsetTop, 0); cb.setFontAndSize(bf, 19); int wcaIdLength = 63; cb.showTextAligned( PdfContentByte.ALIGN_LEFT, "_ _ _ _ _ _ _ _ _ _", competitorInfoLeft + padding + wcaIdLength, top - offsetTop, 0); offsetTop += fontSize + (int) (marginBottom * 1.8); cb.endText(); cb.beginText(); fontSize = 11; cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_CENTER, "DO NOT FILL IF YOU ARE THE COMPETITOR", competitorInfoLeft + (right - competitorInfoLeft) / 2, top - offsetTop, 0); offsetTop += fontSize + marginBottom; cb.endText(); cb.beginText(); fontSize = 11; cb.setFontAndSize(bf, fontSize); cb.showTextAligned( PdfContentByte.ALIGN_CENTER, "Graded by: _______________ Result: ______", competitorInfoLeft + (right - competitorInfoLeft) / 2, top - offsetTop, 0); offsetTop += fontSize + marginBottom; cb.endText(); cb.beginText(); cb.setFontAndSize(bf, 25f); int MAGIC_NUMBER = 40; // kill me now cb.showTextAligned( PdfContentByte.ALIGN_CENTER, "Fewest Moves", left + (competitorInfoLeft - left) / 2, top - MAGIC_NUMBER, 0); cb.endText(); com.itextpdf.text.List rules = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); rules.add("Notate your solution by writing one move per bar."); rules.add("To delete moves, clearly erase/blacken them."); rules.add("Face moves F, B, R, L, U, and D are clockwise."); rules.add("Rotations x, y, and z follow R, U, and F."); rules.add("' inverts a move; 2 doubles a move. (e.g.: U', U2)"); rules.add("w makes a face move into two layers. (e.g.: Uw)"); rules.add("A [lowercase] move is a cube rotation. (e.g.: [u])"); ct.addElement(rules); int rulesTop = competitorInfoBottom + 55; ct.setSimpleColumn( left + padding, scrambleBorderTop, competitorInfoLeft - padding, rulesTop, 0, Element.ALIGN_LEFT); ct.go(); rules = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); rules.add("You have 1 hour to find a solution."); rules.add("Your solution length will be counted in OBTM."); int maxMoves = WCA_MAX_MOVES_FMC; rules.add("Your solution must be at most " + maxMoves + " moves, including rotations."); rules.add( "Your solution must not be directly derived from any part of the scrambling algorithm."); ct.addElement(rules); MAGIC_NUMBER = 150; // kill me now ct.setSimpleColumn( left + padding, scrambleBorderTop, rulesRight - padding, rulesTop - MAGIC_NUMBER, 0, Element.ALIGN_LEFT); ct.go(); doc.newPage(); } } else { Rectangle pageSize = doc.getPageSize(); float sideMargins = 100 + doc.leftMargin() + doc.rightMargin(); float availableWidth = pageSize.getWidth() - sideMargins; float vertMargins = doc.topMargin() + doc.bottomMargin(); float availableHeight = pageSize.getHeight() - vertMargins; if (scrambleRequest.extraScrambles.length > 0) { availableHeight -= 20; // Yeee magic numbers. This should make space for the headerTable. } int scramblesPerPage = Math.min(MAX_SCRAMBLES_PER_PAGE, scrambleRequest.getAllScrambles().size()); int maxScrambleImageHeight = (int) (availableHeight / scramblesPerPage - 2 * SCRAMBLE_IMAGE_PADDING); int maxScrambleImageWidth = (int) (availableWidth / 2); // We don't let scramble images take up more than half the page if (scrambleRequest.scrambler.getShortName().equals("minx")) { // TODO - If we allow the megaminx image to be too wide, the // megaminx scrambles get really tiny. This tweak allocates // a more optimal amount of space to the scrambles. This is possible // because the scrambles are so uniformly sized. maxScrambleImageWidth = 190; } Dimension scrambleImageSize = scrambleRequest.scrambler.getPreferredSize(maxScrambleImageWidth, maxScrambleImageHeight); // First do a dry run just to see if any scrambles require highlighting. // Then do the real run, and force highlighting on every scramble // if any scramble required it. boolean forceHighlighting = false; for (boolean dryRun : new boolean[] {true, false}) { String scrambleNumberPrefix = ""; TableAndHighlighting tableAndHighlighting = createTable( docWriter, doc, sideMargins, scrambleImageSize, scrambleRequest.scrambles, scrambleRequest.scrambler, scrambleRequest.colorScheme, scrambleNumberPrefix, forceHighlighting); if (dryRun) { if (tableAndHighlighting.highlighting) { forceHighlighting = true; continue; } } else { doc.add(tableAndHighlighting.table); } if (scrambleRequest.extraScrambles.length > 0) { PdfPTable headerTable = new PdfPTable(1); headerTable.setTotalWidth(new float[] {availableWidth}); headerTable.setLockedWidth(true); PdfPCell extraScramblesHeader = new PdfPCell(new Paragraph("Extra scrambles")); extraScramblesHeader.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); extraScramblesHeader.setPaddingBottom(3); headerTable.addCell(extraScramblesHeader); if (!dryRun) { doc.add(headerTable); } scrambleNumberPrefix = "E"; TableAndHighlighting extraTableAndHighlighting = createTable( docWriter, doc, sideMargins, scrambleImageSize, scrambleRequest.extraScrambles, scrambleRequest.scrambler, scrambleRequest.colorScheme, scrambleNumberPrefix, forceHighlighting); if (dryRun) { if (tableAndHighlighting.highlighting) { forceHighlighting = true; continue; } } else { doc.add(extraTableAndHighlighting.table); } } } } doc.newPage(); }
public PdfContent( Document document, PdfWriter writer, Date update, List<Computer> computerList, LinkedList<MyObject> objList) throws DocumentException, IOException { PdfMethod pdfMethod = new PdfMethod(document); PdfContentByte pdfContent = writer.getDirectContent(); PdfHeaderFooter event = new PdfHeaderFooter(); Font font = new Font(FontFamily.HELVETICA, 12); BaseFont baseFont = font.getCalculatedBaseFont(false); writer.setPageEvent(event); tableContent(computerList); document.add(table); pdfMethod.addElementToDoc("W - Workstation", 0, 0); pdfMethod.addElementToDoc("P - Production", 0, 0); pdfMethod.addElementToDoc("SVR - Server", 0, 0); pdfMethod.addElementToDoc("STD - Standalone", 0, 0); document.newPage(); for (MyObject object : objList) { Computer computer = (Computer) object.getObject(); int id = computer.getId(); String computerName = computer.getName().toUpperCase(), deptName = computer.getDept().getName(), gaNo = computer.getGaNo(), os = "N/A"; OS_VER osVersion = computer.getOs(); if (osVersion != null) os = osVersion.getAbbreviation(); Iterator<?> folderNameIter = object.getObjList(); // pdf layout new PdfLayout(document, writer, update); pdfContent.beginText(); pdfContent.setFontAndSize(baseFont, 12); // pdf header pdfContent.showTextAligned(0, pdfMethod.setReportNo(id), 118, 733, 0); pdfContent.showTextAligned(0, deptName, 150, 679, 0); pdfContent.showTextAligned(0, computerName, 150, 661, 0); pdfContent.showTextAligned(0, gaNo, 150, 643, 0); pdfContent.showTextAligned(0, os, 150, 625, 0); pdfContent.endText(); pdfMethod.addElementToDoc(" ", 0, 0); // pdf content while (folderNameIter.hasNext()) pdfMethod.addElementToDoc((String) folderNameIter.next(), 0, 0); // pdf remark pdfContent.beginText(); pdfContent.setFontAndSize(baseFont, 7); pdfContent.setColorFill(BaseColor.DARK_GRAY); pdfContent.showTextAligned( 0, "The above program list are for those programs that " + "have to be installed additionally, i.e. Not belonging to default programs / drivers " + "of Windows system.", 15, 30, 0); pdfContent.showTextAligned( 0, "What belongs to default program / driver of Windows system ? " + "It can be searched from the following URL < http://bwhprdrpt:8080/CSCS >", 15, 22, 0); pdfContent.endText(); pdfContent.setColorFill(BaseColor.BLACK); document.newPage(); } }
private static boolean createSingleAccounting( Document accountingDocument, PdfWriter writer, ArrayList<ShiftInstance> shifts, int pageNr) { boolean success = false; PersonalData personalData; float timeSumAsFloat = 0; DecimalFormat euroFormat = new DecimalFormat("#0.00"); float salarySum = 0; try { personalData = PersonalData.getInstance(); Font helveticaFont5 = FontFactory.getFont(FontFactory.HELVETICA, 5); Font helveticaFont6 = FontFactory.getFont(FontFactory.HELVETICA, 6); Font helveticaFont7 = FontFactory.getFont(FontFactory.HELVETICA, 7); Font helveticaFont7Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 7); Font helveticaFont8 = FontFactory.getFont(FontFactory.HELVETICA, 8); Font helveticaFont8Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8); Font helveticaFont9 = FontFactory.getFont(FontFactory.HELVETICA, 9); Font helveticaFont10 = FontFactory.getFont(FontFactory.HELVETICA, 10); Font helveticaFont9Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 9); Font helveticaFont10Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10); Font helveticaFont11Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11); Font helveticaFont18Bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 18); PdfPTable table1 = new PdfPTable(3); table1.setWidthPercentage(100); float[] table1CellWidth = new float[] {18f, 48f, 20f}; table1.setWidths(table1CellWidth); PdfPCell cell1 = new PdfPCell(); cell1.addElement(new Paragraph("DRK Freiburg\nRettungsdienst Freiburg", helveticaFont8)); cell1.setVerticalAlignment(Element.ALIGN_TOP); cell1.setFixedHeight(27f); cell1.setPaddingTop(0); cell1.setBorderWidth(1); Image drkLogo = Image.getInstance(MainWindow.class.getResource("logo_Abrechnung.jpg")); drkLogo.scaleAbsolute(115f, 14f); drkLogo.setAbsolutePosition(441f, 784f); PdfPCell cell2 = new PdfPCell(new Paragraph("Abrechnung AK-RD/Aushilfen", helveticaFont18Bold)); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell2.setPaddingBottom(6); cell2.setBorderWidth(1); cell2.setRowspan(2); PdfPCell cell3 = new PdfPCell(); cell3.setBorderWidth(1); PdfPCell cell1p1 = new PdfPCell(); cell1p1.setFixedHeight(10f); cell1p1.setPaddingTop(0); cell1p1.addElement(new Paragraph("Gültig ab: 01.06.2013", helveticaFont8)); cell1p1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1p1.setVerticalAlignment(Element.ALIGN_TOP); cell1p1.setBorderWidth(1); PdfPCell cell2p1 = new PdfPCell(); cell2p1.setPaddingTop(0); cell2p1.addElement(new Paragraph("Ablage: Personalservice", helveticaFont8)); cell2p1.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2p1.setVerticalAlignment(Element.ALIGN_TOP); cell2p1.setBorderWidth(1); table1.addCell(cell1); table1.addCell(cell2); table1.addCell(cell3); table1.addCell(cell1p1); table1.addCell(cell2p1); // table1.addCell(cell1p1); // create empty line PdfPTable table2 = new PdfPTable(1); table2.setWidthPercentage(100); PdfPCell cellEmpty = new PdfPCell(); cellEmpty.setMinimumHeight(6f); cellEmpty.setBorder(Rectangle.NO_BORDER); table2.addCell(cellEmpty); // set headlines for checkboxes PdfPTable table3 = new PdfPTable(5); table3.setWidthPercentage(100); PdfPCell cell4 = new PdfPCell(new Paragraph(" RD Freiburg", helveticaFont9Bold)); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setMinimumHeight(18f); cell4.setUseBorderPadding(true); PdfPCell cell5 = new PdfPCell(new Paragraph(" KTP Freiburg", helveticaFont9Bold)); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); cell5.setUseBorderPadding(true); PdfPCell cell6 = new PdfPCell(new Paragraph(" RD Aussenwache", helveticaFont9Bold)); cell6.setVerticalAlignment(Element.ALIGN_MIDDLE); cell6.setUseBorderPadding(true); PdfPCell cell7 = new PdfPCell(new Paragraph(" Sanitätsdienste", helveticaFont9Bold)); cell7.setVerticalAlignment(Element.ALIGN_MIDDLE); cell7.setUseBorderPadding(true); PdfPCell cell8 = new PdfPCell(new Paragraph(" KVS Freiburg", helveticaFont9Bold)); cell8.setVerticalAlignment(Element.ALIGN_MIDDLE); cell8.setUseBorderPadding(true); // set checkboxcells PdfPCell cell9 = new PdfPCell(); cell9.setMinimumHeight(92f); PdfPCell cell10 = new PdfPCell(); PdfPCell cell11 = new PdfPCell(); PdfPCell cell12 = new PdfPCell(); PdfPCell cell13 = new PdfPCell(); PdfPCell cell14 = new PdfPCell(new Paragraph("KoSt.: 964001", helveticaFont9Bold)); cell14.setFixedHeight(18f); PdfPCell cell15 = new PdfPCell(new Paragraph("KoSt.: 962100", helveticaFont9Bold)); PdfPCell cell16 = new PdfPCell(new Paragraph("KoSt.: 9640 - X", helveticaFont9Bold)); PdfPCell cell17 = new PdfPCell(new Paragraph("KoSt.: 3653 - X", helveticaFont9Bold)); PdfPCell cell18 = new PdfPCell(new Paragraph("KoSt.: 973100", helveticaFont9Bold)); table3.addCell(cell4); table3.addCell(cell5); table3.addCell(cell6); table3.addCell(cell7); table3.addCell(cell8); table3.addCell(cell9); table3.addCell(cell10); table3.addCell(cell11); table3.addCell(cell12); table3.addCell(cell13); table3.addCell(cell14); table3.addCell(cell15); table3.addCell(cell16); table3.addCell(cell17); table3.addCell(cell18); // checkboxes String[][] KoSt = new String[5][]; // RD Freiburg KoSt[0] = new String[] { "RH (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.RTW, PersonalData.Qualification.RH) + " €/h)", "RS (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.RTW, PersonalData.Qualification.RS) + " €/h)", "RA (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.RTW, PersonalData.Qualification.RA) + " €/h)" }; // KTP Freiburg KoSt[1] = KoSt[0]; // RD Aussenwache KoSt[2] = new String[] { /*"Baby-NAW - 01", */ "Breisach - 03", "Kirchzarten - 10", "RH (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.BREISACH, PersonalData.Qualification.RH) + " €/h)", "RS (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.BREISACH, PersonalData.Qualification.RS) + " €/h)", "RA (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.BREISACH, PersonalData.Qualification.RA) + " €/h)" }; // Sanitätsdienste KoSt[3] = new String[] { "Veranstaltung - 01", "SC-Freiburg - 02", "Konzerthaus - 03", "RH (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.EVENT, PersonalData.Qualification.RH) + " €/h)", "RS (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.EVENT, PersonalData.Qualification.RS) + " €/h)", "RA (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.EVENT, PersonalData.Qualification.RA) + " €/h)" }; // KVS Freiburg KoSt[4] = new String[] { "RH-RA (" + UtilityBox.salaryPerHourString( ShiftContainer.ShiftType.KVS, PersonalData.Qualification.RH) + " €/h)" }; boolean[] boolArray = new boolean[] {false, false, false, false, false, false}; int checkboxSetter; switch (PersonalData.getInstance().getQualification()) { case RH: checkboxSetter = 0; break; case RS: checkboxSetter = 1; break; case RA: checkboxSetter = 2; break; default: checkboxSetter = 0; } int accountType; String costUnit; switch (shifts.get(0).getType()) { case RTW: case HINTERGRUND: accountType = 0; costUnit = "964001"; break; case ELW: accountType = 0; costUnit = "964001"; break; case KTW: accountType = 1; costUnit = "962100"; break; case EVENT: accountType = 3; costUnit = "3653"; break; case SC: accountType = 3; costUnit = "3653"; break; case CONCERT_HALL: accountType = 3; costUnit = "3653"; break; case KVS: accountType = 4; checkboxSetter = 0; costUnit = "973100"; break; default: // Außenwache accountType = 2; costUnit = "9640"; } int xPosition = 46; for (int i = 0; i < KoSt.length; i++) { if (accountType == i) { if (i == 2) { // Außenwache switch (shifts.get(0).getType()) { case BREISACH: boolArray[0] = true; costUnit = costUnit + "03 (RD Breisach)"; break; default: boolArray[1] = true; costUnit = costUnit + "10 (RD Kirchzarten)"; } boolArray[checkboxSetter + 2] = true; } else if (i == 3) { // Sandienst etc. switch (shifts.get(0).getType()) { case SC: boolArray[1] = true; boolArray[checkboxSetter + 3] = true; costUnit = costUnit + "02 (SC-Freiburg)"; break; case EVENT: boolArray[0] = true; boolArray[checkboxSetter + 3] = true; costUnit = costUnit + "01 (Veranstaltung)"; break; default: // CONCERT_HALL boolArray[2] = true; costUnit = costUnit + "03 (Konzerthaus, 8,50 €/h)"; break; } } else { boolArray[checkboxSetter] = true; } } createCheckbox( writer, accountingDocument, helveticaFont9, KoSt[i], xPosition, 736, boolArray, pageNr); boolArray = new boolean[] {false, false, false, false, false, false}; xPosition += 105; } // create another empty line PdfPTable table4 = new PdfPTable(1); table4.setWidthPercentage(100); PdfPCell cellEmpty2 = new PdfPCell(); cellEmpty2.setFixedHeight(5f); cellEmpty2.setBorder(Rectangle.NO_BORDER); table4.addCell(cellEmpty2); // create personal-data-table float personalDataCellHeight = 18f; Font personalDataFont = helveticaFont10Bold; PdfPTable table5 = new PdfPTable(5); table5.setWidthPercentage(100); table5.setWidths(new float[] {137f, 4f, 192f, 30f, 115f}); String address = "Bekannt"; // if address is not known put it into the form if (!personalData.addressKnown()) { address = personalData.getAddress(); } String bankNameAndCity = "Bekannt"; String accountNumber = "Bekannt"; String blz = "Bekannt"; if (!personalData.isDataKnown()) { bankNameAndCity = personalData.getBankNameAndCity(); accountNumber = personalData.getAccountNumber(); blz = Integer.toString(personalData.getBlz()); } // name PdfPCell cell20 = new PdfPCell(new Paragraph("Name", personalDataFont)); cell20.setFixedHeight(personalDataCellHeight); cell20.disableBorderSide(Rectangle.RIGHT); PdfPCell cell21 = new PdfPCell(new Paragraph(":", personalDataFont)); cell21.disableBorderSide(Rectangle.LEFT); cell21.disableBorderSide(Rectangle.RIGHT); PdfPCell cell22 = new PdfPCell( new Paragraph(" " + personalData.getFirstName() + " " + personalData.getLastName())); cell22.setColspan(3); cell22.disableBorderSide(Rectangle.LEFT); // adress PdfPCell cell22p1 = new PdfPCell(new Paragraph("Adresse*", personalDataFont)); cell22p1.setFixedHeight(personalDataCellHeight); cell22p1.disableBorderSide(Rectangle.RIGHT); PdfPCell cell22p2 = new PdfPCell(new Paragraph(":", personalDataFont)); cell22p2.disableBorderSide(Rectangle.LEFT); cell22p2.disableBorderSide(Rectangle.RIGHT); PdfPCell cell22p3 = new PdfPCell(new Paragraph(" " + address)); cell22p3.disableBorderSide(Rectangle.LEFT); cell22p3.setColspan(3); // bankname PdfPCell cell23 = new PdfPCell(new Paragraph("Bankname und Ort*", personalDataFont)); cell23.setFixedHeight(personalDataCellHeight); cell23.disableBorderSide(Rectangle.RIGHT); PdfPCell cell24 = new PdfPCell(new Paragraph(":", personalDataFont)); cell24.disableBorderSide(Rectangle.LEFT); cell24.disableBorderSide(Rectangle.RIGHT); PdfPCell cell25 = new PdfPCell(new Paragraph(" " + bankNameAndCity)); cell25.disableBorderSide(Rectangle.LEFT); cell25.setColspan(3); // accountnr PdfPCell cell26 = new PdfPCell(new Paragraph("Kontonummer*", personalDataFont)); cell26.setFixedHeight(personalDataCellHeight); cell26.disableBorderSide(Rectangle.RIGHT); PdfPCell cell27 = new PdfPCell(new Paragraph(":", personalDataFont)); cell27.disableBorderSide(Rectangle.LEFT); cell27.disableBorderSide(Rectangle.RIGHT); PdfPCell cell28 = new PdfPCell(new Paragraph(" " + accountNumber)); cell28.disableBorderSide(Rectangle.LEFT); cell28.disableBorderSide(Rectangle.RIGHT); PdfPCell cell29 = new PdfPCell(new Paragraph("BLZ :", personalDataFont)); cell29.disableBorderSide(Rectangle.LEFT); cell29.disableBorderSide(Rectangle.RIGHT); PdfPCell cell2930 = new PdfPCell(new Paragraph(blz)); cell2930.disableBorderSide(Rectangle.LEFT); PdfPCell cell30 = new PdfPCell(new Paragraph("zu belastende Kostenstelle", personalDataFont)); cell30.setFixedHeight(personalDataCellHeight); cell30.disableBorderSide(Rectangle.RIGHT); PdfPCell cell3031 = new PdfPCell(new Paragraph(":", personalDataFont)); cell3031.disableBorderSide(Rectangle.LEFT); cell3031.disableBorderSide(Rectangle.RIGHT); PdfPCell cell3032 = new PdfPCell(new Paragraph(" " + costUnit)); cell3032.disableBorderSide(Rectangle.LEFT); cell3032.setColspan(3); table5.addCell(cell20); table5.addCell(cell21); table5.addCell(cell22); table5.addCell(cell22p1); table5.addCell(cell22p2); table5.addCell(cell22p3); table5.addCell(cell23); table5.addCell(cell24); table5.addCell(cell25); table5.addCell(cell26); table5.addCell(cell27); table5.addCell(cell28); table5.addCell(cell29); table5.addCell(cell2930); table5.addCell(cell30); table5.addCell(cell3031); table5.addCell(cell3032); // set textline PdfPTable table6 = new PdfPTable(1); table6.setWidthPercentage(100); PdfPCell cell31 = new PdfPCell( new Paragraph("* Angabe nur bei Neueinstellung oder Veränderungen", helveticaFont8)); cell31.setFixedHeight(12f); cell31.setBorder(Rectangle.NO_BORDER); table6.addCell(cell31); // set the shift table PdfPTable table7 = new PdfPTable(10); table7.setWidthPercentage(100); table7.setWidths( new float[] {1.96f, 0.9f, 1.8f, 1.8f, 2.9f, 1.96f, 1.96f, 1.85f, 1.85f, 2.2f}); // headlines Font shiftTableHeadlineFont = helveticaFont8Bold; PdfPCell cell32 = new PdfPCell(new Paragraph("Datum", shiftTableHeadlineFont)); cell32.setFixedHeight(50f); cell32.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell32.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell33 = new PdfPCell(new Paragraph("Tag", shiftTableHeadlineFont)); cell33.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell33.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell34 = new PdfPCell(new Paragraph("Uhrzeit\nvon", shiftTableHeadlineFont)); cell34.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell34.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell35 = new PdfPCell(new Paragraph("Uhrzeit\nbis", shiftTableHeadlineFont)); cell35.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell35.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell36 = new PdfPCell(new Paragraph("Besatzung", shiftTableHeadlineFont)); cell36.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell36.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell37 = new PdfPCell(new Paragraph("Anzahl geleisteter Stunden (Zeit)", shiftTableHeadlineFont)); cell37.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell37.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell38 = new PdfPCell( new Paragraph("Anzahl geleisteter Stunden (Dezimal)", shiftTableHeadlineFont)); cell38.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell38.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell39 = new PdfPCell(new Paragraph("€ pro\nStunde", shiftTableHeadlineFont)); cell39.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell39.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell40 = new PdfPCell(new Paragraph("€\ngesamt", shiftTableHeadlineFont)); cell40.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell40.setHorizontalAlignment(Rectangle.ALIGN_CENTER); PdfPCell cell41 = new PdfPCell(new Paragraph("Kommentar", shiftTableHeadlineFont)); cell41.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell41.setHorizontalAlignment(Rectangle.ALIGN_CENTER); table7.addCell(cell32); table7.addCell(cell33); table7.addCell(cell34); table7.addCell(cell35); table7.addCell(cell36); table7.addCell(cell37); table7.addCell(cell38); table7.addCell(cell39); table7.addCell(cell40); table7.addCell(cell41); float salary = UtilityBox.getInstance() .calculateSalaryPerHour(shifts.get(0), PersonalData.getInstance().getQualification()); // begin shifttable for (int i = 0; i <= 12; i++) { ShiftInstance currentShift = null; String weekDay = ""; String date = ""; String startTimeAsString = ""; String endTimeAsString = ""; String partner = ""; Font partnerFont = helveticaFont9; String timeInHours = ""; String timeasFloat = ""; String salaryPerHour = ""; String shiftSalary = ""; String commuteExpenses = ""; String comment = ""; Font commentFont = helveticaFont9; SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); Calendar cal = Calendar.getInstance(); if (shifts.size() > i) { currentShift = shifts.get(i); date = currentShift.getDateString(); try { cal.setTime(sdf.parse(date)); weekDay = UtilityBox.getDayOfWeekString(cal.get(Calendar.DAY_OF_WEEK)); } catch (ParseException ex) { System.out.println( "Exception in PdfCreator.createAccounting " + "(parsing date failed): " + ex.getMessage()); } int startTime = currentShift.getActualStartingTimeWithPrepTime(); int endTime = currentShift.getActualEndTime(); int breakTime = currentShift.getActualBreakTime(); startTimeAsString = UtilityBox.createTimeStringFromInt(startTime); endTimeAsString = UtilityBox.createTimeStringFromInt(endTime); partner = currentShift.getPartner(); if (partner.length() > 14) { if (partner.length() > 18) { partner = partner.substring(0, 18); } partnerFont = helveticaFont7; } timeInHours = UtilityBox.getInstance().calculateTimeInHours(startTime, endTime, breakTime); timeasFloat = euroFormat.format(currentShift.getTimeAsFloat()); timeSumAsFloat += currentShift.getTimeAsFloat(); salaryPerHour = euroFormat.format(salary) + " €"; shiftSalary = euroFormat.format(currentShift.getTimeAsFloat() * salary) + " €"; comment = currentShift.getComment(); int commentLength = comment.length(); if (commentLength > 10) { if (commentLength > 13) { if (commentLength > 36) { comment = comment.substring(0, 36); } commentFont = helveticaFont5; } else { commentFont = helveticaFont7; } } } PdfPCell tempCell = emptyPdfPCell(); Paragraph content = new Paragraph(date, helveticaFont9); tempCell.addElement(content); tempCell.setFixedHeight(19f); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(weekDay, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(startTimeAsString, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(endTimeAsString, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(partner, partnerFont); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(timeInHours, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(timeasFloat, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(salaryPerHour, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(shiftSalary, helveticaFont9); tempCell.addElement(content); table7.addCell(tempCell); tempCell = emptyPdfPCell(); content = new Paragraph(comment, commentFont); tempCell.addElement(content); table7.addCell(tempCell); } // end of shift table // calculate the complete salary salarySum = timeSumAsFloat * salary; PdfPCell cell42 = emptyPdfPCell(); cell42.setFixedHeight(20); cell42.setBorderWidth(2); cell42.setColspan(6); cell42.addElement( new Paragraph("Summe der geleisteten Stunden / Auszahlungsbetrag:", helveticaFont8Bold)); cell42.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell42.setPaddingBottom(6); PdfPCell cell43 = new PdfPCell(new Paragraph(euroFormat.format(timeSumAsFloat), helveticaFont9Bold)); cell43.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell43.setBorderWidthBottom(2); cell43.setBorderWidthTop(2); cell43.setBorderWidthLeft(2); PdfPCell cell44 = new PdfPCell(new Paragraph(euroFormat.format(salary) + " €", helveticaFont9Bold)); cell44.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell44.setBorderWidthBottom(2); cell44.setBorderWidthTop(2); PdfPCell cell45 = new PdfPCell(new Paragraph(euroFormat.format(salarySum) + " €", helveticaFont9Bold)); cell45.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell45.setColspan(1); cell45.setBorderWidthBottom(2); cell45.setBorderWidthTop(2); // commentcell PdfPCell cell461 = emptyPdfPCell(); cell461.setColspan(2); cell461.setBorderWidthBottom(2); cell461.setBorderWidthTop(2); cell461.setBorderWidthRight(2); table7.addCell(cell42); table7.addCell(cell43); table7.addCell(cell44); table7.addCell(cell45); // table7.addCell(cell46); table7.addCell(cell461); // another empty line PdfPTable table8 = new PdfPTable(1); table8.setWidthPercentage(100); PdfPCell cell47 = new PdfPCell(); cell47.setFixedHeight(8); cell47.setBorder(Rectangle.NO_BORDER); table8.addCell(cell47); // sign-field PdfPTable table9 = new PdfPTable(1); table9.setWidthPercentage(100); String signatureString = "Unterschrift Mitarbeiter/in:"; if (false) { // TODO: wenn version veraltet signatureString += " NICHT FREIGEGEBENE VERSION. NICHT ABGEBEN."; } PdfPCell cell48 = new PdfPCell(new Paragraph(signatureString, helveticaFont11Bold)); cell48.setVerticalAlignment(Rectangle.ALIGN_MIDDLE); cell48.setFixedHeight(25); cell48.setBorderWidth(2); table9.addCell(cell48); // another empty line. We use table8 again. // PdfPTable table10 = new PdfPTable(3); table10.setWidthPercentage(100); table10.setWidths(new int[] {5, 6, 8}); PdfPCell cell49 = new PdfPCell(new Paragraph("Eingang RDL", helveticaFont10)); cell49.setVerticalAlignment(Rectangle.ALIGN_TOP); cell49.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell49.setBorderWidthBottom(0); cell49.setFixedHeight(48); PdfPCell cell50 = new PdfPCell(new Paragraph("Eingang Personalservice", helveticaFont10)); cell50.setVerticalAlignment(Rectangle.ALIGN_TOP); cell50.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell50.setBorderWidthBottom(0); PdfPCell cell51 = new PdfPCell(new Paragraph("geprüft:", helveticaFont10)); cell51.setVerticalAlignment(Rectangle.ALIGN_TOP); cell51.setHorizontalAlignment(Rectangle.ALIGN_LEFT); PdfPCell cell52 = new PdfPCell(); cell52.setBorderWidthTop(0); cell52.setFixedHeight(48); PdfPCell cell53 = new PdfPCell(); cell53.setBorderWidthTop(0); PdfPCell cell54 = new PdfPCell(new Paragraph("zur Zahlung angewiesen:", helveticaFont10)); cell54.setVerticalAlignment(Rectangle.ALIGN_TOP); cell54.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell54.setFixedHeight(48); table10.addCell(cell49); table10.addCell(cell50); table10.addCell(cell51); table10.addCell(cell52); table10.addCell(cell53); table10.addCell(cell54); // add department-box float departmentBoxX = 345; float departmentBoxY = 123; float departmentBoxWidth = 103; float departmentBoxHeight = 28; float departmentBoxTextY = departmentBoxY + 20; PdfContentByte contentByte = writer.getDirectContent(); contentByte.setLineWidth(.7f); contentByte.rectangle( departmentBoxX, departmentBoxY, departmentBoxWidth, departmentBoxHeight); contentByte.rectangle( departmentBoxX + departmentBoxWidth, departmentBoxY, departmentBoxWidth, departmentBoxHeight); contentByte.beginText(); contentByte.setFontAndSize(BaseFont.createFont("Helvetica", "", false), 8); contentByte.showTextAligned( PdfContentByte.ALIGN_CENTER, "Dienstplanung", (int) (departmentBoxX + (departmentBoxWidth / 2)), departmentBoxTextY, 0); contentByte.setFontAndSize(BaseFont.createFont("Helvetica", "", false), 8); contentByte.showTextAligned( PdfContentByte.ALIGN_CENTER, "bei SAN-Diensten Abt.RK", (int) (departmentBoxX + (departmentBoxWidth * 1.5)), departmentBoxTextY, 0); contentByte.endText(); // add payment order-box float paymentOrderBoxY = 75; float paymentOrderBoxTextY = paymentOrderBoxY + 20; contentByte.rectangle( departmentBoxX, paymentOrderBoxY, 2 * departmentBoxWidth, departmentBoxHeight); // use table8 for a empty line again // Version/Author PdfPTable table11 = new PdfPTable(4); table11.setWidthPercentage(100); table11.addCell(new PdfPCell(new Paragraph("Version 4.2", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("geändert:", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("Freigegeben:", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("Seite 1 von 1", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("Stand: 26.01.2015", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("E. Willaredt, J. Güttler", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("Karin Müller", helveticaFont9))); table11.addCell(new PdfPCell(new Paragraph("Personalservice", helveticaFont9))); // add tables to document accountingDocument.add(table1); accountingDocument.add(drkLogo); accountingDocument.add(table2); accountingDocument.add(table3); accountingDocument.add(table4); accountingDocument.add(table5); accountingDocument.add(table6); accountingDocument.add(table7); accountingDocument.add(table8); accountingDocument.add(table9); accountingDocument.add(table8); accountingDocument.add(table10); accountingDocument.add(table8); accountingDocument.add(table11); success = true; // TODO: for JDK7 use Multicatch } catch (Exception e) { // DocumentException | IOException | NullPointerException e) { success = false; UtilityBox.getInstance() .displayErrorPopup( "Abrechnung", "Fehler beim Erstellen der Abrechnung:\n" + e.getMessage()); } return success; }