/** * Create a font via the <code>FontFactory</code> * * @param fontName The font name to create * @return The created <code>Font</code> object * * @since 2.0.8 */ private Font createfont(String fontName) { Font f1 = null; int pos=-1; do { f1 = FontFactory.getFont(fontName); if(f1.getBaseFont() != null) break; // found a font, exit the do/while pos = fontName.lastIndexOf(' '); // find the last space if(pos>0) { fontName = fontName.substring(0, pos ); // truncate it to the last space } } while(pos>0); return f1; }
/** * Creates a Phrase object based on a list of properties. * @param attributes * @return a Phrase */ public static Phrase getPhrase(Properties attributes) { Phrase phrase = new Phrase(); phrase.setFont(FontFactory.getFont(attributes)); String value; value = attributes.getProperty(ElementTags.LEADING); if (value != null) { phrase.setLeading(Float.parseFloat(value + "f")); } value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT); if (value != null) { phrase.setLeading(Markup.parseLength(value, Markup.DEFAULT_FONT_SIZE)); } value = attributes.getProperty(ElementTags.ITEXT); if (value != null) { Chunk chunk = new Chunk(value); if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) { chunk.setGenericTag(value); } phrase.add(chunk); } return phrase; }
private static int insertDirectory(String requestedDirectory, DefaultFontMapper defaultFontMapper) { int ffCount = FontFactory.registerDirectory(requestedDirectory); int fmCount = 0; if (defaultFontMapper!=null) { fmCount = defaultFontMapper.insertDirectory(requestedDirectory); } if (ffCount>fmCount) return ffCount; else return fmCount; }
public EvalPDFReportBuilder(OutputStream outputStream) { document = new Document(); try { pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setStrictImageSequence(true); document.open(); // attempting to handle i18n chars better // BaseFont evalBF = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, // BaseFont.EMBEDDED); // paragraphFont = new Font(evalBF, 9, Font.NORMAL); // paragraphFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL); titleTextFont = new Font(Font.TIMES_ROMAN, 22, Font.BOLD); boldTextFont = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); questionTextFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); paragraphFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL); paragraphFontBold = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD); frontTitleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, frontTitleSize, Font.NORMAL); frontAuthorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL); frontInfoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.NORMAL); } catch (Exception e) { throw UniversalRuntimeException.accumulate(e, "Unable to start PDF Report"); } }
public FontProvider(String fontDirectories) { if (!StringUtils.isBlank(fontDirectories)) { try { for (String directory : fontDirectories.split(";")) { FontFactory.registerDirectory(directory); } log.info("Font directories registered"); } catch (Exception e) { log.error("Error loading font directories", e); } } }
private static void initFont() { String fontName = ServerConfigurationService.getString("pdf.default.font"); if (StringUtils.isNotBlank(fontName)) { FontFactory.registerDirectories(); if (FontFactory.isRegistered(fontName)) { font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); boldFont = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.BOLD); } else { log.warn("Can not find font: " + fontName); } } if (font == null) { font = new Font(); boldFont = new Font(Font.COURIER, 10, Font.BOLD); } }
@Override IFontPeer getFontInternal(String fontname) { boolean embedded = false; String encoding = "CP1252"; if (loadedFonts.containsKey(fontname)) { Alias alias = loadedFonts.get(fontname); fontname = alias.getName(); encoding = alias.getEncoding(); embedded = alias.isEmbed(); } Font font; try { font = FontFactory.getFont(fontname,encoding,embedded,Font.UNDEFINED, Font.UNDEFINED, null); } catch (Exception e) { throw new RuntimeException("Unable to load Font: " + fontname + " with encoding: " + encoding,e); } if (font==null) { throw new RuntimeException("Font: " + fontname + " not found."); } return new FontPeer(font.getBaseFont()); }
protected void writeBatchGroupSectionTitle(com.lowagie.text.Document pdfDoc, String batchSeqNbr, java.sql.Date procInvDt, String cashControlDocNumber) { Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD); String lineText = "CASHCTL " + rightPad(cashControlDocNumber, 12) + " " + "BATCH GROUP: " + rightPad(batchSeqNbr, 5) + " " + rightPad((procInvDt == null ? "NONE" : procInvDt.toString()), 35); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT); Chunk chunk = new Chunk(lineText, font); chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5); paragraph.add(chunk); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeDetailLine(com.lowagie.text.Document pdfDoc, String detailLineText) { if (ObjectUtils.isNotNull(detailLineText)) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT); paragraph.add(new Chunk(detailLineText, font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } } }
protected void writeInvoiceSectionTitle(com.lowagie.text.Document pdfDoc, String customerNameLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT); paragraph.add(new Chunk(customerNameLine, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeInvoiceSectionMessage(com.lowagie.text.Document pdfDoc, String resultLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT); paragraph.add(new Chunk(resultLine, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeFileNameSectionTitle(Document pdfDoc, String filenameLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(Element.ALIGN_LEFT); Chunk chunk = new Chunk(filenameLine, font); chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5); paragraph.add(chunk); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeCustomerSectionTitle(Document pdfDoc, String customerNameLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.add(new Chunk(customerNameLine, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeCustomerSectionResult(Document pdfDoc, String resultLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.add(new Chunk(resultLine, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
protected void writeMessageEntryLines(Document pdfDoc, List<String[]> messageLines) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL); Paragraph paragraph; String messageEntry; for (String[] messageLine : messageLines) { paragraph = new Paragraph(); paragraph.setAlignment(Element.ALIGN_LEFT); messageEntry = StringUtils.rightPad(messageLine[0], (12 - messageLine[0].length()), " ") + " - " + messageLine[1].toUpperCase(); paragraph.add(new Chunk(messageEntry, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } } }
/** * This method adds any error to the report * * @param errorMsg */ private void generateReportErrorLog(String errorMsg) { try { Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL); Paragraph p1 = new Paragraph(); int rowsWritten = 0; if (!errorMsg.equals("")) { this.generateErrorColumnHeaders(); p1 = new Paragraph(new Chunk(errorMsg, font)); this.document.add(p1); line++; } } catch (Exception de) { throw new RuntimeException("DepreciationReport.generateReportErrorLog(List<String> reportLog) - Report Generation Failed: " + de.getMessage()); } }
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.setPageSize(PageSize.A3); pdf.open(); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png"; Image image=Image.getInstance(logo); image.scaleAbsolute(100f, 50f); pdf.add(image); // add a couple of blank lines pdf.add( Chunk.NEWLINE ); pdf.add( Chunk.NEWLINE ); Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD); fontbold.setColor(55, 55, 55);; pdf.add(new Paragraph("Investment Summary",fontbold)); // add a couple of blank lines pdf.add( Chunk.NEWLINE ); pdf.add( Chunk.NEWLINE ); }
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.setPageSize(PageSize.A3); pdf.open(); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png"; Image image=Image.getInstance(logo); image.scaleAbsolute(100f, 50f); pdf.add(image); // add a couple of blank lines pdf.add( Chunk.NEWLINE ); pdf.add( Chunk.NEWLINE ); Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD); fontbold.setColor(55, 55, 55);; pdf.add(new Paragraph("Account Summary",fontbold)); // add a couple of blank lines pdf.add( Chunk.NEWLINE ); pdf.add( Chunk.NEWLINE ); }
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.open(); ServletContext servletContext = (ServletContext) FacesContext .getCurrentInstance().getExternalContext().getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "logo" + File.separator + "logo.png"; Image image = Image.getInstance(logo); image.scaleAbsolute(100f, 50f); pdf.add(image); // add a couple of blank lines pdf.add(Chunk.NEWLINE); pdf.add(Chunk.NEWLINE); Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD); fontbold.setColor(55, 55, 55); ; pdf.add(new Paragraph("Transaction Summary", fontbold)); // add a couple of blank lines pdf.add(Chunk.NEWLINE); pdf.add(Chunk.NEWLINE); }
private static void registerFontPath( final String fontPath ) { AccessController.doPrivileged( new PrivilegedAction<Object>( ) { public Object run( ) { long start = System.currentTimeMillis( ); File file = new File( fontPath ); if ( file.exists( ) ) { if ( file.isDirectory( ) ) { FontFactory.registerDirectory( fontPath ); } else { FontFactory.register( fontPath ); } } long end = System.currentTimeMillis( ); logger.info( "register fonts in " + fontPath + " cost:" + ( end - start ) + "ms" ); return null; } } ); }
/** * Load system fonts into the static <code>FontFactory</code> object * * @since 2.0.8 */ private void importSystemFonts() { try { Properties pr = getEnvironmentVariables(); String systemRoot = pr.getProperty("SystemRoot"); String fileSeperator = System.getProperty("file.separator"); FontFactory.registerDirectory(systemRoot + fileSeperator + "fonts"); } catch (Throwable e) { // Ignore } }
/** * Generates a PDF file with the 14 standard Type 1 Fonts (using * FontFactory) * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("FontFactoryType1Fonts.pdf")); // step 3: we open the document document.open(); // step 4: // the 14 standard fonts in PDF Font[] fonts = new Font[14]; fonts[0] = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.NORMAL); fonts[1] = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.ITALIC); fonts[2] = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.BOLD); fonts[3] = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.BOLD | Font.ITALIC); fonts[4] = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.NORMAL); fonts[5] = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC); fonts[6] = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD); fonts[7] = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLDITALIC); fonts[8] = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL); fonts[9] = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.ITALIC); fonts[10] = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD); fonts[11] = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC); fonts[12] = FontFactory.getFont(FontFactory.SYMBOL, Font.DEFAULTSIZE, Font.NORMAL); fonts[13] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, Font.DEFAULTSIZE, Font.NORMAL); // add the content for (int i = 0; i < 14; i++) { document.add(new Paragraph("quick brown fox jumps over the lazy dog", fonts[i])); } // step 5: we close the document document.close(); }
/** * Changing the style of a FontFactory Font. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontfactorystyles.pdf")); // step 3: we open the document document.open(); String fontPathBase = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf").getAbsolutePath(); // step 4: we add some content FontFactory.register(fontPathBase + "/LiberationSans-Regular.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-Italic.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-Bold.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-BoldItalic.ttf"); Phrase myPhrase = new Phrase("This is font family Liberation Sans ", FontFactory.getFont("LiberationSans", 8)); myPhrase.add(new Phrase("italic ", FontFactory.getFont("Arial", 8, Font.ITALIC))); myPhrase.add(new Phrase("bold ", FontFactory.getFont("Arial", 8, Font.BOLD))); myPhrase.add(new Phrase("bolditalic", FontFactory.getFont("Arial", 8, Font.BOLDITALIC))); document.add(myPhrase); // step 5: we close the document document.close(); }
/** * Demonstrates some Anchor functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter.getInstance(document, PdfTestBase.getOutputStream("AHref.pdf")); HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("AHref.html")); // step 3: we open the document document.open(); // step 4: Paragraph paragraph = new Paragraph("Please visit my "); Anchor anchor1 = new Anchor("website (external reference)", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference("http://www.lowagie.com/iText/"); anchor1.setName("top"); paragraph.add(anchor1); paragraph.add(new Chunk(".\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); document.add(paragraph); Anchor anchor2 = new Anchor("please jump to a local destination", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); anchor2.setReference("#top"); document.add(anchor2); // step 5: we close the document document.close(); }
/** * Demonstrates some Paragraph functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Paragraphs.pdf")); // step 3: we open the document document.open(); // step 4: Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph. ", FontFactory.getFont( FontFactory.HELVETICA, 10))); p1.add("The leading of this paragraph is calculated automagically. "); p1.add("The default leading is 1.5 times the fontsize. "); p1.add(new Chunk("You can add chunks ")); p1.add(new Phrase("or you can add phrases. ")); p1.add(new Phrase( "Unless you change the leading with the method setLeading, the leading doesn't change if you add text with another leading. This can lead to some problems.", FontFactory.getFont(FontFactory.HELVETICA, 18))); document.add(p1); Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph. ", FontFactory.getFont( FontFactory.HELVETICA, 12))); p2.add("As you can see, it started on a new line."); document.add(p2); Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12)); document.add(p3); // step 5: we close the document document.close(); }
private static Element newPara(String text, int alignment, int type) { Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK); Paragraph p = new Paragraph(text, font); p.setAlignment(alignment); p.setLeading(font.getSize() * 1.2f); return p; }
public static WidgetedTypesafeList determineEditablyPasteableFontFamilyNames() { getFontMapper(); // makes sure FontFactory has been initialized WidgetedTypesafeList list = new WidgetedTypesafeList(String.class); list.addAll(FontFactory.getRegisteredFamilies()); Collections.sort(list); return list; }
protected static synchronized void registerFonts () { if (!fontsRegistered) { List<PropertySuffix> fontFiles = JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).getProperties(PDF_FONT_FILES_PREFIX);//FIXMECONTEXT no default here and below if (!fontFiles.isEmpty()) { for (Iterator<PropertySuffix> i = fontFiles.iterator(); i.hasNext();) { JRPropertiesUtil.PropertySuffix font = i.next(); String file = font.getValue(); if (file.toLowerCase().endsWith(".ttc")) { FontFactory.register(file); } else { String alias = font.getSuffix(); FontFactory.register(file, alias); } } } List<PropertySuffix> fontDirs = JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).getProperties(PDF_FONT_DIRS_PREFIX); if (!fontDirs.isEmpty()) { for (Iterator<PropertySuffix> i = fontDirs.iterator(); i.hasNext();) { JRPropertiesUtil.PropertySuffix dir = i.next(); FontFactory.registerDirectory(dir.getValue()); } } fontsRegistered = true; } }
public boolean gravaPdf(File fArq) { Rectangle pageSize = new Rectangle(PageSize.A4); Document document = new Document(pageSize); try { PdfWriter.getInstance(document, new FileOutputStream(fArq)); document.addTitle(sTitulo); document.open(); Font font = FontFactory.getFont(FontFactory.COURIER, 6, Font.NORMAL, Color.black); for (int i = 1; i <= getNumPags(); ++i) { Paragraph paragrafo = new Paragraph(lePagina(i), font); document.add(paragrafo); if (bImpEject) { document.newPage(); } } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (Exception ioe) { System.err.println(ioe.getMessage()); } document.close(); return true; }
public void contextInitialized(ServletContextEvent event) { System.out.println(FontFactory.getRegisteredFonts()); System.out.println("------------------------------"); System.out.println(FontFactory.getFont("times-roman").hashCode()); String fontFolder = event.getServletContext().getRealPath("font"); FontFactory.register(fontFolder+"/Aller_Rg.ttf","times-roman"); FontFactory.register(fontFolder+"/Aller_BdIt.ttf","times-bolditalic"); FontFactory.register(fontFolder+"/Aller_Bd.ttf","times-bold"); FontFactory.register(fontFolder+"/Aller_It.ttf","times-italic"); System.out.println(FontFactory.getFont("times-roman").hashCode()); System.out.println(FontFactory.getRegisteredFonts()); }
public void contextInitialized(ServletContextEvent event) { LOGGER.debug(FontFactory.getRegisteredFonts().toString()); String fontFolder = event.getServletContext().getRealPath("font"); LOGGER.debug("fontFolder {}", fontFolder); FontFactory.registerDirectory(fontFolder); LOGGER.info(FontFactory.getRegisteredFonts().toString()); }
private void loadFonts() { ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader"); String pathNunitoDir = classLoader.getResource("default-fonts").toString() + "nunito" + System.getProperty("file.separator") + "ttf" + System.getProperty("file.separator"); FontFactory.register(pathNunitoDir + "Nunito-Bold.ttf", "nunito-bold"); FontFactory.register(pathNunitoDir + "Nunito-Light.ttf", "nunito-light"); FontFactory.register(pathNunitoDir + "Nunito-Regular.ttf", "nunito-regular"); fontTitle.setFamily("nunito"); fontTitle.setSize(14); fontTitle.setColor(blanco); fontTitle.setStyle(Font.BOLD); fontNormal.setFamily("nunito"); fontNormal.setSize(12); fontNormal.setColor(negro); fontHeaders.setFamily("nunito"); fontHeaders.setSize(11); fontHeaders.setColor(negro); fontHeaders.setStyle(Font.BOLD); fontTitleModule.setFamily("nunito"); fontTitleModule.setSize(12); fontTitleModule.setColor(rojo); }
/** * Effectue le rendu des headers. * * @param table * MBasicTable * @param datatable * Table * @throws BadElementException * e */ protected void renderHeaders(final MBasicTable table, final Table datatable) throws BadElementException { final int columnCount = table.getColumnCount(); final TableColumnModel columnModel = table.getColumnModel(); // size of columns float totalWidth = 0; for (int i = 0; i < columnCount; i++) { totalWidth += columnModel.getColumn(i).getWidth(); } final float[] headerwidths = new float[columnCount]; for (int i = 0; i < columnCount; i++) { headerwidths[i] = 100f * columnModel.getColumn(i).getWidth() / totalWidth; } datatable.setWidths(headerwidths); datatable.setWidth(100f); // table header final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // datatable.setDefaultCellGrayFill(0.75f); String text; Object value; for (int i = 0; i < columnCount; i++) { value = columnModel.getColumn(i).getHeaderValue(); text = value != null ? value.toString() : ""; datatable.addCell(new Phrase(text, font)); } // end of the table header datatable.endHeaders(); }
/** * Effectue le rendu de la liste. * * @param table * MBasicTable * @param datatable * Table * @throws BadElementException * e */ protected void renderList(final MBasicTable table, final Table datatable) throws BadElementException { final int columnCount = table.getColumnCount(); final int rowCount = table.getRowCount(); // data rows final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); // datatable.setDefaultCellGrayFill(0); Object value; String text; int horizontalAlignment; for (int k = 0; k < rowCount; k++) { for (int i = 0; i < columnCount; i++) { value = getValueAt(table, k, i); if (value instanceof Number || value instanceof Date) { horizontalAlignment = Element.ALIGN_RIGHT; } else if (value instanceof Boolean) { horizontalAlignment = Element.ALIGN_CENTER; } else { horizontalAlignment = Element.ALIGN_LEFT; } datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment); text = getTextAt(table, k, i); datatable.addCell(new Phrase(8, text != null ? text : "", font)); } } }
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter */ @Override protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) { final RtfWriter2 writer = RtfWriter2.getInstance(document, out); // title final String title = buildTitle(table); if (title != null) { final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title)); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } // advanced page numbers : x/y final Paragraph footerParagraph = new Paragraph(); final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); footerParagraph.add(new RtfPageNumber(font)); footerParagraph.add(new Phrase(" / ", font)); footerParagraph.add(new RtfTotalPageNumber(font)); footerParagraph.setAlignment(Element.ALIGN_CENTER); final HeaderFooter footer = new RtfHeaderFooter(footerParagraph); footer.setBorder(Rectangle.TOP); document.setFooter(footer); return writer; }
/** Creates a new instance of HTMLWorker */ public HTMLWorker(DocListener document) { this.document = document; cprops = new ChainedProperties(); String fontName = ServerConfigurationService.getString("pdf.default.font"); if (StringUtils.isNotBlank(fontName)) { FontFactory.registerDirectories(); if (FontFactory.isRegistered(fontName)) { HashMap fontProps = new HashMap(); fontProps.put(ElementTags.FACE, fontName); fontProps.put("encoding", BaseFont.IDENTITY_H); cprops.addToChain("face", fontProps); } } }
/** * Initialize the main info holder table. * * @throws BadElementException * for errors during table initialization */ protected void initTable() throws BadElementException { tablePDF = new Table(this.model.getNumberOfColumns()); tablePDF.setDefaultVerticalAlignment(Element.ALIGN_TOP); tablePDF.setCellsFitPage(true); tablePDF.setWidth(100); tablePDF.setPadding(2); tablePDF.setSpacing(0); // smallFont = FontFactory.getFont(FontFactory.HELVETICA, 7, // Font.NORMAL, new Color(0, 0, 0)); smallFont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", Font.DEFAULTSIZE); }