List of usage examples for com.itextpdf.text Chunk setFont
public void setFont(final Font font)
Chunk
. From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] personalize(byte[] pdf, Contact contact, 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 some text on first page PdfContentByte text = stamper.getOverContent(1); text.beginText();/* w w w .j av a2s .com*/ text.setColorFill(iTextUtil.getFontCoverText().getColor()); text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1, text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2, text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0); text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(), text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0); text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor()); text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(), iTextUtil.getFontCoverPricingguide().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3, text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0); text.setColorFill(iTextUtil.getFontCoverYear().getColor()); text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4, text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0); text.endText(); // stamp some text on first page of the table of contents page final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray( pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword())); final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0, logoImage.getHeight() / resizeRatio, 59, 615); text = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); text.beginText(); text.setColorFill(iTextUtil.getFontPersonalization().getColor()); text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(), iTextUtil.getFontPersonalization().getSize()); text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0); text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0); // set company name if (!StringUtils.isEmpty(contact.getCompany())) { text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0); text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 624, 0); } else { text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 643, 0); } text.endText(); final ColumnText ct = new ColumnText(tocContent); ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575)); final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null); final Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); for (Element element : elements) { for (Chunk chunk : element.getChunks()) { chunk.setFont(iTextUtil.getFontDisclaimer()); } p.add(element); } ct.addElement(p); ct.go(); stamper.close(); reader.close(); return bos.toByteArray(); } }
From source file:com.coast.PDFPrinter_iText.java
License:Apache License
/** * Prints the document at its actual size. This is the recommended way to print. *//*from w w w. j a va2 s .c o m*/ private static void print(String pFileName, String pPayload) throws IOException, Exception { Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(pFileName)); // step 3 document.open(); // step 4 String _dateTime = LocalDateTime.now().toString(); document.addTitle("List of All Customers & their assets as of: " + _dateTime); document.addCreationDate(); document.addSubject("List of All Customers & their assets as of: " + _dateTime); Font _font = new Font(); _font.setColor(BaseColor.BLUE); _font.setStyle(Font.BOLD); _font.setSize(15); Chunk _chunk = new Chunk("List of All Customers & their assets as of: " + _dateTime); _chunk.setFont(_font); Paragraph _header = new Paragraph(); _header.add(_chunk); document.add(_header); document.add(new Paragraph(pPayload)); // step 5 document.close(); }
From source file:com.github.wolfposd.imsqti2pdf.HeaderFooter.java
License:Open Source License
public HeaderFooter(int maximumPageNumber) { _maximumPageNumber = maximumPageNumber; Chunk c = new Chunk("" + (char) 229); c.setFont(new Font(FontFamily.SYMBOL, 28)); _sumSymbol = new Phrase(c); }
From source file:com.github.wolfposd.imsqti2pdf.HeaderFooter.java
License:Open Source License
private void pageNumberFooter(PdfWriter writer, Rectangle rect) { Chunk c = new Chunk( String.format(LocaleStrings.getString("page"), writer.getPageNumber(), _maximumPageNumber)); c.setFont(new Font(FontFamily.HELVETICA, 10)); Phrase pagephrase = new Phrase(c); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, pagephrase, rect.getRight() - 60, rect.getBottom() - 30, 0); }
From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java
License:Open Source License
private Chunk getQuestionNumberChunk(Font f, int number) { Chunk c = new Chunk((number + 1) + ". "); Font ff = new Font(f); ff.setStyle(Font.BOLD);/*ww w . ja va2s.c o m*/ c.setFont(ff); return c; }
From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java
License:Open Source License
private Chunk getPointsChunk(Font f, Question question) { int points = (int) question.getPointsPerAnswer(); String punkteText = LocaleStrings.getString(points == 1 ? "point" : "points"); String text;/*from w ww . j a v a 2s. c o m*/ if (question.basetype == BaseType.STRING) { text = " " + LocaleStrings.getString("maximum"); //(maximal %d %s) text = String.format(text, points, punkteText); } else { if (question.type.equalsIgnoreCase("single")) { text = " " + LocaleStrings.getString("correctAnswer"); //" (1 richtige Antwort"; if (points == 1) { text += ")"; } else { text += ", %d %s)"; text = String.format(text, points, punkteText); } } else { // MUTLIPLE text = " " + LocaleStrings.getString("perCorrectAnswer"); //(%d %s pro richtige Antwort)"; text = String.format(text, points, punkteText); } } Chunk c = new Chunk(text); Font ff = new Font(f); ff.setSize(OVERALLFONTSIZE); c.setFont(ff); return c; }
From source file:com.vectorprint.report.itext.style.stylers.Font.java
License:Open Source License
@Override public <E> E style(E text, Object data) throws VectorPrintException { com.itextpdf.text.Font f = getFont(); if (text instanceof Phrase) { ((Phrase) text).setFont(f);//from w w w . j a v a2 s .co m } else if (text instanceof Chunk) { ((Chunk) text).setFont(f); } if (text instanceof TextElementArray) { for (Object o : ((TextElementArray) text).getChunks()) { Chunk c = (Chunk) o; if (c.getFont().getFamily() == com.itextpdf.text.Font.FontFamily.UNDEFINED) { c.setFont(f); } } } return text; }
From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java
License:Open Source License
/** * /*from ww w. j a v a2s .co m*/ * @return a PDF paragraph cell containing a text encoding of the fields in this set. */ public PdfPCell toPDFCell(LabelDefinitionType printDefinition) { PdfPCell cell = new PdfPCell(); ; if (printDefinition.getTextOrentation().toString().toLowerCase() .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) { log.debug("Print orientation of text is Vertical"); cell.setRotation(90); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); cell.setNoWrap(false); int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1; Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); boolean added = false; boolean hasContent = false; for (int i = 0; i < fields.size(); i++) { log.debug(i); if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) { if (!higher.isEmpty()) { log.debug(higher.getContent()); cell.addElement(higher); } leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1; higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); added = false; hasContent = false; } log.debug(fields.get(i).getTextField().getText().trim()); Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim()); if (fields.get(i).getField().isUseItalic()) { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC)); } else { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); } if (!chunk.isEmpty()) { hasContent = true; higher.add(chunk); log.debug(fields.get(i).getField().getSuffix()); if (fields.get(i).getField().getSuffix() != null && fields.get(i).getField().getSuffix().length() > 0) { higher.add(new Chunk(fields.get(i).getField().getSuffix())); } if (fields.get(i).getTextField().getText().trim().length() > 0) { // add a trailing space as a separator if there was something to separate. higher.add(new Chunk(" ")); } } } if (!added) { log.debug(higher.getContent()); cell.addElement(higher); } String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT); if (extraText != null && extraText.length() > 0) { log.debug(extraText); cell.addElement(new Chunk(extraText)); } return cell; }
From source file:facturacion.pdf.FacturaPdf.java
@SuppressWarnings("unused") private Paragraph getHeader(String header) { Paragraph paragraph = new Paragraph(); Chunk chunk = new Chunk(); paragraph.setAlignment(Element.ALIGN_CENTER); chunk.append(header + getCurrentDateTime() + "\n"); chunk.setFont(fontBold); paragraph.add(chunk);// w ww . j ava2s . co m return paragraph; }
From source file:facturacion.pdf.FacturaPdf.java
private Paragraph getInformation(String informacion) { Paragraph paragraph = new Paragraph(); Chunk chunk = new Chunk(); paragraph.setAlignment(Element.ALIGN_CENTER); chunk.append(informacion);/*from w ww . j av a 2s. c om*/ chunk.setFont(fontNormal); paragraph.add(chunk); return paragraph; }