List of usage examples for com.lowagie.text FontFactory getFont
public static Font getFont(String fontname, float size, int style)
Font
-object. From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Effectue le rendu des headers.//from w ww .j a v a2 s .c om * * @param parameters Paramtres * @param datatable Table */ private static void renderHeaders(final ExportSheet parameters, final Table datatable) throws BadElementException { // table header final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (final ExportField exportColumn : parameters.getExportFields()) { datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font)); } // end of the table header datatable.endHeaders(); }
From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Effectue le rendu de la liste.//from ww w . ja v a 2s . c o m * * @param parameters Paramtres * @param datatable Table */ private void renderList(final ExportSheet parameters, final Table datatable) throws BadElementException { // data rows final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); final Font whiteFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); whiteFont.setColor(Color.WHITE); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); // Parcours des DTO de la DTC for (final DtObject dto : parameters.getDtList()) { for (final ExportField exportColumn : parameters.getExportFields()) { final DtField dtField = exportColumn.getDtField(); final Object value = dtField.getDataAccessor().getValue(dto); final int horizontalAlignement; if (value instanceof Number || value instanceof LocalDate || value instanceof Instant) { horizontalAlignement = Element.ALIGN_RIGHT; } else if (value instanceof Boolean) { horizontalAlignement = Element.ALIGN_CENTER; } else { horizontalAlignement = Element.ALIGN_LEFT; } datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement); String text = ExportUtil.getText(storeManager, referenceCache, denormCache, dto, exportColumn); if (text == null) { text = ""; } datatable.addCell(new Phrase(8, text, font)); } } }
From source file:io.vertigo.quarto.plugins.export.rtf.RTFExporter.java
License:Apache License
/** {@inheritDoc} */ @Override//from ww w. j a va 2 s .c o m protected void createWriter(final Document document, final OutputStream out) { RtfWriter2.getInstance(document, out); // advanced page numbers : x/y final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); //----- final Paragraph footerParagraph = new Paragraph(); 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); }
From source file:jmemorize.core.io.PdfRtfBuilder.java
License:Open Source License
private static void export(Lesson lesson, int mode, File file) throws IOException { logger = Main.getLogger();//w w w . ja va 2s . c o m FontFactory.registerDirectories(); // set up the fonts we will use to write the front and back of cards String frontFontName = Settings.loadFont(FontType.CARD_FRONT).getFont().getFamily(); frontFont = FontFactory.getFont(frontFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (frontFont == null) { logger.warning("FontFactory returned null (front) font for: " + frontFontName); } String backFontName = Settings.loadFont(FontType.CARD_FLIP).getFont().getFamily(); backFont = FontFactory.getFont(backFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (backFont == null) { logger.warning("FontFactory returned null (back) font for: " + backFontName); } try { Document doc = new Document(); OutputStream out = new FileOutputStream(file); switch (mode) { case PDF_MODE: PdfWriter.getInstance(doc, out); break; case RTF_MODE: RtfWriter2.getInstance(doc, out); break; } doc.setHeader(new HeaderFooter(new Phrase(file.getName()), false)); doc.open(); // add cards in subtrees List<Category> subtree = lesson.getRootCategory().getSubtreeList(); for (Category category : subtree) { writeCategory(doc, category); } doc.close(); } catch (Throwable t) { throw (IOException) new IOException("Could not export to PDF").initCause(t); } }
From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java
License:Apache License
private void writeGraphs(Collection<JRobin> jrobins, Map<String, byte[]> mySmallGraphs) throws IOException, DocumentException { if (collector.isStopped()) { // pas de graphs, ils seraient en erreur sans timer // mais un message d'avertissement la place final String message = getString("collect_server_misusage"); final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph);// w ww . java2s .c om return; } if (collector.isStorageUsedByMultipleInstances()) { final String message = getString("storage_used_by_multiple_instances") + "\n\n"; final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph); } final Paragraph jrobinParagraph = new Paragraph("", FontFactory.getFont(FontFactory.HELVETICA, 9f, Font.NORMAL)); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); jrobinParagraph.add(new Phrase("\n\n\n\n")); final Collection<byte[]> graphs; if (mySmallGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise graphs = mySmallGraphs.values(); } else { if (jrobins.isEmpty()) { return; } graphs = new ArrayList<byte[]>(jrobins.size()); for (final JRobin jrobin : jrobins) { graphs.add(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT)); } } int i = 0; for (final byte[] graph : graphs) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(graph); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } jrobinParagraph.add(new Phrase("\n")); addToDocument(jrobinParagraph); }
From source file:net.bull.javamelody.internal.web.pdf.PdfFonts.java
License:Apache License
private static Font getFont(float size, int style) { return FontFactory.getFont(FontFactory.HELVETICA, size, style); }
From source file:net.bull.javamelody.PdfCoreReport.java
License:Apache License
private void writeGraphs(Collection<JRobin> jrobins, Map<String, byte[]> mySmallGraphs) throws IOException, DocumentException { if (collector.isStopped()) { // pas de graphs, ils seraient en erreur sans timer // mais un message d'avertissement la place final String message = getString("collect_server_misusage"); final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont()); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); addToDocument(jrobinParagraph);// ww w . j a v a 2s.c o m return; } final Paragraph jrobinParagraph = new Paragraph("", FontFactory.getFont(FontFactory.HELVETICA, 9f, Font.NORMAL)); jrobinParagraph.setAlignment(Element.ALIGN_CENTER); jrobinParagraph.add(new Phrase("\n\n\n\n")); int i = 0; if (mySmallGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise for (final byte[] imageData : mySmallGraphs.values()) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(imageData); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } } else { if (jrobins.isEmpty()) { return; } for (final JRobin jrobin : jrobins) { if (i % 3 == 0 && i != 0) { // un retour aprs httpSessions et avant activeThreads pour l'alignement jrobinParagraph.add(new Phrase("\n\n\n\n\n")); } final Image image = Image.getInstance(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT)); image.scalePercent(50); jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0))); jrobinParagraph.add(new Phrase(" ")); i++; } } jrobinParagraph.add(new Phrase("\n")); addToDocument(jrobinParagraph); }
From source file:net.bull.javamelody.swing.print.MPdfWriter.java
License:Apache License
/** * Effectue le rendu des headers.// ww w . j a v a2 s .c om * * @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 com.lowagie.text.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(); }
From source file:net.bull.javamelody.swing.print.MPdfWriter.java
License:Apache License
/** * Effectue le rendu de la liste.//from ww w . j av a2 s . c o m * * @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)); } } }
From source file:net.bull.javamelody.swing.print.MRtfWriter.java
License:Apache License
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table/*from w w w.j a v a 2 s. co m*/ * 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; }