com.lowagie.text.FontFactory Java Examples

The following examples show how to use com.lowagie.text.FontFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
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 );
}
 
Example #3
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
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 );
}
 
Example #5
Source File: LockboxServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #6
Source File: LockboxServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #7
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
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);
}
 
Example #9
Source File: RtfDestinationFontTable.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #11
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #12
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #13
Source File: FontMappingManagerFactory.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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;
		}
	} );
}
 
Example #14
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: MultiColumnSimpleTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: FontFactoryType1FontsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #17
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
	 Document pdf = (Document) document; 
	 pdf.add( Chunk.NEWLINE );
	 Font fontbold = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
	 pdf.add(new Paragraph("Disclaimer",fontbold));
	 pdf.add( Chunk.NEWLINE );
	 pdf.add(new Paragraph("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."));
	 pdf.add(new Paragraph("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "));
}
 
Example #18
Source File: RtfDestinationFontTable.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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
	}

}
 
Example #19
Source File: FontFactoryStylesTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #20
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example #21
Source File: PdfWatermarkUtils.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
	FontFactory.register("fonts/fireflysung.ttf"); // fonts/fireflysung.ttf in fireflysung.jar
	Font font = FontFactory.getFont("fonts/fireflysung.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
	PdfReader pdfReader = new PdfReader("/tmp/ex/test.pdf");
	PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("/tmp/ex/test-out.pdf"));
	addWatermark(pdfStamper, font.getBaseFont(), Color.RED, "測試");
	pdfStamper.close();
}
 
Example #22
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #23
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
		}
	}
}
 
Example #24
Source File: MRtfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/** 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);
		}
	}
}
 
Example #26
Source File: cfDOCUMENT.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static void init( xmlCFML configFile ) {
	String fontDirs = cfEngine.getConfig().getString( "server.fonts.dirs", "" );
	
	if ( fontDirs.length() == 0 ) { // no fonts configured, set defaults
		StringBuilder defaultFontDirsList = new StringBuilder();
		if ( cfEngine.WINDOWS ) {
			for ( int i = 0; i < defaultWindowsFontDirs.length; i++ ) {
				if ( FileUtils.exists( defaultWindowsFontDirs[ i ] ) ) {
					if ( defaultFontDirsList.length() > 0 ) { // not the first
						defaultFontDirsList.append( ',' );
					}
					defaultFontDirsList.append( defaultWindowsFontDirs[ i ] );
				}
			}
		} else {
			for ( int i = 0; i < defaultOtherFontDirs.length; i++ ) {
				if ( FileUtils.exists( defaultOtherFontDirs[ i ] ) ) {
					if ( defaultFontDirsList.length() > 0 ) { // not the first
						defaultFontDirsList.append( ',' );
					}
					defaultFontDirsList.append( defaultOtherFontDirs[ i ] );
				}
			}
		}
		
		if ( defaultFontDirsList.length() > 0 ) {
			cfEngine.getConfig().setData( "server.fonts.dirs", defaultFontDirsList.toString() );
		}
		fontDirs = defaultFontDirsList.toString();
	}
	
	
	defaultFontDirs = fontDirs.split(",");
	for ( int i = 0; i < defaultFontDirs.length; i++ ){
		FontFactory.registerDirectory( defaultFontDirs[i].toString() );
	}
	
}
 
Example #27
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates instructions section of the coverpage
 *
 * @returns a {@link Paragraph} for the PDF
 */
protected Paragraph getInstructionsParagraph() {
    final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    final Paragraph retval = new Paragraph();
    retval.add(new Chunk("Instructions", headerFont));
    retval.add(Chunk.NEWLINE);
    retval.add(new Phrase(getInstructions(), normalFont));
    return retval;
}
 
Example #28
Source File: RegisterFontFactorytListener.java    From xdocreport.samples with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());

}
 
Example #29
Source File: RegisterFontFactorytListener.java    From xdocreport.samples with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #30
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void writeFileNameSectionTitle(com.lowagie.text.Document pdfDoc, String filenameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    //  file name title, get title only, on windows & unix platforms
    String fileNameOnly = filenameLine.toUpperCase();
    int indexOfSlashes = fileNameOnly.lastIndexOf("\\");
    if (indexOfSlashes < fileNameOnly.length()) {
        fileNameOnly = fileNameOnly.substring(indexOfSlashes + 1);
    }
    indexOfSlashes = fileNameOnly.lastIndexOf("/");
    if (indexOfSlashes < fileNameOnly.length()) {
        fileNameOnly = fileNameOnly.substring(indexOfSlashes + 1);
    }

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(fileNameOnly, 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);
    }
}