List of usage examples for com.lowagie.text Phrase add
public boolean add(Object o)
Chunk
, Anchor
or another Phrase
to this Phrase
. From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) { Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont); Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1)); com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); for (AttributeVO attr : attrs) { if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue())) continue; Phrase phrase = new Phrase(); phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont)); String v = attr.getAttributeValue(); if (v == null) v = ""; phrase.add(new Chunk(": " + v, normalFont)); list.add(new ListItem(phrase)); }/* ww w .ja v a 2s .co m*/ subsection.add(list); }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printVariablesPdf(Chapter chapter, List<VariableVO> variables, int parentLevel) { Paragraph sTitle = new Paragraph("Process Variables", sectionFont); Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1)); com.lowagie.text.List list = new com.lowagie.text.List(false, false, 10.0f); for (VariableVO var : variables) { Phrase phrase = new Phrase(); phrase.add(new Chunk(var.getVariableName(), fixedWidthFont)); String v = var.getVariableType(); if (var.getDescription() != null) v += " (" + var.getDescription() + ")"; phrase.add(new Chunk(": " + v + "\n", normalFont)); list.add(new ListItem(phrase)); }//from ww w .j a va2s . c o m section.add(list); }
From source file:com.develog.utils.report.engine.export.JRPdfExporter.java
License:Open Source License
/** * */// w w w .j a va 2s. co m protected Phrase getPhrase(JRStyledText styledText, Chunk hyperlinkInfoChunk) throws JRException, DocumentException, IOException { Phrase phrase = new Phrase(); String text = styledText.getText(); int runLimit = 0; AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator(); while (runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) { Chunk chunk = getChunk(iterator.getAttributes(), text.substring(iterator.getIndex(), runLimit)); chunk.setMarkupAttributes(hyperlinkInfoChunk.getMarkupAttributes()); phrase.add(chunk); iterator.setIndex(runLimit); } return phrase; }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
License:Open Source License
/** * *//*from w ww . ja v a 2s . c o m*/ protected Phrase getPhrase(AttributedString as, String text, JRPrintText textElement) { Phrase phrase = new Phrase(); int runLimit = 0; AttributedCharacterIterator iterator = as.getIterator(); Locale locale = getTextLocale(textElement); boolean firstChunk = true; while (runLimit < text.length() && (runLimit = iterator.getRunLimit()) <= text.length()) { Map<Attribute, Object> attributes = iterator.getAttributes(); Chunk chunk = getChunk(attributes, text.substring(iterator.getIndex(), runLimit), locale); if (firstChunk) { // only set anchor + bookmark for the first chunk in the text setAnchor(chunk, textElement, textElement); } JRPrintHyperlink hyperlink = textElement; if (hyperlink.getHyperlinkTypeValue() == HyperlinkTypeEnum.NONE) { hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK); } setHyperlinkInfo(chunk, hyperlink); phrase.add(chunk); iterator.setIndex(runLimit); firstChunk = false; } return phrase; }
From source file:com.efficio.fieldbook.web.demo.controller.BarCodeController.java
License:Open Source License
/** * Upload file.//from w ww .j a v a2 s . c o m * * @param uploadForm the upload form * @param result the result * @param model the model * @return the string */ @ResponseBody @RequestMapping(method = RequestMethod.POST) public String uploadFile(@ModelAttribute("barCodeForm") BarCodeForm barCodeForm, BindingResult result, Model model, HttpServletResponse response) { int width = 60; int height = 48; String delimeter = "|"; StringBuilder barCodeString = new StringBuilder(); barCodeString.append(barCodeForm.getEntryNo()).append(delimeter).append(barCodeForm.getGid()) .append(delimeter).append(barCodeForm.getDesignation()).append(delimeter) .append(barCodeForm.getName()).append(delimeter).append(barCodeForm.getRep()).append(delimeter) .append(barCodeForm.getColumn()).append(delimeter).append(barCodeForm.getRange()); BitMatrix bitMatrix; try { String barCodeLabel = "3|SM114-1A-1-1-1B"; //barCodeLabel = barCodeString.toString(); bitMatrix = new Code128Writer().encode(barCodeLabel, BarcodeFormat.CODE_128, width, height, null); String imageLocation = Math.random() + ".png"; //"src/test/resources/barcode/zxing_barcode.png"; MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File(imageLocation))); String currentDate = DateUtil.getCurrentDate(); String fileName = currentDate + ".doc"; response.setHeader("Content-disposition", "attachment; filename=" + fileName); File xls = new File(fileName); // the selected name + current date FileInputStream in; try { Image image1 = Image.getInstance(imageLocation); //image1.scalePercent(50); //image1.setAbsolutePosition(10f, 10f); //document.add(image1); //PageSize.A4 Document document = new Document(PageSize.LETTER); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 // we'll use 4 images in this example /* Image[] img = { Image.getInstance(String.format(RESOURCE, "0120903")), Image.getInstance(String.format(RESOURCE, "0290334")), Image.getInstance(String.format(RESOURCE, "0376994")), Image.getInstance(String.format(RESOURCE, "0348150")) };*/ PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100); // first movie table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); Phrase phrase = new Phrase(); phrase.add("Entry # " + barCodeForm.getEntryNo()); phrase.add("\n"); phrase.add("Designation " + barCodeForm.getDesignation()); phrase.add("\n"); phrase.add("Rep " + barCodeForm.getRep()); phrase.add("\n"); phrase.add("GID " + barCodeForm.getGid()); phrase.add("\n"); phrase.add("Trial/Nursery Name " + barCodeForm.getName()); phrase.add("\n"); phrase.add("Col " + barCodeForm.getColumn()); phrase.add("\n"); phrase.add("Range " + barCodeForm.getRange()); table.addCell(phrase); // we add the image with addCell() table.addCell(image1); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell("X-Men: The Last Stand"); // we add the image with addCell() table.addCell(image1); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell("X-Men: The Last Stand"); // we add the image with addCell() table.addCell(image1); // we complete the table (otherwise the last row won't be rendered) table.completeRow(); document.add(table); document.close(); in = new FileInputStream(xls); OutputStream out = response.getOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; // use bigger if you want int length = 0; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } catch (FileNotFoundException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } return ""; } catch (WriterException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } return show(barCodeForm, model); }
From source file:com.geek.tutorial.itext.text.Paragraph_Example.java
License:Open Source License
public Paragraph_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf")); document.open();/*from w w w.jav a2s .c o m*/ Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); for (int i = 0; i < 10; i++) { phrase.add(chunk); } Paragraph paragraph = new Paragraph(); // 1 paragraph.add(phrase); // 2 document.add(paragraph); // 3 document.add(paragraph); // 4 document.close(); }
From source file:com.geek.tutorial.itext.text.Phrase_Example.java
License:Open Source License
public Phrase_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("phrase_example.pdf")); document.open();//from w w w . j a va 2 s .co m Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); // 1 for (int i = 0; i < 10; i++) { phrase.add(chunk); // 2 } document.add(phrase); // 3 document.close(); }
From source file:com.gtdfree.test.PDFTestFont.java
License:Open Source License
/** * Fonts and encoding./*from w w w. ja v a 2 s. co m*/ * @param args no arguments needed */ public static void main(String[] args) { System.out.println("Encodings"); String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); System.out.println(Arrays.toString(names)); /*System.out.println("---"); try { System.getProperties().store(System.out, ""); } catch (IOException e1) { e1.printStackTrace(); } System.out.println("---");*/ //System.out.println(System.getenv()); //System.out.println("---"); //String font= System.getProperty("java.home")+"/lib/fonts/LucidaBrightRegular.ttf"; //String font= "fonts/DejaVuSans.ttf"; //byte[] ttf= ApplicationHelper.loadResource(font); try { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter.getInstance(document, new FileOutputStream("encodingfont.pdf")); // step 3 document.open(); // step 4 String all[] = { "Symbol", "ZapfDingbats" }; Font hex = new Font(Font.HELVETICA, 5); for (int z = 0; z < all.length; ++z) { String file = all[z]; document.add(new Paragraph( "Unicode equivalence for the font \"" + file + "\" with the encoding \"" + file + "\"\n")); /*char tb[]; if (z == 0) tb = SYMBOL_TABLE; else tb = DINGBATS_TABLE;*/ BaseFont bf; if (z == 2) { bf = BaseFont.createFont(file, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, null, null); ; } else { bf = BaseFont.createFont(file, file, true); } Font f = new Font(bf, 12); PdfPTable table = new PdfPTable(16); table.setWidthPercentage(100); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (char k = 0; k < Character.MAX_VALUE; ++k) { char c = k; if (bf.charExists(c)) { Phrase ph = new Phrase(12, new String(new char[] { c }), f); ph.add(new Phrase(12, "\n" + Integer.toString(c) + "\n" + cst(c), hex)); table.addCell(ph); } /* else { Phrase ph = new Phrase("\u00a0"); ph.add(new Phrase(12, "\n\n" + cst(c), hex)); table.addCell(ph); }*/ } document.add(table); document.newPage(); } // step 5 document.close(); FontFactory.registerDirectories(); Set<?> s = FontFactory.getRegisteredFonts(); System.out.println("Fonts: " + s); s = FontFactory.getRegisteredFamilies(); System.out.println("Families: " + s); ArrayList<Font> f = new ArrayList<Font>(s.size()); for (Object name : s) { try { f.add(FontFactory.getFont(name.toString(), "UTF-8", true, 12, Font.NORMAL, Color.BLACK, true)); } catch (Exception e) { f.add(FontFactory.getFont(name.toString(), "UTF-8", false, 12, Font.NORMAL, Color.BLACK, true)); } } Collections.sort(f, new Comparator<Font>() { @Override public int compare(Font o1, Font o2) { return o1.getFamilyname().compareTo(o2.getFamilyname()); } }); for (Font ff : f) { if (ff.getBaseFont() == null) { continue; } System.out.println(ff.getFamilyname() + " " + ff.getBaseFont().isEmbedded()); } } catch (Exception de) { de.printStackTrace(); } }
From source file:com.krawler.accounting.fontsetting.FontFamilySelector.java
License:Open Source License
public Phrase process(String text, FontContext context, Color color, Float size, Integer style) { int fsize = families.size(); if (fsize == 0) throw new IndexOutOfBoundsException("No font is defined."); if (text == null) text = ""; char cc[] = text.toCharArray(); int len = cc.length; StringBuffer sb = new StringBuffer(); Font font = null;//from w ww. j a va 2s.c o m int lastidx = -1; Phrase ret = new Phrase(); for (int k = 0; k < len; ++k) { char c = cc[k]; if (c == '\n' || c == '\r') { sb.append(c); continue; } if (Utilities.isSurrogatePair(cc, k)) { int u = Utilities.convertToUtf32(cc, k); for (int f = 0; f < fsize; ++f) { font = (Font) families.get(f).getPrimaryFont(); if (font.getBaseFont().charExists(u)) { if (lastidx != f) { if (sb.length() > 0 && lastidx != -1) { FontFamily fm = families.get(lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); sb.setLength(0); } lastidx = f; } sb.append(c); sb.append(cc[++k]); break; } } } else { for (int f = 0; f < fsize; ++f) { font = (Font) families.get(f).getPrimaryFont(); if (font.getBaseFont().charExists(c)) { if (lastidx != f) { if (sb.length() > 0 && lastidx != -1) { FontFamily fm = families.get(lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); sb.setLength(0); } lastidx = f; } sb.append(c); break; } } } } if (sb.length() > 0) { FontFamily fm = families.get(lastidx == -1 ? 0 : lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); } return ret; }
From source file:com.krawler.common.fontsettings.FontFamilySelector.java
License:Open Source License
public Phrase process(String text, FontContext context, Color color, Float size, Integer style) { int fsize = families.size(); if (fsize == 0) throw new IndexOutOfBoundsException("No font is defined."); if (text == null) text = ""; char cc[] = text.toCharArray(); int len = cc.length; StringBuffer sb = new StringBuffer(); Font font = null;/*from w w w .ja v a2s. c o m*/ int lastidx = -1; Phrase ret = new Phrase(); for (int k = 0; k < len; ++k) { char c = cc[k]; if (c == '\n' || c == '\r') { sb.append(c); continue; } if (Utilities.isSurrogatePair(cc, k)) { int u = Utilities.convertToUtf32(cc, k); for (int f = 0; f < fsize; ++f) { font = (Font) families.get(f).getPrimaryFont(); if (font.getBaseFont().charExists(u)) { if (lastidx != f) { if (sb.length() > 0 && lastidx != -1) { FontFamily fm = families.get(lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); sb.setLength(0); } lastidx = f; } sb.append(c); sb.append(cc[++k]); break; } } } else { for (int f = 0; f < fsize; ++f) { font = (Font) families.get(f).getPrimaryFont(); if (font.getBaseFont().charExists(c)) { if (lastidx != f) { if (sb.length() > 0 && lastidx != -1) { FontFamily fm = families.get(lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); sb.setLength(0); } lastidx = f; } sb.append(c); break; } } } } if (sb.length() > 0) { FontFamily fm = families.get(lastidx == -1 ? 0 : lastidx); Font fnt = fm.getFont(context); applyPropertiesToFont(fnt, color, size, style); Chunk ck = new Chunk(sb.toString(), fnt); ret.add(ck); } return ret; }