@Override public PdfPTable generatePage() throws Exception { Image image = Image.getInstance(imageFile.toURL()); float heightToWidthRatio = (210f / 297f); Image imageCropped = ImageUtils.cropImageToMeetRatio(pdfWriter, image, heightToWidthRatio); PdfPCell cell = new PdfPCell(imageCropped, true); cell.setBorder(0); cell.setPadding(COVER_MARGIN); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setExtraParagraphSpace(0); cell.setRightIndent(0); PdfPTable table = new PdfPTable(1); ; table.setWidthPercentage(100f); table.setWidths(new int[]{1}); table.setExtendLastRow(true); table.addCell(cell); return table; }
private PdfPTable cellRodape(String value, boolean l,boolean r,int align) { Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f); PdfPTable pTable = new PdfPTable(1); pTable.setWidthPercentage(100f); PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO)); if(l){cellValue.setBorderWidthLeft(0);} if(r){cellValue.setBorderWidthRight(0);} switch (align) { case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break; case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break; case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break; default:break; } pTable.addCell(cellValue); return pTable; }
private void addContent(PdfPTable table) { if (!SelectionRepository.noBaseData()) addBaseData(table); if (SelectionRepository.summary) addSummary(table); if (!SelectionRepository.noExperience()) addWorkExperience(table); if (!SelectionRepository.noSkills()) addSkills(table); if (!SelectionRepository.noAccomplishments()) addAccomplishments(table); if (SelectionRepository.languages) addLanguages(table); if (SelectionRepository.education) addEducation(table); if (SelectionRepository.additionalInfo) addAdditionalInfo(table); if (SelectionRepository.interests) addInterests(table); }
private void addBaseData(PdfPTable table) { addSectionName(table, "Base data"); if (SelectionRepository.nameSurname) addNameMiddleSurname(table); if (SelectionRepository.gender) addGender(table); if (SelectionRepository.email) addEmail(table); if (SelectionRepository.cityCountry) addCityAndCountry(table); if (SelectionRepository.phones) addPhones(table); if (SelectionRepository.jobTitles) addJobTitles(table); if (SelectionRepository.urls) addUrls(table); }
protected PdfPTable createGridTable(ReportDataModel dataModel, boolean isRepeatHeader) throws Exception { PdfPTable table = new PdfPTable(calculateGridColumnCount(dataModel.getTopColumnHeaders())); table.setWidthPercentage(100); Collection<ColumnHeader> topHeaders = dataModel.getTopColumnHeaders(); List<Integer> widths = new ArrayList<Integer>(); generateGridColumnWidths(topHeaders, widths); int[] values = new int[widths.size()]; for (int i = 0; i < widths.size(); i++) { values[i] = widths.get(i); } table.setWidths(values); int maxHeaderLevel = getGridMaxColumngroup(topHeaders); createGridColumnHeader(table, topHeaders, maxHeaderLevel); createGridTableDatas(table, dataModel.getReportData()); if (isRepeatHeader) { table.setHeaderRows(maxHeaderLevel); } return table; }
private void createGridColumnHeader(PdfPTable table, Collection<ColumnHeader> topHeaders, int maxHeaderLevel) throws Exception { for (int i = 1; i < 50; i++) { List<ColumnHeader> result = new ArrayList<ColumnHeader>(); generateGridHeadersByLevel(topHeaders, i, result); for (ColumnHeader header : result) { PdfPCell cell = new PdfPCell(createParagraph(header)); if (header.getBgColor() != null) { int[] colors = header.getBgColor(); cell.setBackgroundColor(new BaseColor(colors[0], colors[1], colors[2])); } cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(header.getAlign()); cell.setColspan(header.getColspan()); if (header.getColumnHeaders().size() == 0) { int rowspan = maxHeaderLevel - (header.getLevel() - 1); if (rowspan > 0) { cell.setRowspan(rowspan); } } table.addCell(cell); } } }
private void createGridTableDatas(PdfPTable table, Collection<ReportData> datas) { for (ReportData data : datas) { PdfPCell cell = new PdfPCell(createParagraph(data.getTextChunk())); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); int level = this.calculateIndentationCount(data.getTextChunk().getText()); if (data.getBgColor() != null) { int[] colors = data.getBgColor(); cell.setBackgroundColor(new BaseColor(colors[0], colors[1], colors[2])); } if (level == 0) { cell.setHorizontalAlignment(data.getAlign()); } else { cell.setIndent(20 * level); } table.addCell(cell); } }
public void generatePDF() throws Exception { PdfPTable table = createTable(4); table.addCell(createCell("学生信息列表:", keyfont, Element.ALIGN_LEFT, 4, false)); table.addCell(createCell("姓名", keyfont, Element.ALIGN_CENTER)); table.addCell(createCell("年龄", keyfont, Element.ALIGN_CENTER)); table.addCell(createCell("性别", keyfont, Element.ALIGN_CENTER)); table.addCell(createCell("住址", keyfont, Element.ALIGN_CENTER)); for (int i = 0; i < 5; i++) { table.addCell(createCell("姓名" + i, textfont)); table.addCell(createCell(i + 15 + "", textfont)); table.addCell(createCell((i % 2 == 0) ? "男" : "女", textfont)); table.addCell(createCell("地址" + i, textfont)); } document.add(table); document.close(); }
private void createCells(PdfPTable table, Object t, List<ExcelExportEntity> excelParams, int rowHeight) throws Exception { ExcelExportEntity entity; int maxHeight = getThisMaxHeight(t, excelParams); for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { Collection<?> list = getListCellValue(entity, t); for (Object obj : list) { createListCells(table, obj, entity.getList(), rowHeight); } } else { Object value = getCellValue(entity, t); if (entity.getType() == 1) { createStringCell(table, value == null ? "" : value.toString(), entity, rowHeight, 1, maxHeight); } else { createImageCell(table, value == null ? "" : value.toString(), entity, rowHeight, 1, maxHeight); } } } }
/** * 创建表头 * * @param title * @param table */ private int createTitleRow(PdfExportParams title, PdfPTable table, List<ExcelExportEntity> excelParams) { int rows = getRowNums(excelParams); for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) { ExcelExportEntity entity = excelParams.get(i); if (entity.getList() != null) { if (StringUtils.isNotBlank(entity.getName())) { createStringCell(table, entity.getName(), entity, 10, entity.getList().size(), 1); } List<ExcelExportEntity> sTitel = entity.getList(); for (int j = 0, size = sTitel.size(); j < size; j++) { createStringCell(table, sTitel.get(j).getName(), sTitel.get(j), 10); } } else { createStringCell(table, entity.getName(), entity, 10, 1, rows == 2 ? 2 : 1); } } return rows; }
private void createAccomodationTableHeaders(PdfPTable accomodationsTable) { PdfPCell numberHeader = new PdfPCell(new Paragraph("Lp.")); PdfPCell roomNumberHeader = new PdfPCell(new Paragraph("Nr pokoju")); PdfPCell dateFromHeader = new PdfPCell(new Paragraph("Od")); PdfPCell dateToHeader = new PdfPCell(new Paragraph("Do")); PdfPCell placesHeader = new PdfPCell(new Paragraph("Miejsca")); PdfPCell roomTypeHeader = new PdfPCell(new Paragraph("Typ")); PdfPCell roomPriceHeader = new PdfPCell(new Paragraph("Cena")); accomodationsTable.addCell(numberHeader); accomodationsTable.addCell(roomNumberHeader); accomodationsTable.addCell(dateFromHeader); accomodationsTable.addCell(dateToHeader); accomodationsTable.addCell(placesHeader); accomodationsTable.addCell(roomTypeHeader); accomodationsTable.addCell(roomPriceHeader); }
private void addOfferInstances(List<OfferInstance> offerInstances, Document document, BaseFont bf) throws DocumentException { if(offerInstances.isEmpty()) { return; } document.add(new Paragraph("Wybrane oferty: ", new Font(bf, 12))); PdfPTable offerInstancesTable = new PdfPTable(3); offerInstancesTable.setWidthPercentage(100); offerInstancesTable.setSpacingBefore(18f); offerInstancesTable.setSpacingAfter(18f); createofferInstancesTableHeaders(offerInstancesTable); createofferInstancesTableContent(offerInstances, offerInstancesTable); document.add(offerInstancesTable); }
private void createofferInstancesTableContent(List<OfferInstance> offerInstances, PdfPTable offerInstancesTable) { DecimalFormat decimalFormat = new DecimalFormat(PRICE_DECIMAL_FORMAT); int i = 1; for (OfferInstance offerInstance : offerInstances) { Offer offer = offerInstance.getOffer(); PdfPCell numberCell = new PdfPCell(new Paragraph(String.valueOf(i++))); String offerName = offer.getName(); PdfPCell roomNumberCell = new PdfPCell(new Paragraph(offerName)); String offerPrice = decimalFormat.format(offer.getBaseValue()) + " PLN"; PdfPCell roomPriceCell = new PdfPCell(new Paragraph(offerPrice)); offerInstancesTable.addCell(numberCell); offerInstancesTable.addCell(roomNumberCell); offerInstancesTable.addCell(roomPriceCell); } }
private void createTableContent(List<CleaningSchedule> cleaningSchedules, PdfPTable cleaningScheduleTable) { int i = 1; for (CleaningSchedule cleaningSchedule : cleaningSchedules) { PdfPCell numberCell = new PdfPCell(new Paragraph(String.valueOf(i++))); String roomNumber = cleaningSchedule.getAccomodation().getAllocationEntity().getNumber(); PdfPCell roomNumberCell = new PdfPCell(new Paragraph(roomNumber)); String preferredTime = cleaningSchedule.getDesiredTime() == null ? "-" : cleaningSchedule.getDesiredTime().toString("HH:mm"); PdfPCell preferredTimeCell = new PdfPCell(new Paragraph(preferredTime)); String note = cleaningSchedule.getNote() == null ? "-" : cleaningSchedule.getNote(); PdfPCell noteCell = new PdfPCell(new Paragraph(note)); cleaningScheduleTable.addCell(numberCell); cleaningScheduleTable.addCell(roomNumberCell); cleaningScheduleTable.addCell(preferredTimeCell); cleaningScheduleTable.addCell(noteCell); } }
private void putSignature(PdfPTable table, Context context) throws Exception { String uploadOid = (String)context.get("uploadSignatureOid"); if ( StringUtils.isBlank(uploadOid) ) { return; } byte[] imageBytes = UploadSupportUtils.getDataBytes( uploadOid ); if ( null == imageBytes ) { return; } Image signatureImgObj = Image.getInstance( imageBytes ); signatureImgObj.setWidthPercentage(40f); PdfPCell cell = new PdfPCell(); cell.setBorder( Rectangle.NO_BORDER ); cell.addElement(signatureImgObj); table.addCell(cell); }
@Override public void buildWidgetInternal(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedNodeInfoList pEvalNode) { if (pEvalNode.getChildren().size() > 0) { ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes(); pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, LIST_TAG, getListClasses(pEvalNode), getListStyles(pEvalNode)); pSerialiser.pushElementAttributes(lElementAttributes); // The list of forms is generated as a table with one column, with a form set-out per row PdfPTable lListTable = pSerialiser.getElementFactory().getTable(1); pSerialiser.startContainer(ElementContainerFactory.getContainer(lListTable)); addFormRows(pSerialisationContext, pSerialiser, pEvalNode); pSerialiser.endContainer(); if (!pEvalNode.isNested()) { pSerialiser.addTableSpacer(); } pSerialiser.add(lListTable); pSerialiser.popElementAttributes(); } }
/** * Serialise the input field div and content * @param pSerialisationContext * @param pSerialiser * @param pEvalNode */ public void serialise(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EN pEvalNode) { ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes(); pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, INPUT_FIELD_TAG, getInputFieldClasses(), Collections.emptyList()); pSerialiser.pushElementAttributes(lElementAttributes); PdfPTable lTable = pSerialiser.getElementFactory().getTable(1); PdfPCell lCell = pSerialiser.getElementFactory().getCell(); Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph(); pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph)); mInputFieldContent.addContent(pSerialisationContext, pSerialiser, pEvalNode); if (lCellParagraph.isEmpty()) { // If there is no cell content in all cells in a table row, the row will be 0 height - add a zero width space to // ensure that the input field div isn't collapsed like this (the height will be determined from the cell // paragraph font) lCellParagraph.add(ZERO_WIDTH_SPACE_CHARACTER); } pSerialiser.endContainer(); lTable.addCell(lCell); pSerialiser.add(lTable); pSerialiser.popElementAttributes(); }
/** * Create a table with the factory element attributes applied * @return A table with the element attributes applied */ public PdfPTable getTable(int pColumns) { PdfPTable lTable = new PdfPTable(pColumns); // Set split late to false so that tables will be split immediately if they don't fit on a page instead of moving // them to the next page then attempting to split if they don't fit there. iText gets in an infinite loop with the // latter option when content in nested table rows can't split (see EDU-3490 on JIRA). lTable.setSplitLate(false); mElementAttributes.getTableAttributes().getWidthPercentage().ifPresent(pWidthPercentage -> { lTable.setWidthPercentage(pWidthPercentage); lTable.setLockedWidth(false); }); mElementAttributes.getTableAttributes().getFixedWidth().ifPresent(pFixedWidth -> { lTable.setTotalWidth(pFixedWidth); lTable.setLockedWidth(true); }); lTable.setHorizontalAlignment(mElementAttributes.getTableAttributes().getHorizontalAlignment()); lTable.setSpacingBefore(mElementAttributes.getTableAttributes().getSpacingBefore()); lTable.setSpacingAfter(mElementAttributes.getTableAttributes().getSpacingAfter()); lTable.setKeepTogether(mElementAttributes.getTableAttributes().isKeepTogether()); return lTable; }
@Override public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EPN pEvalNode) { ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes(); pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, mTag, Collections.singletonList(pEvalNode.getClasses()), Collections.singletonList(pEvalNode.getStyles())); pSerialiser.pushElementAttributes(lElementAttributes); // Add header/footer content to a table PdfPTable lTable = pSerialiser.getElementFactory().getTable(1); PdfPCell lCell = pSerialiser.getElementFactory().getCell(); Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph(); pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph)); processChildren(pSerialisationContext, pSerialiser, pEvalNode); pSerialiser.endContainer(); lTable.addCell(lCell); // Consume the header/footer content (i.e. set the header or footer content via the serialiser) mHeaderFooterContentConsumer.accept(pSerialiser, new HeaderFooterContent(lTable)); pSerialiser.popElementAttributes(); }
@Override public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedGridPresentationNode pEvalNode) { ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes(); pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, GRID_TAG, Collections.singletonList(pEvalNode.getClasses()), Collections.singletonList(pEvalNode.getStyles())); pSerialiser.pushElementAttributes(lElementAttributes); PdfPTable lTable = pSerialiser.getElementFactory().getTable(FOXGridUtils.getMaxColumns()); pSerialiser.startContainer(ElementContainerFactory.getContainer(lTable)); processChildren(pSerialisationContext, pSerialiser, pEvalNode); pSerialiser.endContainer(); pSerialiser.add(lTable); pSerialiser.popElementAttributes(); }
@Override public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedHtmlPresentationNode pEvalNode) { // Number of columns is required to construct a table, however this is not known until the table contents have been // processed. Serialise to the temp serialiser, and use the number of columns added in the first row of the table // as the number of columns to construct the table PDFTempSerialiser lTempSerialiser = pSerialiser.getTempSerialiser(); processChildren(pSerialisationContext, lTempSerialiser, pEvalNode); PDFTempSerialiserOutput lTempSerialiserOutput = lTempSerialiser.getOutput(); int lColumnCount = getColumnCount(lTempSerialiserOutput.getSerialisedHTMLTags()); if (lColumnCount == 0) { throw new ExInternal("No table cells found under row, cannot create a table with 0 columns"); } PdfPTable lTable = pSerialiser.getElementFactory().getTable(lColumnCount); pSerialiser.startContainer(ElementContainerFactory.getContainer(lTable)); processChildren(pSerialisationContext, pSerialiser, pEvalNode); pSerialiser.endContainer(); pSerialiser.addTableSpacer(); pSerialiser.add(lTable); }
@Override public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedHeadingPresentationNode pEvalNode) { ElementAttributes lElementAttributes = pSerialiser.getInheritedElementAttributes(); pSerialiser.getCSSResolver().resolveStyles(lElementAttributes, HEADING_TAG_PREFIX + pEvalNode.getLevel(), Collections.singletonList(pEvalNode.getClasses()), Collections.singletonList(pEvalNode.getStyles())); pSerialiser.pushElementAttributes(lElementAttributes); // Heading text is contained within a table so that it may be styled as a block-level element (i.e. the same as a // div with borders, background colours etc.) PdfPTable lTable = pSerialiser.getElementFactory().getTable(1); PdfPCell lCell = pSerialiser.getElementFactory().getCell(); Paragraph lCellParagraph = pSerialiser.getElementFactory().getParagraph(); pSerialiser.startContainer(ElementContainerFactory.getContainer(lCell, lCellParagraph)); processChildren(pSerialisationContext, pSerialiser, pEvalNode); pSerialiser.endContainer(); lTable.addCell(lCell); // A table spacer is required so any content before the heading is not overlapped pSerialiser.addTableSpacer(); pSerialiser.add(lTable); pSerialiser.popElementAttributes(); }
@Override public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.BACKGROUNDCANVAS]; float xTransition = position.getLeft() + (position.getRight() - position.getLeft()) * (percent/100.0f); float yTransition = (position.getTop() + position.getBottom()) / 2f; float radius = (position.getRight() - position.getLeft()) * 0.025f; PdfShading axial = PdfShading.simpleAxial(canvas.getPdfWriter(), xTransition - radius, yTransition, xTransition + radius, yTransition, leftColor, rightColor); PdfShadingPattern shading = new PdfShadingPattern(axial); canvas.saveState(); canvas.setShadingFill(shading); canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight()); // canvas.clip(); canvas.fill(); canvas.restoreState(); }
/** * <a href="http://stackoverflow.com/questions/43807931/creating-table-in-pdf-on-last-page-bottom-wrong-official-solution"> * Creating table in pdf on last page bottom (wrong official solution) * </a> * <p> * Helper method for {@link #testCreateTableLikeUser7968180()}. * </p> */ private static PdfPTable createFooterTable() throws DocumentException { int[] columnWidths = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; PdfPTable datatable = new PdfPTable(columnWidths.length); datatable.setKeepTogether(true); datatable.setWidthPercentage(100); datatable.setWidths(columnWidths); datatable.getDefaultCell().setPadding(5); // datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment); // datatable.getDefaultCell().setVerticalAlignment(verticalAlignment); for (int i = 0; i < 100; i++) { datatable.addCell("Přehledová tabulka"); // addCellToTable(datatable, horizontalAlignmentLeft, verticalAlignmentMiddle, "Přehledová tabulka", // columnWidths.length, 1, fontTypeBold, fontSizeRegular, cellLayout_Bottom); } return datatable; }
/** * <a href="http://stackoverflow.com/questions/35699167/double-space-not-being-preserved-in-pdf"> * Double space not being preserved in PDF * </a> * <p> * Indeed, the double space collapses into a single one when copying&pasting from the * generated PDF displayed in Adobe Reader. On the other hand the gap for the double * space is twice as wide as for the single space. So this essentially is a quirk of * copy&paste of Adobe Reader (and some other PDF viewers, too). * </p> */ @Test public void testDoubleSpace() throws DocumentException, IOException { try ( OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "DoubleSpace.pdf"))) { PdfPTable table = new PdfPTable(1); table.getDefaultCell().setBorderWidth(0.5f); table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(new Phrase("SINGLE SPACED", new Font(BaseFont.createFont(), 36))); table.addCell(new Phrase("DOUBLE SPACED", new Font(BaseFont.createFont(), 36))); table.addCell(new Phrase("TRIPLE SPACED", new Font(BaseFont.createFont(), 36))); Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0); PdfWriter.getInstance(pdfDocument, pdfStream); pdfDocument.open(); pdfDocument.add(table); pdfDocument.close(); } }
/** * <a href="http://stackoverflow.com/questions/44005834/changing-rowspans"> * Changing rowspans * </a> * <p> * Helper method of the OP. * </p> * @see #testUseRowspanLikeUser7968180() * @see #testUseRowspanLikeUser7968180Fixed() * @see #createPdf(String) * @see #createPdfFixed(String) */ private static void addCellToTableCzech(PdfPTable table, int horizontalAlignment, int verticalAlignment, String value, int colspan, int rowspan, String fontType, float fontSize) { BaseFont base = null; try { base = BaseFont.createFont(fontType, BaseFont.CP1250, BaseFont.EMBEDDED); } catch (Exception e) { e.printStackTrace(); } Font font = new Font(base, fontSize); PdfPCell cell = new PdfPCell(new Phrase(value, font)); cell.setColspan(colspan); cell.setRowspan(rowspan); cell.setHorizontalAlignment(horizontalAlignment); cell.setVerticalAlignment(verticalAlignment); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); }
public PdfPTable generateFooter() { try { BaseFont baseFont = BaseFont.createFont(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf", BaseFont.IDENTITY_H, true); footerTable = new PdfPTable(1); footerTable.setTotalWidth(440); footerTable.setLockedWidth(true); Font pageNumberFont = new Font(baseFont, 9, Font.BOLD); Paragraph pageNumberP = new Paragraph(titleIndex+"-"+ pageNumber, pageNumberFont); PdfPCell pageNumberCell = new PdfPCell(pageNumberP); pageNumberCell.setBorder(0); pageNumberCell.setPaddingTop(20); footerTable.addCell(pageNumberCell); } catch (Exception e) { e.printStackTrace(); } return footerTable; }
private void generateSectionTitle(PdfPTable table, Data data) throws IOException, DocumentException { if (!this.currentSection.equals(data.mountains)) { currentSection = data.mountains; currentBackgroundColor = backgroundColorGenerator.generate(data); PdfPCell cellSeparator = new PdfPCell(PhraseUtil.phrase(" ")); cellSeparator.setBorder(0); cellSeparator.setPadding(10); cellSeparator.setColspan(4); table.addCell(cellSeparator); PdfPCell cell = new PdfPCell(PhraseUtil.phrase(currentSection, 14, Font.BOLD)); cell.setBorder(0); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(4); cell.setBackgroundColor(currentBackgroundColor); table.addCell(cell); } }
private PdfPTable tableWithPageNumber() throws DocumentException, IOException { PdfPTable innerTable = new PdfPTable(1); innerTable.setWidths(new int[]{1}); innerTable.setWidthPercentage(100); innerTable.setPaddingTop(0); innerTable.addCell(new PageNumberCellGenerator(pageNumber, BackgroundColorGenerator.DEFAULT_BACKGROUND_COLOR) .generateTile()); PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setPadding(0); cell.addElement(innerTable); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); table.setWidths(new int[]{1}); table.setExtendLastRow(true); table.addCell(cell); return table; }
@Override public PdfPTable generatePage() throws DocumentException, IOException, URISyntaxException { PdfPTable table = new PdfPTable(12); // Bootstrap style table.setWidthPercentage(100f); table.setWidths(new int[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); table.setExtendLastRow(true); table.addCell(generateHeaderTitle()); table.addCell(generateHeaderData()); table.addCell(generatePhoto()); table.addCell(generateMapImage()); table.addCell(generateDescription()); table.addCell(generateFooter()); return table; }
private PdfPCell generateFooter() throws IOException, DocumentException, URISyntaxException { PdfPCell cell = new PdfPCell(); cell.setColspan(12); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); cell.setPadding(0); PdfPTable innerTable = new PdfPTable(2); innerTable.getDefaultCell().setBorder(0); innerTable.setWidths(new int[]{1, 1}); innerTable.setWidthPercentage(100); innerTable.addCell(generateStamp()); innerTable.addCell(new PageNumberCellGenerator(pageNumber, backgroundColor).generateTile()); cell.addElement(innerTable); return cell; }
private void writeTree(Document document) throws DocumentException, IOException { if(mTreeReport == null) { return; } Paragraph title = createTitleParagraph(); document.add(title); addSpace(document); PdfPTable titleTable = new PdfPTable(new float[]{1f, 3f}); titleTable.setWidthPercentage(100f); getParagraph(titleTable, MobileRangerApplication.getAppContext().getString(R.string.form_date_title), mTreeReport.getDate(), 0); getParagraph(titleTable, MobileRangerApplication.getAppContext().getString(R.string.form_reporting_employee_title), mTreeReport.getReportingEmployee(), 0); document.add(titleTable); addSpace(document); if(mTreeReport.getLocations() != null && mTreeReport.getLocations().size() > 0) { for (TreeLocation location : mTreeReport.getLocations()) { PdfPTable table = createTableForLocation(location); document.add(table); document.newPage(); } } }
private void createReceiptHeaderAndTextBelow(PdfContentByte cb) throws DocumentException { PdfPTable headerTable = new PdfPTable(1); float[] rows = { 450f }; headerTable.setTotalWidth(rows); headerTable.getDefaultCell() .setBorder(Rectangle.NO_BORDER); headerTable.addCell(new Phrase(new Chunk("Bestätigung über Geldzuwendungen", textFontForReceiptHeader))); headerTable.writeSelectedRows(0, 1, 75f, 625, cb); PdfPTable table = new PdfPTable(1); table.setTotalWidth(rows); table.getDefaultCell() .setBorder(Rectangle.NO_BORDER); table.getDefaultCell() .setLeading(8f, 0); table.addCell(new Phrase(new Chunk("im Sinne des §10b des Einkommensteuergesetzes", textFont))); table.addCell(new Phrase(new Chunk("an eine der in §5 Abs. 1 Nr. 9 des Körperschaftsteuergesetzes bezeichneten", textFont))); table.addCell(new Phrase(new Chunk("Körperschaften, Personenvereinigungen oder Vermögensmassen", textFont))); table.writeSelectedRows(0, 3, 75f, 590, cb); }
private PdfPTable createPriceTable(PdfContentByte cb, Receipt receipt) throws DocumentException { PdfPTable tableForPrices = new PdfPTable(1); float[] rowForTotalPrice = { 250f }; tableForPrices.setTotalWidth(rowForTotalPrice); tableForPrices.getDefaultCell() .setBorder(Rectangle.NO_BORDER); tableForPrices.addCell(new Phrase(new Chunk("Betrag der Zuwendung in Ziffern:", textFont))); tableForPrices.addCell(new Phrase(new Chunk(" ", textFont))); Double totalPrice = 0.0; for (final Cart cart : receipt.getCarts()) { tableForPrices.addCell(new Phrase(new Chunk(cart.getTotalPrice() .toString() + " €", textFontUserData))); totalPrice += cart.getTotalPrice() .doubleValue(); } String formattedPrice = priceFormat.format(totalPrice) .toString(); tableForPrices.addCell(new Phrase(new Chunk("Gesamt: " + formattedPrice + " €", textFontUserData))); return tableForPrices; }
private PdfPTable createDateTable(PdfContentByte cb, Receipt receipt) throws DocumentException { PdfPTable tableForDate = new PdfPTable(1); float[] rowForDate = { 110f }; tableForDate.setTotalWidth(rowForDate); tableForDate.getDefaultCell() .setBorder(Rectangle.NO_BORDER); tableForDate.addCell(new Phrase(new Chunk("Datum der Zuwendung:", textFont))); tableForDate.addCell(new Phrase(new Chunk(" ", textFont))); final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2"), Locale.GERMAN); for (final Cart cart : receipt.getCarts()) { cal.setTimeInMillis(cart.getTimeStamp()); final String date = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR); PdfPCell cell = new PdfPCell(new Phrase(new Chunk(date, textFontUserData))); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cell.setBorder(PdfPCell.NO_BORDER); tableForDate.addCell(cell); } return tableForDate; }
private PdfPTable createLawTable(PdfContentByte cb) throws DocumentException { PdfPTable table = new PdfPTable(1); float[] rows = { 445f }; table.setTotalWidth(rows); table.getDefaultCell() .setBorder(Rectangle.NO_BORDER); table.getDefaultCell() .setLeading(8f, 0); table.addCell(new Phrase(new Chunk("Es handelt sich nicht um den Verzicht auf Erstattung von Aufwendungen.", textFontLawText))); table.addCell(new Phrase(new Chunk("Die Gesellschaft ist wegen Förderung (begünstigter Zweck: Umweltschutz (§52 (2) S. 1 Nr.(n) 8 AO)) durch", textFontLawText))); table.addCell(new Phrase(new Chunk("Bescheinigung des Finanzamt Halle (Saale)-Nord, StNr. 110/108/91169, vom 19.11.2008 ab 01.01.2009", textFontLawText))); table.addCell(new Phrase(new Chunk("als gemeinnützig anerkannt. Letzter Freistellungsbescheid datiert auf den 20.06.2013.", textFontLawText))); table.addCell(new Phrase(new Chunk("Es wird bestätigt, dass die Zuwendung nur zur Förderung des Umweltschutzes verwendet wird.", textFontLawText))); PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(Rectangle.BOTTOM); emptyCell.setFixedHeight(15f); table.addCell(emptyCell); return table; }
public static void createCircleAndText(PdfContentByte cb, String text, float xCoord, float yCoord, float radius, Font textFont, int circleColorRed, int circleColorGreen, int circleColorBlue) throws DocumentException, IOException { cb.saveState(); cb.setRGBColorFill(circleColorRed, circleColorGreen, circleColorBlue); cb.circle(xCoord, yCoord, radius); cb.fill(); cb.stroke(); cb.restoreState(); PdfPTable table = new PdfPTable(1); float[] rows = { 595f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setFixedHeight(radius * 2); table.addCell(new Phrase(new Chunk(text, textFont))); table.writeSelectedRows(0, 1, 0, yCoord + radius, cb); }