List of usage examples for com.lowagie.text.pdf FontSelector addFont
public void addFont(Font font)
Font
to be searched for valid characters. From source file:ilarkesto.integration.itext.Paragraph.java
License:Open Source License
public FontSelector createFontSelector(String preferredFont, FontStyle fontStyle) { FontSelector selector = new FontSelector(); selector.addFont(createFont(preferredFont, fontStyle)); // fallback from ilarkesto.jar selector.addFont(createFont("fonts/HDZB_36.ttf", fontStyle)); // embeddable chinese // fallback from iTextAsian.jar selector.addFont(createFont("STSong-Light", fontStyle)); // simplified chinese selector.addFont(createFont("MHei-Medium", fontStyle)); // traditional chinese selector.addFont(createFont("HeiseiMin-W3", fontStyle)); // japanese selector.addFont(createFont("KozMinPro-Regular", fontStyle)); // japanese selector.addFont(createFont("HYGoThic-Medium", fontStyle)); // korean return selector; }
From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
private FontSelector createFontSelector(String fontName, float size, int style, Color color) { FontSelector selector = new FontSelector(); selector.addFont(FontFactory.getFont(fontName, size, style, color)); /*//from w w w . ja v a 2 s . c o m * Add extra fonts provided by the FontProvider */ if (fontProvider != null) { Collection<Font> extraFonts = fontProvider.getFonts(); for (Font extraFont : extraFonts) { selector.addFont(extraFont); } } /* * Supported CJK (Chinese, Japanse, Korean) * * his is the list of fonts supported in the iTextAsian.jar: * Chinese Simplified: * STSong-Light and STSongStd-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V * Chinese Traditional: * MHei-Medium, MSung-Light and MSungStd-Light with the encodings UniCNS-UCS2-H and UniCNS-UCS2-V * Japanese: * HeiseiMin-W3, HeiseiKakuGo-W5 and KozMinPro-Regular with the encodings UniJIS-UCS2-H, UniJIS-UCS2-V, UniJIS-UCS2-HW-H and UniJIS-UCS2-HW-V * Korean: * HYGoThic-Medium, HYSMyeongJo-Medium and HYSMyeongJoStd with the encodings UniKS-UCS2-H and UniKS-UCS2-V * * Need to find out which fonts we should add to the selector and in which order */ selector.addFont(FontFactory.getFont("KozMinPro-Regular", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED, size, style, color)); selector.addFont( FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED, size, style, color)); selector.addFont( FontFactory.getFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED, size, style, color)); return selector; }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveListOfAlbumsAsPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File file = askForFile(window, "pdf"); if (file == null) return;/* ww w . ja v a 2 s . com*/ Hashtable albums = analysis.getHash(Analysis.KIND_ALBUM); DecimalFormat timeFormat = new DecimalFormat("0.0"); StringPair list[] = new StringPair[albums.size()]; Enumeration keys = albums.keys(); Integer index = 0; String regex = Album.SeparatorRegEx; while (keys.hasMoreElements()) { String albumartist = (String) keys.nextElement(); String[] parts = albumartist.split(regex); StringPair pair = new StringPair(parts[1], parts[0]); list[index] = pair; index++; } Arrays.sort(list, new StringPairComparator()); int done = 0; progressBar.setMinimum(0); progressBar.setMaximum(list.length); String infoString = NumberFormat.getInstance().format(list.length) + " "; if (list.length == 1) infoString += Misc.getString("ALBUM") + ", "; else infoString += Misc.getString("ALBUMS") + ", "; DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); infoString += "created on " + dateFormat.format(Calendar.getInstance().getTime()); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(file)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_ALBUMS"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); FontSelector albumSelector = new FontSelector(); Color albumColor = new Color(0x55, 0x55, 0x55); albumSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, albumColor)); Font albumAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); albumAsianFont.setSize(8); albumAsianFont.setColor(albumColor); albumSelector.addFont(albumAsianFont); FontSelector artistSelector = new FontSelector(); Color artistColor = new Color(0x77, 0x77, 0x77); artistSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, artistColor)); Font artistAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); artistAsianFont.setSize(8); artistAsianFont.setColor(artistColor); artistSelector.addFont(artistAsianFont); for (index = 0; index < list.length; index++) { p = new Paragraph(); p.setLeading(9); // separate the string into the album and artist parts Phrase phrase = albumSelector.process(list[index].Value); p.add(phrase); phrase = artistSelector.process(" " + Misc.getString("BY") + " " + list[index].Name); p.add(phrase); document.add(p); done++; progressBar.setValue(done); } // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:optika.sql.java
public PdfPCell getCellWhite(String text, int alignment, int bottom) { PdfPCell cell = new PdfPCell(); FontSelector selector = new FontSelector(); com.lowagie.text.Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); f1.setColor(Color.white);/*ww w.ja v a2 s. c om*/ selector.addFont(f1); cell.addElement(selector.process(text)); cell.setPadding(0); cell.setHorizontalAlignment(alignment); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingBottom(bottom); return cell; }
From source file:org.pz.platypus.plugin.pdf.commands.PdfBulletListPlainStartWithOptions.java
License:Open Source License
/** * Look up the symbol in the symbol table and get the Unicode value and any symbol font info. * /*www.j a v a 2 s . c o m*/ * @param param value passed with the "bullet:" parameter * @param pdd the PDF document data * @param tok the token for the whole bullet list command * @return Chunk containing for the bullet symbol */ Chunk lookupBulletSymbol(final String param, final Token tok, final PdfData pdd) { assert (pdd != null); assert (tok != null); assert (param != null); GDD gdd = pdd.getGdd(); StringBuilder sb = new StringBuilder(10); int i = 0; while (i < param.length() && param.charAt(i) != '}' && param.charAt(i) != ']') sb.append(param.charAt(i++)); if (param.charAt(i) != '}') { errorUnclosedOption(gdd, tok); return (new Chunk(DefaultValues.BULLET)); } String root = "[" + sb.toString() + "]"; ICommand value = gdd.getCommandTable().getCommand(root); if (!(value instanceof Symbol)) { errorBulletSymbolNotFound(gdd, tok); } // get the entry for this symbol. Should be a string that specifies the char value // as a Unicode value, with an optional font name. PdfSymbol processor = (PdfSymbol) pdd.getCommandTable().getCommand(root); String symEquivalent = processor.getSymEquivalent(); // get the Unicode value and font name, if any String font = processor.getFontName(symEquivalent, gdd, tok); String sym = processor.getCharCode(symEquivalent); if (font == null || font.isEmpty()) { return (new Chunk(sym)); } else { PdfFont newFont = new PdfFont(pdd, font, pdd.getFont()); FontSelector fs = new FontSelector(); fs.addFont(newFont.getItextFont()); Chunk chk = new Chunk(sym, newFont.getItextFont()); return (chk); } }
From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java
License:Open Source License
/** * Emit a single character in the current font, size, etc. This is used to output * a character by its Unicode value and is called by PdfSymbol, which handles the * processing of symbols and special characters. * * @param ch char to be emitted/*w ww. j a va 2 s.c o m*/ * @param fontName fontName to use. If null, use current font. */ public void emitChar(final String ch, final String fontName) { assert (ch != null) : "ch parameter null in PdfOutfile.emitChar()"; if (iTPara == null) { startNewParagraph(); } FontSelector fs = new FontSelector(); if (fontName == null || fontName.isEmpty()) { fs.addFont(pdfData.getFont().getItextFont()); } else { PdfFont newFont = new PdfFont(pdfData, fontName, pdfData.getFont()); fs.addFont(newFont.getItextFont()); } Phrase phr = fs.process(ch); iTPara.add(phr); }