List of usage examples for com.lowagie.text Font Font
public Font(int family)
From source file:br.gov.jfrj.siga.ex.util.GeradorRTF.java
License:Open Source License
public byte[] geraRTF(ExDocumento doc) throws Exception { html = doc.getConteudoBlobHtmlString(); html = (new ProcessadorHtml()).canonicalizarHtml(html, true, false, true, true, false); html = html.replace("<!-- INICIO MIOLO -->", "<MIOLO>"); html = html.replace("<!-- FIM MIOLO -->", "</MIOLO>"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); RtfWriter2.getInstance(document, baos); document.open();//from ww w . ja v a2s . c om document.setMargins(29, 340, 29, 29); parser.setInput(new StringReader(html)); BaseFont arial = BaseFont.createFont("C:\\WINDOWS\\FONTS\\ARIAL.TTF", BaseFont.CP1252, true); Font fonte = new Font(arial); fonte.setSize(7); Paragraph paragrafoBase = new Paragraph("", fonte); paragrafoBase.add("\t" + doc.getOrgaoUsuario().getDescricaoMaiusculas()); paragrafoBase.add("\n\n"); paragrafoBase .add("\t" + doc.getExFormaDocumento().getDescricao().toUpperCase() + " " + doc.getCodigoString()); if (doc.getDtDocDDMMYY() != null && doc.getDtDocDDMMYY().length() > 0) paragrafoBase.add(" DE " + doc.getDtDocDDMMYY()); paragrafoBase.add("\n\n"); try { seekTag("MIOLO"); paragrafoBase = (Paragraph) percorreProximoBloco(paragrafoBase, 0, true); document.add(paragrafoBase); } catch (XmlPullParserException xppe) { int a = 2; } catch (IOException ioe) { int a = 2; } finally { document.close(); } /* * Pattern p1 = Pattern .compile("^.<!-- INICIO MIOLO -->.<!-- * FIM MIOLO -->."); final Matcher m = p1.matcher(html); */ byte[] retorno = baos.toByteArray(); baos.close(); return retorno; }
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;// ww w . j ava 2 s . co m 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(); 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
static void setDefaultFont(Font defaultFont) { _defaultFont = new Font(defaultFont); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
static void setDefaultFontMono(Font defaultFontMono) { _defaultFontMono = new Font(defaultFontMono); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
/** * @return a new Font with the same settings as the Font assigned to the most recently-created Paragraph at time of construction. *///from w w w .jav a2 s . c om public Font getCurrentFont() { if (currentFont == null) currentFont = getDefaultFont(); return new Font(currentFont); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
public Font getDefaultFont() { return new Font(_defaultFont); }
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
public Font getDefaultFontMono() { return new Font(_defaultFontMono); }
From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java
License:Open Source License
private List<PdfPCell> getHeaders(Document document) { List<PdfPCell> result = new ArrayList<>(); Element tr = document.getRootElement().getChild("thead").getChildren().get(0); for (Element th : tr.getChildren()) { PdfPCell cell = new PdfPCell(new Phrase(th.getText(), new Font(Font.BOLD))); result.add(cell);/*ww w . j a v a 2 s . c o m*/ } return result; }
From source file:com.kahlon.guard.controller.DocumentManager.java
/** * * @param document//from w ww . j a v a2 s. c o m */ public void preProcessPDF(Object document) { try { BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.setMargins(5f, 5f, 10f, 5f); // headers and footers must be added before the document is opened HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); pdf.setFooter(footer); // HeaderFooter header = new HeaderFooter( // new Phrase("This is a header without a page number", new Font(bf_courier)), false); // header.setAlignment(Element.ALIGN_CENTER); // pdf.setHeader(header); pdf.open(); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); pdf.add(Image.getInstance(logo)); Person person = context.getSelectedPerson().getDisplayPerson(); String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName(); String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge()); String gender = FacesMessageUtil.getMessage("person.gender") + " : " + person.getGender().getDescription(); String race = FacesMessageUtil.getMessage("person.ethnicity") + " : " + person.getEthnicity().getDescription(); Person rootPerson = person.getRootPerson(); PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId()); Image imgb = Image.getInstance(imgp.getContent()); imgb.scaleToFit(100, 120); PdfPTable headerTable = new PdfPTable(2); PdfPTable personTable = new PdfPTable(1); personTable.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(name)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(age)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(gender)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(race)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.setText(Integer.toString(person.getId())); Image img = pdf417.getImage(); img.scalePercent(150, 60 * pdf417.getYHeight()); cell = new PdfPCell(img); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(15); personTable.addCell(cell); cell.addElement(personTable); headerTable.addCell(cell); cell = new PdfPCell(imgb); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(cell); headerTable.setSpacingAfter(15); pdf.add(headerTable); LineSeparator lineSeparator = new LineSeparator(); lineSeparator.setPercentage(82); pdf.add(lineSeparator); Paragraph space = new Paragraph(); space.add(""); space.setSpacingAfter(15); pdf.add(space); } catch (IOException e) { logger.log(Level.INFO, e.getMessage()); } catch (BadElementException e) { logger.log(Level.INFO, e.getMessage()); } catch (DocumentException e) { logger.log(Level.INFO, e.getMessage()); } catch (Exception e) { logger.log(Level.INFO, e.getMessage()); } }
From source file:cz.incad.kramerius.pdf.utils.pdf.FontMap.java
License:Open Source License
private Font createArialFont(File fontDirectory) throws DocumentException, IOException { File fontFile = new File(fontDirectory.getAbsolutePath(), "ext_ontheflypdf_ArialCE.ttf"); BaseFont bf = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.CP1250, true); return new Font(bf); }