List of usage examples for com.itextpdf.text Chunk Chunk
private Chunk(final Float tabInterval, final boolean isWhitespace)
From source file:com.jpsycn.print.util.PDFUtils.java
private static Document setHeader(File file, Context mContext, Font simfang12, Font simfangBlod12, String title, String sno) throws DocumentException, IOException { Document document = new Document(PageSize.A4, 30, 30, 20, 0); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open();/*from w w w .j ava 2 s. co m*/ // Font simhei18 = FontUtil.getFont(mContext, 18, "simhei.ttf"); Paragraph b = new Paragraph(title, simhei18); b.setAlignment(Element.ALIGN_CENTER); document.add(b); // ? Chunk m1 = new Chunk("?", simfang12); Chunk m2 = new Chunk(sno, simfangBlod12); Paragraph p2 = new Paragraph(); p2.add(m1); p2.add(m2); p2.setAlignment(Element.ALIGN_RIGHT); document.add(p2); return document; }
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 ww w. ja v a2 s. com*/ 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.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 {/*w ww . j a v a 2 s . c o m*/ 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 createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data) throws BadElementException { Context _con = null;/*w w w. ja v a2s . com*/ // 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); }
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable1(Paragraph preface, String Text, String Value) throws BadElementException { Context _con = null;// ww w . j a v a2 s . c o m PdfPTable table = new PdfPTable(new float[] { 1, 3 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < 2; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase()); table.addCell(c1); } PdfPCell[] cells = table.getRow(0).getCells(); // for (int j=0;j<cells.length;j++){ cells[0].setHorizontalAlignment(Element.ALIGN_LEFT); // } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable1(Paragraph preface, String[] Header, String[] Text, String[] Value) throws BadElementException { Context _con = null;//from w w w .j av a2 s. c om PdfPTable table = new PdfPTable(new float[] { 2, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 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_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); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Value[i]); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable2(Paragraph preface, String[] Header, String[] Text, String[] Source, String[] Value) throws BadElementException { Context _con = null;/* ww w. jav a 2 s .c o m*/ PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 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_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); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Source[i]); table.addCell(Value[i]); 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); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable4(Paragraph preface, String[] Header, String Text, String Value) throws BadElementException { Context _con = null;/*from w ww. j a v a 2 s . co m*/ PdfPTable table = new PdfPTable(new float[] { 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 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_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); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable7(Paragraph preface, String Text, String Value) throws BadElementException { Context _con = null;//w ww .j a va2s . c o m PdfPTable table = new PdfPTable(new float[] { 1, 2 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < 2; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase()); table.addCell(c1); } PdfPCell[] cells = table.getRow(0).getCells(); // for (int j=0;j<cells.length;j++){ cells[0].setHorizontalAlignment(Element.ALIGN_LEFT); // } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); } preface.add(table); }
From source file:com.nubean.michutil.PDFConverter.java
License:Open Source License
private Chunk getChunk(javax.swing.text.Element ele) throws javax.swing.text.BadLocationException { int start = ele.getStartOffset(); int end = ele.getEndOffset(); String text = doc.getText(start, end - start); AttributeSet set = ele.getAttributes(); String fontFamily = StyleConstants.getFontFamily(set); int fontSize = StyleConstants.getFontSize(set); int style = Font.NORMAL; if (StyleConstants.isBold(set)) style = Font.BOLD;//w w w . j a v a 2 s .c o m if (StyleConstants.isItalic(set)) style |= Font.ITALIC; Color fontColor = StyleConstants.getForeground(set); BaseColor baseColor = new BaseColor(fontColor); Chunk chunk = new Chunk(text, FontFactory.getFont(fontFamily, fontSize, style, baseColor)); return chunk; }