List of usage examples for com.itextpdf.text Phrase getChunks
public java.util.List<Chunk> getChunks()
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable buildModelDetailSection(Model model, PdfWriter pdfWriter) throws IOException, BadElementException { final Phrase p = processHtmlCodes(model.getProductNameProcessed(), iTextUtil.getFontModelTitle(), iTextUtil.getFontModelSymbol()); for (Chunk c : p.getChunks()) { c.setAction(new PdfAction(model.getUrl())); }// w ww . j a v a 2s . c om final StringBuilder strAppList = new StringBuilder(); for (String application : model.getApplicationsSorted()) { if (strAppList.length() != 0) { strAppList.append(", "); } strAppList.append(application); } final PdfPTable table = new PdfPTable(1); table.addCell(cell(p)); table.addCell(createRow("Model Number", model.getModelNumber(), null)); table.addCell(createRow("Animal Type", model.getAnimalType(), null)); table.addCell(createRow("Nomenclature", model.getNomenclatureParsed(), null)); table.addCell(createRow("Application(s)", strAppList.toString(), null)); table.addCell(createRow("Health Report", model.getHealthReport(), model.getHealthReport())); table.addCell(createRow("Species", model.getSpecies(), null)); table.addCell(cell(createOrderButton(model))); return table; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPCell createRow(String key, String value, String url) { final Paragraph paragraph = new Paragraph(); paragraph.add(new Chunk(key, iTextUtil.getFontModelKey())); paragraph.add(new Chunk(": ", iTextUtil.getFontModelKey())); if (value == null) { value = ""; }/*from w w w .j a v a 2 s .co m*/ final Phrase valuePhrase = processHtmlCodes(value.trim(), iTextUtil.getFontModelValue(), iTextUtil.getFontModelSymbol()); if (!StringUtils.isEmpty(url)) { for (Chunk chunk : valuePhrase.getChunks()) { chunk.setAction(new PdfAction(url)); } } for (Chunk chunk : valuePhrase.getChunks()) { chunk.setLineHeight(13f); } paragraph.add(valuePhrase); final PdfPCell cell = cell(paragraph); cell.setPaddingBottom(5f); return cell; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] stampTableOfContents(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdf); final PdfStamper stamper = new PdfStamper(reader, bos); // stamp the named destinations for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) { stamper.addNamedDestination("page" + pageNumber, pageNumber, new PdfDestination(PdfDestination.XYZ, 80f, 800f, 0)); }/*from w w w . ja v a2s. c o m*/ // create the table of contents final Chunk tocTitle = new Chunk("TABLE OF CONTENTS", iTextUtil.getFontTocTitle()); int currentTocPage = tableOfContents.getFirstPageOfToc(); int firstTocPage = currentTocPage; PdfContentByte canvas = stamper.getOverContent(currentTocPage); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tocTitle), 55, 470, 0); final List<TocEntry> entriesSorted = tableOfContents.getEntriesSorted(); int tocEntryNumber = 0; for (TocEntry tocEntry : entriesSorted) { if (tocEntry.isIncludedInToc()) { tocEntryNumber++; // take the right TOC page to stamp the TOC entry on (needed for TOC's with multiple pages) if (tocEntryNumber == getNumberOfItemsPerTocPage(0) || (tocEntryNumber > getNumberOfItemsPerTocPage(0) && (tocEntryNumber - getNumberOfItemsPerTocPage(0)) % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage) == 0)) { currentTocPage++; canvas = stamper.getOverContent(currentTocPage); } Font font = iTextUtil.getFontToc(); if (tocEntry.getLevel() == 1) { font = iTextUtil.getFontTocBold(); } final Phrase p = processHtmlCodes(tocEntry.getLevelString() + tocEntry.getName(), font, iTextUtil.getFontTocSymbol()); p.add(new Chunk("", iTextUtil.getFontToc())); if (tocEntry.isShowingPageNumber()) { p.add(new Chunk(new DottedLineSeparator())); p.add(new Chunk(" " + String.valueOf(tocEntry.getFinalPageNumber()), iTextUtil.getFontToc())); } for (Chunk chunk : p.getChunks()) { chunk.setAction(PdfAction.gotoLocalPage("page" + tocEntry.getFinalPageNumber(), false)); } int y; if (tocEntryNumber < getNumberOfItemsPerTocPage(0)) { y = 460 - (16 * (tocEntryNumber % getNumberOfItemsPerTocPage(0))); } else { y = 680 - (16 * ((tocEntryNumber - getNumberOfItemsPerTocPage(0)) % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage))); } final ColumnText ct = new ColumnText(canvas); ct.setSimpleColumn(p, 52, y, 555, 70, 0, Element.ALIGN_JUSTIFIED); ct.go(); } } stamper.close(); reader.close(); return bos.toByteArray(); } }