Java Code Examples for com.lowagie.text.FontFactory#getFont()
The following examples show how to use
com.lowagie.text.FontFactory#getFont() .
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: AccountSummaryController.java From primefaces-blueprints with The Unlicense | 6 votes |
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 2
Source File: TransactionSummaryController.java From primefaces-blueprints with The Unlicense | 6 votes |
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 3
Source File: CustomerLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
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: CustomerLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
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 5
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
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 6
Source File: PdfWatermarkUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
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 7
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: FontFactoryStylesTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 9
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Helper method to create a Header Cell from text * * @returns {@link Cell} with the header flag set */ protected Cell getHeaderCell(final String text) throws BadElementException { final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); final Cell retval = new Cell(new Chunk(text, headerFont)); retval.setBorder(NO_BORDER); retval.setHeader(true); return retval; }
Example 10
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Helper method to create a Header Cell from text * * @returns {@link Cell} with the header flag set */ protected Cell getBorderlessCell(final String text) throws BadElementException { final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); final Cell retval = new Cell(new Chunk(text, normalFont)); retval.setBorder(NO_BORDER); return retval; }
Example 11
Source File: MultiColumnSimpleTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
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 12
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 13
Source File: RemoteGotoTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates documents with Remote Goto functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter writerA = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("DocumentA.pdf")); PdfWriter writerB = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("DocumentB.pdf")); // step 3: we open the document document.open(); // step 4: // we create some content // a paragraph with a link to an external url Paragraph p1 = new Paragraph("You can turn a Chunk into an ", FontFactory.getFont(FontFactory.HELVETICA, 12)); p1.add(new Chunk("anchor", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))) .setAnchor(new URL("http://www.lowagie.com/iText/"))); p1.add(", for instance to the iText site."); // some paragraph Paragraph p2 = new Paragraph("blah, blah, blah"); // two paragraphs with a local destination Paragraph p3a = new Paragraph("This paragraph contains a "); p3a.add(new Chunk("local destination in document A", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 255, 0))).setLocalDestination("test")); Paragraph p3b = new Paragraph("This paragraph contains a "); p3b.add(new Chunk("local destination in document B", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 255, 0))).setLocalDestination("test")); // two paragraphs with a remote goto Paragraph p4a = new Paragraph( new Chunk("Click this paragraph to go to a certain destination on document B").setRemoteGoto( "DocumentB.pdf", "test")); Paragraph p4b = new Paragraph( new Chunk("Click this paragraph to go to a certain destination on document A").setRemoteGoto( "DocumentA.pdf", "test")); // a special remote goto Paragraph p5a = new Paragraph("you can also jump to a "); p5a.add(new Chunk("specific page on another document", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC)).setRemoteGoto("DocumentB.pdf", 3)); // we add all the content document.add(p1); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); // only for DocumentB.pdf: writerA.pause(); document.add(p4b); writerA.resume(); // only for DocumentA.pdf: writerB.pause(); document.add(p4a); document.add(p5a); writerB.resume(); // for both documents: document.add(p2); document.add(p2); document.add(p2); document.add(p2); // only for DocumentB.pdf: writerA.pause(); document.add(p3b); document.add(p2); document.add(p2); document.newPage(); document.add(p2); document.add(p2); document.newPage(); writerA.resume(); // only for documentA.pdf writerB.pause(); document.add(p3a); writerB.resume(); // for both documents document.add(p2); document.add(p2); // step 5: we close the document document.close(); }
Example 14
Source File: RepeatingTableTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Shows how a table is split if it doesn't fit the page. */ @Test public void main() throws Exception { // creation of the document with a certain size and certain margins Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); // creation of the different writers PdfWriter.getInstance(document, PdfTestBase.getOutputStream("repeatingtable.pdf")); // we add some meta information to the document document.addAuthor("Alan Soukup"); document.addSubject("This is the result of a Test."); document.open(); Table datatable = new Table(10); int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 }; datatable.setWidths(headerwidths); datatable.setWidth(100); datatable.setPadding(3); // the first cell spans 10 columns Cell cell = new Cell(new Phrase("Administration -System Users Report", FontFactory.getFont( FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setLeading(30); cell.setColspan(10); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); datatable.addCell(cell); // These cells span 2 rows datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(1); datatable.addCell("User Id"); datatable.addCell("Name\nAddress"); datatable.addCell("Company"); datatable.addCell("Department"); datatable.addCell("Admin"); datatable.addCell("Data"); datatable.addCell("Expl"); datatable.addCell("Prod"); datatable.addCell("Proj"); datatable.addCell("Online"); // this is the end of the table header datatable.endHeaders(); datatable.getDefaultCell().setBorderWidth(1); for (int i = 1; i < 30; i++) { datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("myUserId"); datatable .addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name"); datatable.addCell("No Name Company"); datatable.addCell("D" + i); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); } document.add(new Paragraph("com.lowagie.text.Table - Cells split")); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells split\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.Table - Cells kept together")); datatable.setConvert2pdfptable(false); datatable.setCellsFitPage(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells kept together\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); // we close the document document.close(); }
Example 15
Source File: PhrasesTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrates how the class Phrase works. * */ @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("Phrases.pdf")); // step 3: we open the document document.open(); // step 4: Phrase phrase1 = new Phrase("(1) this is a phrase\n"); // In this example the leading is passed as a parameter Phrase phrase2 = new Phrase( 24, "(2) this is a phrase with leading 24. You can only see the difference if the line is long enough. Do you see it? There is more space between this line and the previous one.\n"); // When a Font is passed (explicitely or embedded in a chunk), // the default leading = 1.5 * size of the font Phrase phrase3 = new Phrase( "(3) this is a phrase with a red, normal font Courier, size 20. As you can see the leading is automatically changed.\n", FontFactory.getFont(FontFactory.COURIER, 20, Font.NORMAL, new Color(255, 0, 0))); Phrase phrase4 = new Phrase(new Chunk("(4) this is a phrase\n")); Phrase phrase5 = new Phrase(18, new Chunk( "(5) this is a phrase in Helvetica, bold, red and size 16 with a given leading of 18 points.\n", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)))); // A Phrase can contains several chunks with different fonts Phrase phrase6 = new Phrase("(6)"); Chunk chunk = new Chunk(" This is a font: "); phrase6.add(chunk); phrase6.add(new Chunk("Helvetica", FontFactory.getFont(FontFactory.HELVETICA, 12))); phrase6.add(chunk); phrase6.add(new Chunk("Times New Roman", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12))); phrase6.add(chunk); phrase6.add(new Chunk("Courier", FontFactory.getFont(FontFactory.COURIER, 12))); phrase6.add(chunk); phrase6.add(new Chunk("Symbol", FontFactory.getFont(FontFactory.SYMBOL, 12))); phrase6.add(chunk); phrase6.add(new Chunk("ZapfDingBats", FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12))); Phrase phrase7 = new Phrase("(7) if you don't add a newline yourself, all phrases are glued to eachother!"); document.add(phrase1); document.add(phrase2); document.add(phrase3); document.add(phrase4); document.add(phrase5); document.add(phrase6); document.add(phrase7); // step 5: we close the document document.close(); }
Example 16
Source File: LocalGotoTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates a document with a Local Goto and a Local Destination. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LocalGoto.pdf")); // step 3: we open the document document.open(); // step 4: // we make some content // a paragraph with a local goto Paragraph p1 = new Paragraph("We will do something special with this paragraph. If you click on ", FontFactory.getFont(FontFactory.HELVETICA, 12)); p1.add(new Chunk("this word", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))) .setLocalGoto("test")); p1.add(" you will automatically jump to another location in this document."); // some paragraph Paragraph p2 = new Paragraph("blah, blah, blah"); // a paragraph with a local destination Paragraph p3 = new Paragraph("This paragraph contains a "); p3.add(new Chunk("local destination", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 255, 0))).setLocalDestination("test")); // we add the content document.add(p1); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p2); document.add(p3); // step 5: we close the document document.close(); }
Example 17
Source File: MetaFont.java From gcs with Mozilla Public License 2.0 | 4 votes |
public BaseFont getFont() { if (font != null) return font; Font ff2 = FontFactory.getFont(faceName, BaseFont.CP1252, true, 10, ((italic != 0) ? Font.ITALIC : 0) | ((bold != 0) ? Font.BOLD : 0)); font = ff2.getBaseFont(); if (font != null) return font; String fontName; if (faceName.indexOf("courier") != -1 || faceName.indexOf("terminal") != -1 || faceName.indexOf("fixedsys") != -1) { fontName = fontNames[MARKER_COURIER + italic + bold]; } else if (faceName.indexOf("ms sans serif") != -1 || faceName.indexOf("arial") != -1 || faceName.indexOf("system") != -1) { fontName = fontNames[MARKER_HELVETICA + italic + bold]; } else if (faceName.indexOf("arial black") != -1) { fontName = fontNames[MARKER_HELVETICA + italic + MARKER_BOLD]; } else if (faceName.indexOf("times") != -1 || faceName.indexOf("ms serif") != -1 || faceName.indexOf("roman") != -1) { fontName = fontNames[MARKER_TIMES + italic + bold]; } else if (faceName.indexOf("symbol") != -1) { fontName = fontNames[MARKER_SYMBOL]; } else { int pitch = pitchAndFamily & 3; int family = (pitchAndFamily >> 4) & 7; switch (family) { case FF_MODERN: fontName = fontNames[MARKER_COURIER + italic + bold]; break; case FF_ROMAN: fontName = fontNames[MARKER_TIMES + italic + bold]; break; case FF_SWISS: case FF_SCRIPT: case FF_DECORATIVE: fontName = fontNames[MARKER_HELVETICA + italic + bold]; break; default: { switch (pitch) { case FIXED_PITCH: fontName = fontNames[MARKER_COURIER + italic + bold]; break; default: fontName = fontNames[MARKER_HELVETICA + italic + bold]; break; } } } } try { font = BaseFont.createFont(fontName, "Cp1252", false); } catch (Exception e) { throw new ExceptionConverter(e); } return font; }
Example 18
Source File: StudentCardTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generates a StudentCard */ @Test public void main() throws Exception { // step 1: creation of a document-object Rectangle rect = new Rectangle(243, 153); rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC)); Document document = new Document(rect, 10, 10, 10, 10); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf")); // step 3: we open the document document.open(); // step 4: Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE); Paragraph p = new Paragraph("Ghent University", font); p.setAlignment(Element.ALIGN_CENTER); document.add(p); PdfContentByte cb = writer.getDirectContent(); Font f = FontFactory.getFont(FontFactory.HELVETICA, 8); PdfPTable outertable = new PdfPTable(3); outertable.setTotalWidth(200); outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] outer = { 60, 25, 15 }; outertable.setWidths(outer); PdfPTable innertable = new PdfPTable(2); float[] inner = { 35, 65 }; innertable.setWidths(inner); innertable.addCell(new Paragraph("name:", f)); innertable.addCell(new Paragraph("Bruno Lowagie", f)); innertable.addCell(new Paragraph("date of birth:", f)); innertable.addCell(new Paragraph("June 10th, 1970", f)); innertable.addCell(new Paragraph("Study Program:", f)); innertable.addCell(new Paragraph("master in civil engineering", f)); innertable.addCell(new Paragraph("option:", f)); innertable.addCell(new Paragraph("architecture", f)); outertable.addCell(innertable); outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD)); outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg")); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN13); codeEAN.setCode("8010012529736"); Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null); imageEAN.setRotationDegrees(90); outertable.getDefaultCell().setBackgroundColor(Color.WHITE); outertable.addCell(imageEAN); outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent()); // step 5: we close the document document.close(); }
Example 19
Source File: RtfDestinationDocument.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
public void beforePropertyChange(String propertyName) { // do we have any text to do anything with? // if not, then just return without action. if(this.buffer.length() == 0) return; if(propertyName.startsWith(RtfProperty.CHARACTER)) { // this is a character change, // add a new chunk to the current paragraph using current character settings. Chunk chunk = new Chunk(); chunk.append(this.buffer.toString()); this.buffer = new StringBuffer(255); HashMap charProperties = this.rtfParser.getState().properties.getProperties(RtfProperty.CHARACTER); String defFont = (String)charProperties.get(RtfProperty.CHARACTER_FONT); if(defFont == null) defFont = "0"; RtfDestinationFontTable fontTable = (RtfDestinationFontTable)this.rtfParser.getDestination("fonttbl"); Font currFont = fontTable.getFont(defFont); int fs = Font.NORMAL; if(charProperties.containsKey(RtfProperty.CHARACTER_BOLD)) fs |= Font.BOLD; if(charProperties.containsKey(RtfProperty.CHARACTER_ITALIC)) fs |= Font.ITALIC; if(charProperties.containsKey(RtfProperty.CHARACTER_UNDERLINE)) fs |= Font.UNDERLINE; Font useFont = FontFactory.getFont(currFont.getFamilyname(), 12, fs, new Color(0,0,0)); chunk.setFont(useFont); if(iTextParagraph == null) this.iTextParagraph = new Paragraph(); this.iTextParagraph.add(chunk); } else { if(propertyName.startsWith(RtfProperty.PARAGRAPH)) { // this is a paragraph change. what do we do? } else { if(propertyName.startsWith(RtfProperty.SECTION)) { } else { if(propertyName.startsWith(RtfProperty.DOCUMENT)) { } } } } }
Example 20
Source File: MetaFont.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
public BaseFont getFont() { if (font != null) return font; Font ff2 = FontFactory.getFont(faceName, BaseFont.CP1252, true, 10, ((italic != 0) ? Font.ITALIC : 0) | ((bold != 0) ? Font.BOLD : 0)); font = ff2.getBaseFont(); if (font != null) return font; String fontName; if (faceName.indexOf("courier") != -1 || faceName.indexOf("terminal") != -1 || faceName.indexOf("fixedsys") != -1) { fontName = fontNames[MARKER_COURIER + italic + bold]; } else if (faceName.indexOf("ms sans serif") != -1 || faceName.indexOf("arial") != -1 || faceName.indexOf("system") != -1) { fontName = fontNames[MARKER_HELVETICA + italic + bold]; } else if (faceName.indexOf("arial black") != -1) { fontName = fontNames[MARKER_HELVETICA + italic + MARKER_BOLD]; } else if (faceName.indexOf("times") != -1 || faceName.indexOf("ms serif") != -1 || faceName.indexOf("roman") != -1) { fontName = fontNames[MARKER_TIMES + italic + bold]; } else if (faceName.indexOf("symbol") != -1) { fontName = fontNames[MARKER_SYMBOL]; } else { int pitch = pitchAndFamily & 3; int family = (pitchAndFamily >> 4) & 7; switch (family) { case FF_MODERN: fontName = fontNames[MARKER_COURIER + italic + bold]; break; case FF_ROMAN: fontName = fontNames[MARKER_TIMES + italic + bold]; break; case FF_SWISS: case FF_SCRIPT: case FF_DECORATIVE: fontName = fontNames[MARKER_HELVETICA + italic + bold]; break; default: { switch (pitch) { case FIXED_PITCH: fontName = fontNames[MARKER_COURIER + italic + bold]; break; default: fontName = fontNames[MARKER_HELVETICA + italic + bold]; break; } } } } try { font = BaseFont.createFont(fontName, "Cp1252", false); } catch (Exception e) { throw new ExceptionConverter(e); } return font; }