List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:com.lawyer.pdfgeneration.AddParagraph.java
public void addNewParagraph(Document document, Font smallBold) throws DocumentException { // TODO Auto-generated method stub Paragraph preface = new Paragraph(); // We add one empty line // Lets write a big header //addEmptyLine(preface, 27); String SomeDataWhichIsDerived = pdfReaderFunction.rep1; // preface.add(new Paragraph("Generated Path of file"+OUTPUTFILE, catFont)); //The new paragraph allows us to set the font of our choice //addEmptyLine(preface, 5); // Will create: Report generated by: _name, _date // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3smallBold)); // addEmptyLine(preface, 20); preface.add(new Paragraph(SomeDataWhichIsDerived, smallBold)); // addEmptyLine(preface, 25); // preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",redFont)); document.add(preface);//from ww w. ja v a 2s .c om // Start a new page document.newPage(); }
From source file:com.leenmeij.app.utils.CreatePdf.java
/** * Adds an empty row for better overview * @param paragraph/* w w w . j a v a2 s .co m*/ * @param number */ private static void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private Paragraph getParagraph(Map it) throws Exception { Paragraph p = new Paragraph(); String lb = MapUtil.getStr(it, "label", null); if (lb != null) { Chunk ch = new Chunk(); ch.setLocalDestination(lb);/*from w w w.ja va 2s .co m*/ p.add(ch); } getChunks(p, it, null); List<Map> lst = (List) it.get("items"); if (lst != null) { for (Map item : lst) { Element el = getElement(item); if (el != null) p.add(el); } } applyFont(p, it); return p; }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private void getChunks(Paragraph p, final Map it, String text) throws Exception { if (text == null) { text = (String) it.get("text"); }//from ww w .j a va 2s .c o m if (text != null) { if (text.startsWith("<") || text.endsWith(">")) { //treat as HTML Reader in = new StringReader(text); FontFactoryImp ffi = new FontFactoryImp() { @Override public Font getFont(String fontname, String encoding, boolean embedded, float size, int style, BaseColor color, boolean cached) { if (size == Font.UNDEFINED) size = getSize(it); if (style == Font.UNDEFINED) style = getStyle(it); if (color == null) color = getColor(it, "color"); return super.getFont(fontname, encoding, embedded, size, style, color, cached); } }; HashMap map = new HashMap(); map.put("font_factory", ffi); List list = DirectHtmlWorker.parse2List(in, null, null, map); for (int i = 0; i < list.size(); i++) { Object el = list.get(i); if (el instanceof Paragraph) { Paragraph pp = (Paragraph) el; applyFont(pp, it); p.add(pp); } } return; } List<BaseFont> base = new ArrayList<BaseFont>(); String st = text; StringBuffer buf = new StringBuffer(); for (int i = 0; i < st.length(); i++) { char c = st.charAt(i); if (!compatible(base, c)) { processMacro(buf.toString(), base.get(0), it, p); buf.delete(0, buf.length()); base.clear(); } buf.append(c); } if (buf.length() > 0) { processMacro(buf.toString(), base.get(0), it, p); } } }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private void processMacro(String buf, BaseFont base, Map it, Paragraph p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { List<String> list = LightUtil.splitMacro(buf, '$'); for (String ss : list) { Chunk ch = null;//from www .j a va2s . c om if (ss.equals("${pageNumber}")) { PdfWriter writer = getWriter(); if (writer != null) ss = writer.getPageNumber() + ""; else ss = ThreadHelper.get("pageNumber") + ""; } else if (ss.equals("${pageCount}")) { ss = ThreadHelper.get("pageCount") + ""; } else if (ss.equals("${newPage}")) { ch = Chunk.NEXTPAGE; } else if (ss.equals("${newLine}")) { ch = Chunk.NEWLINE; } if (ch == null) ch = new Chunk(ss, new Font(base)); applyFont(ch, it); String gt = MapUtil.getStr(it, "goto", null); if (gt != null) { ch.setLocalGoto(gt); } p.add(ch); } }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
/** * Adds a link to the current paragraph. * @since 5.0.6/*from ww w .ja v a2s .c o m*/ */ public void processLink() { if (currentParagraph == null) { currentParagraph = new Paragraph(); } // The link provider allows you to do additional processing LinkProcessor i = (LinkProcessor) providers.get(HTMLWorker.LINK_PROVIDER); if (i == null || !i.process(currentParagraph, chain)) { // sets an Anchor for all the Chunks in the current paragraph String href = chain.getProperty(HtmlTags.HREF); if (href != null) { for (Chunk ck : currentParagraph.getChunks()) { ck.setAnchor(href); } } } // a link should be added to the current paragraph as a phrase if (stack.isEmpty()) { // no paragraph to add too, 'a' tag is first element Paragraph tmp = new Paragraph(new Phrase(currentParagraph)); currentParagraph = tmp; } else { Paragraph tmp = (Paragraph) stack.pop(); tmp.add(new Phrase(currentParagraph)); currentParagraph = tmp; } }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public void generatePdf(Author author, String filename, String type) { // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch) // marginLeft, marginRight, marginTop, marginBottom Document document = new Document(PageSize.A4, 50, 50, 80, 50); try {//from w w w.java2s.c om if (m_shopping_basket.size() > 0) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setBoxSize("art", new Rectangle(50, 50, 560, 790)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); PdfContentByte cb = writer.getDirectContent(); document.addAuthor("ywesee GmbH"); document.addCreator("AmiKo for Windows"); document.addCreationDate(); // Logo String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png"); File logoFile = new File(logoImageStr); if (!logoFile.exists()) logoImageStr = Constants.IMG_FOLDER + "empty_logo.png"; Image logo = Image.getInstance(logoImageStr); logo.scalePercent(30); logo.setAlignment(Rectangle.ALIGN_RIGHT); document.add(logo); document.add(Chunk.NEWLINE); // Bestelladresse // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); String bestellAdrStr = getAddressAsString(BestellAdresseID); Paragraph p = new Paragraph(12); // p.setIndentationLeft(60); p.add(new Chunk(bestellAdrStr, font_norm_10)); document.add(p); document.add(Chunk.NEWLINE); // Title p = new Paragraph(m_rb.getString("order"), font_bold_16); document.add(p); // Date DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(); p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10); p.setSpacingAfter(20); document.add(p); // document.add(Chunk.NEWLINE); // Add addresses (Lieferadresse + Rechnungsadresse) /* --> OLD String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2")); String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3")); */ // --> NEW String lieferAdrStr = getAddressAsString(LieferAdresseID); String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID); PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 }); addressTable.setWidthPercentage(100f); addressTable.getDefaultCell().setPadding(5); addressTable.setSpacingAfter(5f); addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); document.add(addressTable); document.add(Chunk.NEWLINE); // Add shopping basket if (type.equals("specific")) document.add(getShoppingBasketForAuthor(author, cb)); else if (type.equals("all")) document.add(getFullShoppingBasket(cb, "all")); else if (type.equals("rest")) document.add(getFullShoppingBasket(cb, "rest")); LineSeparator separator = new LineSeparator(); document.add(separator); } } catch (IOException e) { } catch (DocumentException e) { } document.close(); // System.out.println("Saved PDF to " + filename); }
From source file:com.microware.intrahealth.Createpdf2.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);// ww w.jav a 2s . c o m // Lets write a big header preface.add(new Paragraph("Break Even Master Input", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Community profile", subFont)); // addEmptyLine(preface, 3); // preface.add(new Paragraph("This document describes something which is very important ", // smallBold)); // // addEmptyLine(preface, 8); // // preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", // redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:com.microware.intrahealth.Createpdf2.java
private static void addContent(Document document, String Header[], ArrayList<HashMap<String, String>> data, String[] sHeader2, int Flag) throws Exception { Paragraph preface = new Paragraph(); // preface.setAlignment(Element.ALIGN_CENTER); addEmptyLine(preface, 1);/* w w w. ja v a2 s .c o m*/ preface.add(mypara(sHeader[0], 1)); addEmptyLine(preface, 1); preface.add(mypara(sHeader[1], 1)); addEmptyLine(preface, 1); preface.add(mypara(sHeader[2], 2)); addEmptyLine(preface, 1); createTable(preface, Header, data); preface.add(mypara(sHeader2[0], 2)); addEmptyLine(preface, 1); preface.add(mypara(sHeader2[1] + " " + data.size(), 2)); addEmptyLine(preface, 1); preface.add(mypara(sHeader2[2] + " " + data.size(), 2)); addEmptyLine(preface, 1); addEmptyLine(preface, 1); preface.add(mypara(sHeader2[3], 3)); addEmptyLine(preface, 1); // document.add(preface); }
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data) throws BadElementException { Context _con = null;/* w w w .ja v a2s .co m*/ // PdfPTable table = new PdfPTable(new float[] { 2, 1 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPTable table = new PdfPTable(new float[] { 1, 3, 3, 5, 5, 2, 3, 2, 2, 2 }); table.setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); } // table.addCell("Value"); // table.addCell("Location"); table.setHeaderRows(1); // PdfPCell c1 = new PdfPCell(new Phrase("Text",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // c1 = new PdfPCell(new Phrase("Value",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); // // Font f = FontFactory.getFont(getFilesDir() + "/" + HINDI_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // PdfPCell eCell = new PdfPCell(new Phrase(entry, f)); for (int i = 0; i < data.size(); i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(data.get(i).get("ASHAName"), subFont)); table.addCell(String.valueOf((i + 1))); table.addCell(data.get(i).get("ASHAName")); table.addCell(data.get(i).get("VillageName")); table.addCell(data.get(i).get("PWName")); table.addCell(data.get(i).get("MotherMCTSID")); table.addCell(data.get(i).get("HusbandName")); table.addCell(Validate.changeDateFormat(data.get(i).get("CheckupVisitDate"))); table.addCell(data.get(i).get("DangerSign")); table.addCell(data.get(i).get("CheckupPlace")); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); // cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); // cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } // table.addCell("Colour"); // table.addCell("Hazen Unit"); // table.addCell("1.2"); // table.addCell("Turbidity"); // table.addCell("NTU"); // table.addCell("2.3"); preface.add(table); }