@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 PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){ PdfPCell cell=new PdfPCell(); cell.setPadding(0); cell.setBorder(Rectangle.NO_BORDER); Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline()); String fontColor=phf.getForecolor(); if(StringUtils.isNotEmpty(fontColor)){ String[] color=fontColor.split(","); font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2])); } Paragraph graph=new Paragraph(text,font); cell.setPhrase(graph); switch(type){ case 1: cell.setHorizontalAlignment(Element.ALIGN_LEFT); break; case 2: cell.setHorizontalAlignment(Element.ALIGN_CENTER); break; case 3: cell.setHorizontalAlignment(Element.ALIGN_RIGHT); break; } cell.setVerticalAlignment(Element.ALIGN_MIDDLE); return cell; }
public PdfPCell getFillCell(){ PdfPCell fillCell = new PdfPCell(); fillCell.setBorderWidth( 0f ); fillCell.setLeft(0); fillCell.setTop(0); fillCell.setRight( 0 ); fillCell.setBottom( 0 ); fillCell.setUseAscender( true ); fillCell.setIndent(0); fillCell.setHorizontalAlignment( Element.ALIGN_LEFT ); fillCell.setVerticalAlignment( Element.ALIGN_BOTTOM ); fillCell.setPaddingLeft( 0f); fillCell.setPaddingBottom(0f); fillCell.setPaddingRight(0f ); fillCell.setPaddingTop( 0f ); fillCell.setBorder( 0 ); renderEmptyCell(fillCell); return fillCell; }
private static PdfPCell getPhotoCell(BufferedImage bufferedImage, float scalePercent, boolean isHorizontallyCentered) throws BadElementException, IOException { Image jpeg = Image.getInstance(bufferedImage, null); jpeg.scalePercent(scalePercent); jpeg.setAlignment(Image.MIDDLE); PdfPCell photoCell = new PdfPCell(jpeg); photoCell.setBorder(0); if (isHorizontallyCentered) { photoCell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { photoCell.setHorizontalAlignment(Element.ALIGN_RIGHT); } photoCell.setVerticalAlignment(Element.ALIGN_TOP); int height = (int) Math.ceil(bufferedImage.getHeight() * scalePercent / 100); photoCell.setFixedHeight(height); return photoCell; }
private Phrase funcaoTitulo(int i) { String txt; Font fontcabecatable = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f ); switch (i) { case 0:txt="Nr. Factura";break; case 1:txt="Nome do Segurado"; break; case 2:txt="Prémio";break; case 3:txt="Imposto 6%";break; case 4:txt="Imposto 5%";break; case 5:txt="FGA 2.6%";break; default:txt="TOTAL";break; } a=com.itextpdf.text.Element.ALIGN_CENTER; Phrase rt = new Phrase(txt,fontcabecatable); return rt; }
/** * 根据URL提前blog的基本信息,返回结果>>:[主题 ,分类,日期,内容]等. * * @param blogURL * @return * @throws Exception */ public static String[] extractBlogInfo(String blogURL) throws Exception { String[] info = new String[4]; org.jsoup.nodes.Document doc = Jsoup.connect(blogURL).get(); org.jsoup.nodes.Element e_title = doc.select("h2.title").first(); info[0] = e_title.text(); org.jsoup.nodes.Element e_category = doc.select("a[rel=category tag]") .first(); info[1] = e_category.attr("href").replace("http://www.micmiu.com/", ""); org.jsoup.nodes.Element e_date = doc.select("span.post-info-date") .first(); String dateStr = e_date.text().split("日期")[1].trim(); info[2] = dateStr; org.jsoup.nodes.Element entry = doc.select("div.entry").first(); info[3] = formatContentTag(entry); return info; }
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); } }
private void addTitlePage(Document document) throws DocumentException { addEmptyLine(document, 5); Paragraph title = new Paragraph("Data Dictionary by Arrah technology"); title.setAlignment(Element.ALIGN_CENTER); document.add(title); addEmptyLine(document, 1); Paragraph url = new Paragraph("http://sourceforge.net/projects/dataquality/"); url.setAlignment(Element.ALIGN_CENTER); document.add(url); addEmptyLine(document, 3); Paragraph rtime = new Paragraph("Report generated on: " + new Date()); rtime.setAlignment(Element.ALIGN_CENTER); document.add(rtime); document.newPage(); }
/** * The OP's original code transformed into Java */ void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException { Date today = new Date(); PdfReader reader = new PdfReader(source); PdfStamper stamper = new PdfStamper(reader, target); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED); int tSize = 24; String mark = "DRAFT " + today; int angle = 45; float height = reader.getPageSizeWithRotation(1).getHeight()/2; float width = reader.getPageSizeWithRotation(1).getWidth()/2; PdfContentByte cb = stamper.getOverContent(1); cb.setColorFill(new BaseColor(255,200,200)); cb.setFontAndSize(bf, tSize); cb.beginText(); cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle); cb.endText(); stamper.close(); reader.close(); }
/** * The OP's code transformed into Java changed with the work-around. */ void stampTextChanged(InputStream source, OutputStream target) throws DocumentException, IOException { Date today = new Date(); PdfReader reader = new PdfReader(source); PdfStamper stamper = new PdfStamper(reader, target); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED); int tSize = 24; String mark = "DRAFT " + today; int angle = 45; float height = reader.getPageSizeWithRotation(1).getHeight()/2; float width = reader.getPageSizeWithRotation(1).getWidth()/2; PdfContentByte cb = stamper.getOverContent(1); cb.setFontAndSize(bf, tSize); cb.beginText(); cb.setColorFill(new BaseColor(255,200,200)); cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle); cb.endText(); stamper.close(); reader.close(); }
/** * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment"> * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment * </a> * <p> * Indeed, the coordinates do not line up. The y coordinate of * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)} * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds * the text to come. * </p> */ @Test public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf"))); document.open(); Font fontQouteItems = new Font(BaseFont.createFont(), 12); PdfContentByte canvas = writer.getDirectContent(); // Item Number ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0); // Estimated Qty ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0); // Item Description ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping ct.setSimpleColumn(new Rectangle(193, 070, 390, 450)); ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems)); ct.go(); document.close(); }
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; }
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; }
public ProSheet(TridasObject o, TridasDerivedSeries master, ArrayListModel<org.tellervo.desktop.sample.Element> elements){ // Find all series for an object SearchParameters sampparam = new SearchParameters(SearchReturnObject.OBJECT); sampparam.addSearchConstraint(SearchParameterName.OBJECTID, SearchOperator.EQUALS, o.getIdentifier().getValue().toString()); // we want a series returned here EntitySearchResource<TridasObject> searchResource = new EntitySearchResource<TridasObject>(sampparam); searchResource.setProperty(TellervoResourceProperties.ENTITY_REQUEST_FORMAT, TellervoRequestFormat.COMPREHENSIVE); TellervoResourceAccessDialog dialog = new TellervoResourceAccessDialog(searchResource); searchResource.query(); dialog.setVisible(true); List<TridasObject> objlist = searchResource.getAssociatedResult(); if(objlist.size()>0) { this.o = (TridasObjectEx) objlist.get(0); } this.elements = elements; }
private Paragraph getObjectDescription() { Paragraph p = new Paragraph(); p.setLeading(0, 1.2f); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setSpacingAfter(10); p.setSpacingBefore(50); if(o.getDescription()!=null){ p.add(new Chunk(o.getDescription(), bodyFont)); } else{ p.add(new Chunk("No description recorded", bodyFont)); } return p; }
private Paragraph getObjectComments() { Paragraph p = new Paragraph(); p.setLeading(0, 1.2f); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setSpacingAfter(10); if(o.getComments()!=null){ p.add(new Chunk("Notes: ", commentFont)); p.add(new Chunk(o.getComments(), commentFont)); } return p; }
/** * Generates a document with a header containing Page x of y and with a Watermark on every page. * @param args no arguments needed */ public static void main(String args[]) { try { // step 1: creating the document Document doc = new Document(PageSize.A4, 50, 50, 100, 72); // step 2: creating the writer PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("pageNumbersWatermark.pdf")); // step 3: initialisations + opening the document writer.setPageEvent(new PageNumbersWatermark()); doc.open(); // step 4: adding content String text = "some padding text "; for (int k = 0; k < 10; ++k) text += text; Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); doc.add(p); // step 5: closing the document doc.close(); } catch ( Exception e ) { e.printStackTrace(); } }
/** * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ public void onStartPage(PdfWriter writer, Document document) { if (writer.getPageNumber() < 3) { PdfContentByte cb = writer.getDirectContentUnder(); cb.saveState(); cb.setColorFill(BaseColor.PINK); cb.beginText(); cb.setFontAndSize(helv, 48); cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45); cb.endText(); cb.restoreState(); } }
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); }
private void addIndividuelleEinschaetzung(Chapter chapterLEB, PdfWriter writer) throws DocumentException, PdfFormatierungsException { if (!lebData.getIndividuelleEinschaetzung().isEmpty()) { sectionCount += 1; breakHurenkind(writer); breakSchusterjunge(writer); Paragraph paragraphIndividuelleEinschaetzung = new Paragraph(); Section individuelleEinschaetzungsTextSection = chapterLEB.addSection(paragraphIndividuelleEinschaetzung); individuelleEinschaetzungsTextSection.setNumberDepth(0); Paragraph schuelereinschaetzungParapgraph = new Paragraph(lebData.getIndividuelleEinschaetzung().replace('\t', '\0'), standardTextFont); schuelereinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED); schuelereinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor); individuelleEinschaetzungsTextSection.add(schuelereinschaetzungParapgraph); document.add(individuelleEinschaetzungsTextSection); document.add(getKlassenlehrerunterschrift(chapterLEB)); alertHurenkind(writer); insertDummyLineIfNecessary(writer); } }
private void addKlassenbrief(Chapter chapterLEB, PdfWriter writer) throws DocumentException, PdfFormatierungsException { if (!lebData.getKlassenbrief().isEmpty()) { sectionCount += 1; breakSchusterjunge(writer); Paragraph paragraphKlassenbrief = new Paragraph(); Section klassenbriefSection = chapterLEB.addSection(paragraphKlassenbrief); klassenbriefSection.setNumberDepth(0); Paragraph klasseneinschaetzungParapgraph = new Paragraph(lebData.getKlassenbrief().replace('\t', '\0'), standardTextFont); klasseneinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED); klasseneinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor); klasseneinschaetzungParapgraph.add(Chunk.NEWLINE); if (lebData.getIndividuelleEinschaetzung().isEmpty()) { klassenbriefSection.add(klasseneinschaetzungParapgraph); document.add(klassenbriefSection); document.add(getKlassenlehrerunterschrift(chapterLEB)); } else { klasseneinschaetzungParapgraph.add(Chunk.NEWLINE); klassenbriefSection.add(klasseneinschaetzungParapgraph); document.add(klassenbriefSection); } alertLonelyHeader(writer); insertDummyLineIfNecessary(writer); } }
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(527); table.setWidthPercentage(100); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(105f); table.getDefaultCell().setBorderWidth(0); table.addCell(""); table.addCell(csmLogoImage); table.writeSelectedRows(0, -1, 100, 840, writer.getDirectContent()); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(lebData.getSchuelername() + " " + lebData.getSchuljahr() + " " + lebData.getSchulhalbjahr().getId() + " Seite " + document.getPageNumber(), fusszeilenFont), 100, 75, 0); }
public static PdfPTable buildFooterVersetzungsvermerkLine(String versetzungsvermerk, Font footerFont) throws DocumentException { PdfPCell labelCell = new PdfPCell(new Phrase("Versetzungsvermerk", footerFont)); labelCell.setBorder(Rectangle.BOTTOM); labelCell.setBorderWidth(1f); PdfPCell nameCell = new PdfPCell(new Phrase(versetzungsvermerk, footerFont)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.addCell(labelCell); table.addCell(nameCell); table.setWidths(new float[] {0.3f, 0.7f}); return table; }
public static PdfPTable buildFooterDatumLine(String datumString, Font footerFont) throws DocumentException { PdfPCell labelCell = new PdfPCell(new Phrase("Datum", footerFont)); labelCell.setBorder(Rectangle.BOTTOM); labelCell.setBorderWidth(1f); PdfPCell nameCell = new PdfPCell(new Phrase(datumString, footerFont)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.addCell(labelCell); table.addCell(nameCell); table.setWidths(new float[] {0.3f, 0.7f}); return table; }
public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont)); leftCell.setBorder(Rectangle.NO_BORDER); leftCell.setBorderWidth(1f); PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont)); centerCell.setBorder(Rectangle.NO_BORDER); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont)); rightCell.setBorder(Rectangle.NO_BORDER); rightCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(3); table.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] {0.3f, 0.3f, 0.3f}); return table; }
public static PdfPTable buildFooterUnterschriftenLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("Schulleiter(in)", footerFont)); leftCell.setBorder(Rectangle.TOP); leftCell.setBorderWidth(1f); leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.TOP); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont)); rightCell.setBorder(Rectangle.TOP); rightCell.setBorderWidth(1f); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] {0.3f, 0.3f, 0.3f}); return table; }
public static PdfPTable buildFooterHalbjahrDatumLine(String datumString, Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase(datumString, footerFont)); leftCell.setBorder(Rectangle.NO_BORDER); leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.NO_BORDER); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont)); rightCell.setBorder(Rectangle.NO_BORDER); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] {0.3f, 0.3f, 0.3f}); return table; }
public static PdfPTable buildFooterHalbjahrDatumKlassenleiterLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("Datum", footerFont)); leftCell.setBorder(Rectangle.TOP); leftCell.setBorderWidth(1f); leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.TOP); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont)); rightCell.setBorder(Rectangle.TOP); rightCell.setBorderWidth(1f); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] {0.3f, 0.3f, 0.3f}); return table; }
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) { if (pageInfos.getRawPageNumber() == 1 && !footerOnFirstPage) return; if (drawLine) { BaseColor lineColor = styles.getColorOrDefault(HEADER_LINE_COLOR); canvas.saveState(); canvas.setColorStroke(lineColor); canvas.setLineWidth(1.2f); canvas.moveTo(rect.getLeft(), rect.getBottom() - 6); canvas.lineTo(rect.getRight(), rect.getBottom() - 6); canvas.stroke(); canvas.restoreState(); } float bottom = rect.getBottom() - 20; Phrase footer = footerText(pageInfos); if (footer != null) { showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0); } Font footerFont = styles.getFontOrDefault(FOOTER_FONT); Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont); showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0); }
@Override public void process(int level, Node node, InvocationContext context) { List<Element> subs = context.collectChildren(level, node); Paragraph p = new Paragraph(); for (Element sub : subs) { p.add(discardNewline(sub)); } KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(PARAGRAPH_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(PARAGRAPH_SPACING_AFTER).or(5f); p.setSpacingBefore(spacingBefore); p.setSpacingAfter(spacingAfter); applyAttributes(context, p); context.append(p); }
@Override public void process(int level, Node node, InvocationContext context) { VerbatimNode vNode = (VerbatimNode) node; SourceCode code = convertToSourceCode(vNode); Attributes attributes = context.peekAttributes(level); applyAttributes(code, attributes); ITextContext iTextContext = context.iTextContext(); List<Element> elements = iTextContext.emitButCollectElements(code); for (Element element : elements) { ITextUtils.applyAttributes(element, attributes); context.append(element); } }
@SuppressWarnings("unchecked") @Override public void process(int level, Node node, InvocationContext context) { TreeNavigation nav = context.treeNavigation(); boolean isHeaderRow = nav.ancestorTreeMatches(TableRowNode.class, TableHeaderNode.class); List<Element> elements = context.collectChildren(level, node); TableInfos tableInfos = context.peekTable(); PdfPTable table = tableInfos.getTable(); int col = 0; for (Element element : elements) { PdfPCell cell = (PdfPCell) element; cell.setHorizontalAlignment(tableInfos.columnAlignment(col)); table.addCell(cell); col += cell.getColspan(); } table.completeRow(); if (isHeaderRow) { int headerRows = table.getHeaderRows(); table.setHeaderRows(headerRows + 1); } }
@SuppressWarnings("unchecked") @Override public void process(int level, Node node, InvocationContext context) { TreeNavigation nav = context.treeNavigation(); boolean isHeaderCell = nav.ancestorTreeMatches(TableCellNode.class, TableRowNode.class, TableHeaderNode.class); CellStyler cellStyler = context.peekCellStyler(); context.pushFont(cellStyler.cellFont()); List<Element> elements = context.collectChildren(level, node); context.popFont(); Phrase phrase = new Phrase(); phrase.addAll(elements); int colspan = ((TableCellNode) node).getColSpan(); PdfPCell cell = isHeaderCell ? headerCell(phrase) : new PdfPCell(phrase); cell.setColspan(colspan); cellStyler.applyStyle(cell); context.append(cell); }
@Override public void process(int level, Node node, InvocationContext context) { List<Element> subs = context.collectChildren(level, node); com.itextpdf.text.List orderedList = new com.itextpdf.text.List(com.itextpdf.text.List.ORDERED); for (Element sub : subs) { if (!orderedList.add(sub)) { // wrap it ListItem listItem = new ListItem(); listItem.add(sub); orderedList.add(listItem); } } KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(ORDERED_LIST_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(ORDERED_LIST_SPACING_AFTER).or(5f); Paragraph p = new Paragraph(); p.add(orderedList); p.setSpacingBefore(spacingBefore); p.setSpacingAfter(spacingAfter); context.append(p); }