List of usage examples for com.lowagie.text Font setStyle
public void setStyle(String style)
String
containing one of more of the following values: normal, bold, italic, underline, strike. From source file:be.fedict.eid.applet.service.impl.PdfGenerator.java
License:Open Source License
public byte[] generatePdf(EIdData eIdData) throws DocumentException { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open();/* www .j a va 2s . c o m*/ Paragraph titleParagraph = new Paragraph("eID Identity Data"); titleParagraph.setAlignment(Paragraph.ALIGN_CENTER); Font titleFont = titleParagraph.getFont(); titleFont.setSize((float) 20.0); titleFont.setStyle(Font.BOLD); titleParagraph.setSpacingAfter(20); document.add(titleParagraph); if (null != eIdData && null != eIdData.getIdentity()) { if (null != eIdData.getPhoto()) { try { Image image = createImageFromPhoto(eIdData.getPhoto()); document.add(image); } catch (Exception e) { LOG.error("Error getting photo: " + e.getMessage()); } Identity identity = eIdData.getIdentity(); // metadata setDocumentMetadata(document, identity.firstName, identity.name); writer.createXmpMetadata(); // create a table with the data of the eID card PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(0); table.addCell("Name"); table.addCell(identity.name); table.addCell("First name"); String firstName = identity.firstName; if (null != identity.middleName) { firstName += " " + identity.middleName; } table.addCell(firstName); table.addCell("Nationality"); table.addCell(identity.nationality); table.addCell("National Registration Number"); table.addCell(identity.nationalNumber); table.addCell("Gender"); table.addCell(identity.gender.toString()); table.addCell("Date of birth"); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); table.addCell(formatter.format(identity.dateOfBirth.getTime())); table.addCell("Place of birth"); table.addCell(identity.placeOfBirth); if (null != eIdData.getAddress()) { Address address = eIdData.getAddress(); table.addCell("Address"); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(new Paragraph(address.streetAndNumber)); cell.addElement(new Paragraph(address.zip + " " + address.municipality)); table.addCell(cell); } document.add(table); // TODO: to be tested /* try { Image barcodeImage = createBarcodeImage(identity.nationalNumber, identity.cardNumber); barcodeImage.setAlignment(Element.ALIGN_CENTER); Paragraph barcodePara = new Paragraph(); barcodePara.add(barcodeImage); document.add(barcodeImage); } catch (Exception e) { LOG.error("Error adding barcode: " + e.getMessage()); } */ } else { document.add(new Paragraph("No eID identity data available.")); } } document.close(); return baos.toByteArray(); }
From source file:ca.nines.ise.writer.RTFWriter.java
License:Open Source License
@Override public void render(DOM dom, Annotation annotation) throws DocumentException, IOException { this.preprocess(dom, annotation); fontStack = new ArrayDeque<>(); fontStack.push(FontFactory.getFont("Times New Roman", 12, Color.BLACK)); Font font; boolean inSP = false; // in speech prefix boolean inSD = false; // in stage direction boolean inDQ = false; // in a double quote boolean inS = false; // in a speech boolean inHW = false; char part = 'i'; String mode = "verse"; doc.open();/* ww w .jav a 2 s . co m*/ startParagraph(); for (Node n : dom) { switch (n.type()) { case ABBR: break; case CHAR: addChunk(n.unicode()); break; case EMPTY: switch (n.getName()) { case "FNLOC": EmptyNode fnloc = (EmptyNode) n; Note note = annotation.get(Integer.parseInt(fnloc.getAttribute("ref")) - 1); if (!note.hasNoteLevel("1")) { break; } this.footnote(note); break; case "TLN": case "L": if (mode.equals("prose")) { break; } if (inS) { startParagraph(p2); } else { startParagraph(p1); } EmptyNode en = (EmptyNode) n; if (en.hasAttribute("part")) { part = en.getAttribute("part").charAt(0); } else { part = 'i'; } break; } break; case END: switch (n.getName()) { case "FOREIGN": fontStack.pop(); break; case "HW": inHW = false; break; case "I": fontStack.pop(); break; case "LD": startParagraph(); break; case "S": inS = false; break; case "SD": fontStack.pop(); inSD = false; break; case "SP": addChunk(". "); inSP = false; break; } break; case START: switch (n.getName()) { case "FOREIGN": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); fontStack.push(font); break; case "HW": inHW = true; break; case "I": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); fontStack.push(font); break; case "LD": startParagraph(ld); break; case "MODE": mode = ((TagNode) n).getAttribute("t"); break; case "S": if (mode.equals("prose")) { startParagraph(prose); } inS = true; break; case "SD": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); StartNode start = (StartNode) n; if (start.hasAttribute("t") && start.getAttribute("t").contains("exit")) { startParagraph(exit); } if (start.hasAttribute("t") && start.getAttribute("t").contains("optional")) { font.setColor(Color.GRAY); } fontStack.push(font); inSD = true; break; case "SP": inSP = true; break; } break; case TEXT: String txt = n.getText(); txt = txt.replace("--", "\u2014"); txt = txt.replace("\n", ""); if (inSP) { addChunk(txt.toUpperCase()); break; } if (inHW) { txt = txt.replaceFirst("[(]", ""); inHW = false; } if (inSD) { // DOES NOT MATCH AFTER A TAG. if ((txt.indexOf('[') >= 0) || (txt.indexOf(']') >= 0)) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); if (c == '[' || c == ']') { if (sb.length() > 0) { addChunk(sb.toString()); sb = new StringBuilder(); } addDirect("{\\i0" + String.valueOf(c) + "}"); } else { sb.append(c); } } if (sb.length() > 0) { addChunk(sb.toString()); } break; } else { addChunk(txt); break; } } if (part != 'i' && inS) { RtfTab tab = null; String tabStr = ""; if (part == 'm') { tab = new RtfTab(100, RtfTab.TAB_LEFT_ALIGN); tabStr = "\t"; } if (part == 'f') { tab = new RtfTab(200, RtfTab.TAB_LEFT_ALIGN); tabStr = "\t\t"; } if (tab != null) { p.add(tab); addChunk(tabStr); } part = 'i'; // ensure it's only done once for m or f. } // fix quotation marks. StringBuilder sb = new StringBuilder(); for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); switch (c) { case '"': if (inDQ) { // typographer's end quote. sb.append("\u201D"); inDQ = false; } else { // typographer's start quote. sb.append("\u201C"); inDQ = true; } break; case '\'': sb.append("\u2019"); // appostrophe break; default: sb.append(c); } } addChunk(sb.toString()); break; } } startParagraph(); doc.close(); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
void modifyFontInPlace(Font font, StyleSpecText styleSpec) { int style = font.getStyle(); if (styleSpec.isBold()) { style |= Font.BOLD;//ww w .j av a 2 s . c o m } if (styleSpec.isItalic()) { style |= Font.ITALIC; } font.setStyle(style); }
From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
@Override public void characters(char[] ch, int start, int length) { String content = new String(ch, start, length); String abridgedContent;/*from ww w. j a v a 2 s.c om*/ if (content.length() <= 20) { abridgedContent = content; } else { abridgedContent = content.substring(0, 10); abridgedContent += " ... "; int tailStartIndex = content.length() - 10; int tailEndIndex = content.length(); abridgedContent += content.substring(tailStartIndex, tailEndIndex); } //printlnerr("chars:[" + abridgedContent + "]"); boolean printThese = true; for (String tag : nonPrintingTags) { if (tag.equals(currentTag)) { printThese = false; break; } } if (inStyleTag) { if (styleTagContents == null) { styleTagContents = new StringBuilder(); } styleTagContents.append(content); } else if (printThese) { Font font = null; if (XhtmlTags.PRE.equals(currentTag) || XhtmlTags.TT.equals(currentTag)) { font = textFactory.getDefaultFontMono(); } else { font = textFactory.getCurrentFont(); } if (currentITextStyle != font.getStyle()) { font.setStyle(currentITextStyle); } if (!(XhtmlTags.PRE.equals(currentTag) || XhtmlTags.TT.equals(currentTag))) { if (stack.size() > 0 && stack.peek() instanceof Paragraph) { content = changeLineBreaksToSpaces(content); } else { content = removeLineBreaks(content); } if (nothingButSpaces(content)) { SaxElement tagInProgress = saxElementStack.peek(); if (!tagInProgress.qName.equals("p")) { content = ""; } } boolean leadingSpace = content.length() >= 1 && content.startsWith(" ") && !freshParagraph; //content.charAt(1) != ' '; boolean trailingSpace = content.length() > 1 && content.endsWith(" "); //&& //content.charAt(content.length()-2) != ' '; content = content.trim(); if (leadingSpace) { content = " " + content; } if (trailingSpace) content = content + " "; } if (content.length() > 0) { if (currentChunk != null) { if (specialParagraph != null || currentChunk.getFont().compareTo(font) != 0) { pushToStack(currentChunk); currentChunk = null; } else { currentChunk.append(content); } } else { if (specialParagraph != null) { specialParagraph.add(new Chunk(content)); } else { currentChunk = new Chunk(content, font); } } } freshParagraph = false; } }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startChapter(String pStrChapterTitle) { Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());/*from w ww. j ava2 s . c om*/ lFont.setStyle(Font.BOLD); Anchor anchor = new Anchor(pStrChapterTitle, lFont); anchor.setName(pStrChapterTitle); mChapter = new Chapter(new Paragraph(anchor), ++mIntChapterPosition); addEmptyLines(1); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void addText(String pStrText, TextFormatting pTextFormatting) { mLog.debug("Start addText(): " + pStrText); Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());// ww w . ja v a 2 s. co m int lIntStyle = 0; if (pTextFormatting.bold) { lIntStyle = lIntStyle | Font.BOLD; } if (pTextFormatting.italic) { lIntStyle = lIntStyle | Font.ITALIC; } if (pTextFormatting.underline) { lIntStyle = lIntStyle | Font.UNDERLINE; } if (pTextFormatting.strike) { lIntStyle = lIntStyle | Font.STRIKETHRU; } lFont.setStyle(lIntStyle); Chunk lChunk = new Chunk(pStrText, lFont); if (mListItem != null) { mListItem.add(lChunk); } else if (mParagraph != null) { mParagraph.add(lChunk); } mLog.debug("End addText()"); }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startSection(String pStrSectionTitle) { Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());/*from www. j a v a 2 s . c om*/ lFont.setStyle(Font.ITALIC); Anchor anchor = new Anchor(pStrSectionTitle, lFont); anchor.setName(pStrSectionTitle); mSection = mChapter.addSection(new Paragraph(anchor)); }
From source file:com.geek.tutorial.itext.bookmarks.Anchor.java
License:Open Source License
public Anchor() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("anchor.pdf")); document.open();//from w w w. j a v a 2 s . c om // Code 1 Font font = new Font(); font.setColor(Color.BLUE); font.setStyle(Font.UNDERLINE); document.add(new Chunk("Chapter 1")); document.add(new Paragraph(new Chunk("Press here to go chapter 2", font).setLocalGoto("2")));// Code 2 document.newPage(); document.add(new Chunk("Chapter 2").setLocalDestination("2")); document.add(new Paragraph( new Chunk("http://www.geek-tutorials.com", font).setAnchor("http://www.geek-tutorials.com")));//Code 3 document.add( new Paragraph(new Chunk("Open outline.pdf chapter 3", font).setRemoteGoto("outline.pdf", "3")));//Code 4 document.close(); }
From source file:com.krawler.accounting.fontsetting.FontFamilySelector.java
License:Open Source License
private void applyPropertiesToFont(Font font, Color color, Float size, Integer style) { if (color != null) font.setColor(color);/* ww w .j a v a2 s . co m*/ if (size != null) font.setSize(size); if (style != null) font.setStyle(style); }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getReceiptAcc1(String ackrecp) { ByteArrayOutputStream os = null; try {// w w w. ja v a2s. c om os = new ByteArrayOutputStream(); JSONObject jbj = new JSONObject(ackrecp); com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ginfo[] = new String[gridinfo.length() * 2]; String ids[] = { "name", "receiptno", "paymentdate", "address" }; String currency = "USD"; // String address = jbj.getString("address"); String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); Font font3 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); //Font font4 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font12 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); Document document1 = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document1, os); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document1.setFooter(temp); document1.open(); PdfPTable tableHinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(1); font3.setStyle(Font.UNDERLINE); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); // img.scalePercent(90); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setPaddingTop(18); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(1, tableHinfo); tableHinfo = addspace(4, tableHinfo); cell1 = new PdfPCell(new Paragraph("RECEIPT", font1)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(0, tableHinfo); // cell1 = new PdfPCell(new Paragraph(uinfo[4], font11)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableHinfo.addCell(cell1); document1.add(tableHinfo); PdfPTable tableUinfo = new PdfPTable(1); cell1 = new PdfPCell(new Paragraph(receiptheading[0], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[0], font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[3], font11)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); document1.add(new Paragraph("\u00a0")); tableUinfo = addspace(1, tableUinfo); String hed[] = { "", "Receipt No : ", "Date : ", "" }; PdfPTable tableDinfo = new PdfPTable(1); //tableDinfo.setTotalWidth(100); for (int j = 1; j < 3; j++) { PdfPTable nested1 = new PdfPTable(3); cell1 = new PdfPCell(); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(hed[j], font)); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[j], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); nested1.addCell(cell1); cell1 = new PdfPCell(nested1); cell1.setBorder(0); tableDinfo.addCell(cell1); } PdfPTable container = new PdfPTable(2); cell1 = new PdfPCell(tableUinfo); cell1.setBorder(0); cell1.setPaddingBottom(15); container.addCell(cell1); cell1 = new PdfPCell(tableDinfo); cell1.setBorder(0); container.addCell(cell1); document1.add(container); PdfPTable table1 = new PdfPTable(2); String[] colwidth2 = { "Invoice No.", "Amount Paid($)" }; for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); if (i == 1) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setPaddingBottom(5); cell.setBorderWidthRight(1); cell.setBorderWidthTop(1); table1.addCell(cell); } table1.setHeaderRows(1); double d = 0; colwidth2 = new String[] { "invoicenum", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { for (int j = 0; j < colwidth2.length; j++) { PdfPCell cell = null; if (j == 1) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]))), font12)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell = new PdfPCell( new Paragraph(gridinfo.getJSONObject(i).getString(colwidth2[j]), font12)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } //cell.setMinimumHeight(25); cell.setBorderWidthRight(1); cell.setPaddingTop(5); cell.setFixedHeight(100); table1.addCell(cell); if (j == colwidth2.length - 1) { d += Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j])); } } } // EnglishDecimalFormat f1 = new EnglishDecimalFormat(); PdfPCell cell = new PdfPCell(new Paragraph("", font)); cell.setBorderWidthBottom(1); cell.setBorderWidthRight(0); cell.setBorderWidthLeft(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(cell); cell = new PdfPCell(new Paragraph("Total " + df.format(d), font)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); //cell.setPaddingBottom(15); cell.setPaddingLeft(15); cell.setPaddingBottom(5); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); table1.addCell(cell); PdfPTable table3 = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); //cell.setPaddingBottom(15); cell.setBorder(0); cell.setColspan(4); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table3.addCell(cell); document1.add(table1); document1.add(table3); document1.add(new Paragraph("\u00a0")); cell = new PdfPCell(new Paragraph(String.format( "All payments are non-refundable and non-transferable. \nThis Receipt is valid subject to clearance of the payments."), font11)); //cell.setPaddingLeft(5); cell.setBorder(0); table.addCell(cell); // String delFlag = jbj.getString("delflag"); // if(delFlag.compareTo("2")==0){ // BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); // PdfContentByte cb = writer.getDirectContentUnder(); // cb.saveState(); // cb.setColorFill(Color.BLACK); // cb.beginText(); // cb.setFontAndSize(bf, 48); // cb.showTextAligned(Element.ALIGN_CENTER, "Canceled Payment", document1.getPageSize().getWidth() / 2, document1.getPageSize().getHeight() / 2, 45); // cb.endText(); // cb.restoreState(); // } document1.add(table); document1.close(); writer.close(); os.close(); } catch (Exception e) { System.out.println(e); } return os; }