List of usage examples for com.lowagie.text Chunk Chunk
public Chunk(DrawInterface separator, float tabPosition)
From source file:de.ipbhalle.metfrag.tools.renderer.WritePDFTable.java
License:Open Source License
private void addProperty(Phrase phrase, String text) { phrase.add(new Chunk(text + "\n", FontFactory.getFont(FontFactory.HELVETICA))); }
From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java
License:Apache License
private void renderTextLine(PDFTitlePageLine inTextLine, Font pdffont, com.lowagie.text.Document pdfdoc) throws DocumentException { String content = inTextLine.getContent(); if (content == null) { return;//w w w .j av a 2 s . co m } if ((content != null) && (content.length() > inTextLine.getShortentextlength())) { content = content.substring(0, inTextLine.getShortentextlength()) + "..."; } // show first line Paragraph p1 = new Paragraph(); // check, if content needs to be wrapped if (content.length() > inTextLine.getLinewrap()) { String allwords[] = content.split(" "); int numberofwords = allwords.length; int charsinline = 0; // counter for characters per line StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < numberofwords; i++) { if ((charsinline + (allwords[i].length()) + 1) < inTextLine.getLinewrap()) { // word does fit in line, so add it to paragraph // ch1 = ch1 + allwords[i] + " "; charsinline = charsinline + (allwords[i].length()) + 1; } else { // word does not fit in line; p1 = new Paragraph(stringBuilder.toString(), pdffont); // create a new // paragraph pdfdoc.add(p1); // finally add the current paragraph to the // document stringBuilder.setLength(0); charsinline = (allwords[i].length()); // counter for // characters } stringBuilder.append(allwords[i]); stringBuilder.append(' '); } p1 = new Paragraph(stringBuilder.toString(), pdffont); // create a new paragraph pdfdoc.add(p1); // finally add the current paragraph to the document } else { // content doesn't need to be wrapped p1 = new Paragraph(new Chunk(content, pdffont)); pdfdoc.add(p1); } }
From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java
License:Apache License
/************************************************************************************ * render paragraph into title page/*from ww w . j a va 2s . c om*/ * * @param pdftpp given {@link PDFTitlePageParagraph} to render * @param pdfdoc given {@link com.lowagie.text.Document} where to render * @throws DocumentException ************************************************************************************/ private void renderParagraph(PDFTitlePageParagraph pdftpp, com.lowagie.text.Document pdfdoc) throws DocumentException { String text = pdftpp.getContent(); if (text == null) { text = ""; } int fontstyle = Font.NORMAL; if (pdftpp.getFonttype().equals("bold")) { fontstyle = Font.BOLD; } if (pdftpp.getFonttype().equals("italic")) { fontstyle = Font.ITALIC; } if (pdftpp.getFonttype().equals("bolditalic")) { fontstyle = Font.BOLDITALIC; } if (pdftpp.getFonttype().equals("underline")) { fontstyle = Font.UNDERLINE; } if (pdftpp.getFonttype().equals("strikethru")) { fontstyle = Font.STRIKETHRU; } // create BaseFont for embedding try { Font font = FontFactory.getFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, pdftpp.getFontsize(), fontstyle); Paragraph p2 = new Paragraph(new Chunk(text, font)); // Paragraph p2=new Paragraph(text, // FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)); pdfdoc.add(p2); } catch (Exception e) { LOGGER.error("error occured while generating paragraph for titlepage", e); } }
From source file:de.xirp.report.ReportGenerator.java
License:Open Source License
/** * Returns a default formatted list for the given list type. * /* w w w .j a va2s. c om*/ * @param type * The list type. * @return A default formatted list. */ private static List getList(ListType type) { switch (type) { case BULLET: List list = new List(false, 20); list.setListSymbol(new Chunk("\u2022", FontFactory.getFont( //$NON-NLS-1$ FontFactory.HELVETICA, 12, Font.BOLD))); return list; case DASH: return new List(false, 20); case NUMBER: return new List(true, 20); } return null; }
From source file:fr.aliasource.webmail.server.export.ConversationExporter.java
License:GNU General Public License
@SuppressWarnings("unchecked") private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException { LineSeparator hr = new LineSeparator(); StyleSheet styles = new StyleSheet(); Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL); Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD); Iterator<ClientMessage> it = cm.iterator(); Cell c = null;/*from w w w . jav a 2 s . com*/ while (it.hasNext()) { ClientMessage fwdCm = it.next(); if (isForward) { c = new Cell(); } // Subject (only if isForward) if (isForward) { String subjectText = fwdCm.getSubject(); String dateText = formatDate(fwdCm.getDate()); Chunk subject = new Chunk(subjectText, fbold); Chunk date = new Chunk(dateText, fbold); Paragraph subjectPar = new Paragraph(subject + ", " + date); subjectPar.setIndentationLeft(5.0f); c.add(subjectPar); c.add(Chunk.NEWLINE); } else { String dateText = formatDate(fwdCm.getDate()); Chunk date = new Chunk(dateText, fbold); Paragraph datePar = new Paragraph(date); datePar.setAlignment(Element.ALIGN_RIGHT); d.add(datePar); } // Sender String senderText = formatAddress(fwdCm.getSender()); Chunk sender = new Chunk(senderText, fbold); sender.setTextRise(10.0f); Paragraph senderPar = new Paragraph(sender); if (isForward) { senderPar.setIndentationLeft(5.0f); c.add(senderPar); } else { d.add(senderPar); } appendRecipients(d, c, isForward, "To:", fwdCm.getTo()); appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc()); appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc()); if (isForward) { c.add(Chunk.NEWLINE); } // Body String bodyText = fwdCm.getBody().getCleanHtml(); Paragraph bodyPar = new Paragraph(); bodyPar.setFont(fnormal); if (bodyText != null && !bodyText.isEmpty()) { try { List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles); for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) { Element el = iterator.next(); if (!(el instanceof Image)) { // bodyPar.add(el); if (isForward) { c.add(el); } else { bodyPar.add(el); } } } } catch (Exception e) { logger.warn("Cannot generate pdf from html body use plain text instead", e); // bodyPar.add(fwdCm.getBody().getPlain()); if (isForward) { Chunk t = new Chunk(fwdCm.getBody().getPlain()); t.setFont(fnormal); c.add(t); } else { bodyPar.add(fwdCm.getBody().getPlain()); } } } else { if (isForward) { Chunk t = new Chunk(fwdCm.getBody().getPlain()); t.setFont(fnormal); c.add(t); } else { bodyPar.add(fwdCm.getBody().getPlain()); } } if (isForward) { // c.add(bodyPar); Table t = new Table(1); t.setPadding(5); t.setBackgroundColor(new Color(242, 242, 242)); t.addCell(c); d.add(t); } else { bodyPar.setIndentationLeft(15.0f); d.add(bodyPar); } if (fwdCm.getFwdMessages() != null) { this.exportMessage(fwdCm.getFwdMessages(), d, true); } d.add(hr); } }
From source file:fr.aliasource.webmail.server.export.ConversationExporter.java
License:GNU General Public License
private Chunk getRecipientValue(List<EmailAddress> recipients) { Chunk recipientsChunk = null;/*from w w w . j a v a 2 s . c o m*/ if (recipients != null && !recipients.isEmpty()) { StringBuilder recipientsText = new StringBuilder(200); formatRecipients(recipientsText, recipients, false); recipientsChunk = new Chunk(recipientsText.toString(), new Font(Font.HELVETICA, 9)); recipientsChunk.setTextRise(15.0f); } return recipientsChunk; }
From source file:fr.aliasource.webmail.server.export.ConversationExporter.java
License:GNU General Public License
private Chunk getRecipientLabel(String label) { Chunk recipientsLabel = new Chunk(label, new Font(Font.HELVETICA, 10, Font.BOLD)); recipientsLabel.setTextRise(15.0f);//from www . j av a2 s . c o m return recipientsLabel; }
From source file:fr.aliasource.webmail.server.export.ConversationPdfEventHandler.java
License:GNU General Public License
/** * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, * com.lowagie.text.Document)// w ww. j a va 2s .co m */ public void onOpenDocument(PdfWriter writer, Document document) { try { headerImage = Image.getInstance(getLogoUrl()); table = new PdfPTable(new float[] { 1f, 2f }); Phrase p = new Phrase(); Chunk ck = new Chunk(cr.getTitle(), new Font(Font.HELVETICA, 16, Font.BOLD)); p.add(ck); p.add(Chunk.NEWLINE); ck = new Chunk(ConversationExporter.formatName(account), new Font(Font.HELVETICA, 12, Font.BOLDITALIC)); p.add(ck); p.add(Chunk.NEWLINE); ck = new Chunk(cm.length + " messages", new Font(Font.HELVETICA, 10)); p.add(ck); table.getDefaultCell().setBorder(0); table.addCell(new Phrase(new Chunk(headerImage, 0, 0))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(p); // initialization of the template tpl = writer.getDirectContent().createTemplate(100, 100); tpl.setBoundingBox(new Rectangle(-20, -20, 100, 100)); // initialization of the font helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableHeading.java
License:Open Source License
private Chunk formatNumber(StyleListProperties listProperties, int value) { Chunk symbol = new Chunk("", getFont()); StyleTextProperties textProperties = listProperties.getTextProperties(); if (textProperties != null) { Font font = textProperties.getFont(); if (font != null) { symbol.setFont(font);/*from w w w . j a v a 2 s .c o m*/ } } StyleNumFormat numFormat = listProperties.getNumFormat(); if (numFormat != null) { StringBuilder sbuf = new StringBuilder(); // num-prefix String numPrefix = listProperties.getNumPrefix(); if (numPrefix != null) { sbuf.append(numPrefix); } // number if (numFormat.isAlphabetical()) { sbuf.append(RomanAlphabetFactory.getString(value, numFormat.isLowercase())); } else if (numFormat.isRoman()) { sbuf.append(RomanNumberFactory.getString(value, numFormat.isLowercase())); } else { sbuf.append(value); } // num-suffix String numSuffix = listProperties.getNumSuffix(); if (numSuffix != null) { sbuf.append(numSuffix); } symbol.append(sbuf.toString()); } return symbol; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java
License:Open Source License
public static Chunk createAdjustedChunk(String content, Font font, float lineHeight, boolean lineHeightProportional) { // adjust chunk attributes like text rise // use StylableParagraph mechanism StylableParagraph p = new StylableParagraph(null, null); p.setFont(font);/*from w w w . ja v a 2 s .co m*/ if (lineHeightProportional) { p.setMultipliedLeading(lineHeight); } else { p.setLeading(lineHeight); } p.addElement(new Chunk(content, font)); p.getElement(); // post-processing here return (Chunk) p.getChunks().get(0); }