Java Code Examples for com.lowagie.text.Font#BOLD
The following examples show how to use
com.lowagie.text.Font#BOLD .
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: OptionalContentTest.java From itext2 with GNU Lesser General Public License v3.0 | 7 votes |
/** * Demonstrates the use of layers. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("optionalcontent.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3: opening the document document.open(); // step 4: content PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase( "Automatic layers, form fields, images, templates and actions", new Font(Font.HELVETICA, 18, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620), "field1"); ff.setBorderColor(Color.blue); ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); ff.setBorderWidth(TextField.BORDER_WIDTH_THIN); ff.setText("I'm a form field"); PdfFormField form = ff.getTextField(); form.setLayer(l4); writer.addAnnotation(form); Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png"); img.setLayer(l4); img.setAbsolutePosition(200, 550); cb.addImage(img); PdfTemplate tp = cb.createTemplate(100, 20); Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12, Font.NORMAL, Color.magenta)); ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0); tp.setLayer(l4); tp.setBoundingBox(new Rectangle(0, -10, 100, 20)); cb.addTemplate(tp, 200, 500); ArrayList<Object> state = new ArrayList<Object>(); state.add("toggle"); state.add(l1); state.add(l2); state.add(l3); state.add(l4); PdfAction action = PdfAction.setOCGstate(state, true); Chunk ck = new Chunk("Click here to toggle the layers", new Font( Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground( Color.blue).setAction(action); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck), 250, 400, 0); cb.sanityCheck(); // step 5: closing the document document.close(); }
Example 2
Source File: PropertyUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
public static int getFontStyle( String fontStyle, String fontWeight ) { int styleValue = Font.NORMAL; if ( CSSConstants.CSS_OBLIQUE_VALUE.equals( fontStyle ) || CSSConstants.CSS_ITALIC_VALUE.equals( fontStyle ) ) { styleValue |= Font.ITALIC; } if ( CSSConstants.CSS_BOLD_VALUE.equals( fontWeight ) || CSSConstants.CSS_BOLDER_VALUE.equals( fontWeight ) || CSSConstants.CSS_600_VALUE.equals( fontWeight ) || CSSConstants.CSS_700_VALUE.equals( fontWeight ) || CSSConstants.CSS_800_VALUE.equals( fontWeight ) || CSSConstants.CSS_900_VALUE.equals( fontWeight ) ) { styleValue |= Font.BOLD; } return styleValue; }
Example 3
Source File: PdfOutline.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns the PDF representation of this <CODE>PdfOutline</CODE>. * * @param writer the encryption information * @param os * @throws IOException */ public void toPdf(PdfWriter writer, OutputStream os) throws IOException { if (color != null && !color.equals(Color.black)) { put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f})); } int flag = 0; if ((style & Font.BOLD) != 0) flag |= 2; if ((style & Font.ITALIC) != 0) flag |= 1; if (flag != 0) put(PdfName.F, new PdfNumber(flag)); if (parent != null) { put(PdfName.PARENT, parent.indirectReference()); } if (destination != null && destination.hasPage()) { put(PdfName.DEST, destination); } if (action != null) put(PdfName.A, action); if (count != 0) { put(PdfName.COUNT, new PdfNumber(count)); } super.toPdf(writer, os); }
Example 4
Source File: RTFTextExtractor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public void add( final String text ) { int style = Font.NORMAL; if ( bold ) { style |= Font.BOLD; } if ( italic ) { style |= Font.ITALIC; } if ( strikethrough ) { style |= Font.STRIKETHRU; } if ( underline ) { style |= Font.UNDERLINE; } final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics( fontName, fontSize, bold, italic, "utf-8", false, false ); final BaseFont baseFont = fontMetrics.getBaseFont(); final Font font = new Font( baseFont, (float) fontSize, style, textColor ); final Chunk c = new Chunk( text, font ); if ( backgroundColor != null ) { c.setBackground( backgroundColor ); } target.add( c ); }
Example 5
Source File: ExtendedFontTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Extended font example. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFont.rtf")); document.open(); // Create a RtfFont with the desired font name. RtfFont msComicSans = new RtfFont("Comic Sans MS"); // Use the RtfFont like any other Font. document.add(new Paragraph("This paragraph uses the" + " Comic Sans MS font.", msComicSans)); // Font size, font style and font colour can also be specified. RtfFont bigBoldGreenArial = new RtfFont("Arial", 36, Font.BOLD, Color.GREEN); document.add(new Paragraph("This is a really big bold green Arial text", bigBoldGreenArial)); document.close(); }
Example 6
Source File: PdfOutline.java From MesquiteCore with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns the PDF representation of this <CODE>PdfOutline</CODE>. * * @param writer the encryption information * @param os * @throws IOException */ public void toPdf(PdfWriter writer, OutputStream os) throws IOException { if (color != null && !color.equals(Color.black)) { put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f})); } int flag = 0; if ((style & Font.BOLD) != 0) flag |= 2; if ((style & Font.ITALIC) != 0) flag |= 1; if (flag != 0) put(PdfName.F, new PdfNumber(flag)); if (parent != null) { put(PdfName.PARENT, parent.indirectReference()); } if (destination != null && destination.hasPage()) { put(PdfName.DEST, destination); } if (action != null) put(PdfName.A, action); if (count != 0) { put(PdfName.COUNT, new PdfNumber(count)); } super.toPdf(writer, os); }
Example 7
Source File: PPTXCanvas.java From birt with Eclipse Public License 1.0 | 5 votes |
private void setTextProperty( String fontName, float fontSize, int fontStyle, Color color, boolean isUnderline, boolean isLineThrough, HyperlinkDef link ) { writer.openTag( "a:rPr" ); writer.attribute( "lang", "en-US" ); writer.attribute( "altLang", "zh-CN" ); writer.attribute( "dirty", "0" ); writer.attribute( "smtClean", "0" ); if ( isLineThrough ) { writer.attribute( "strike", "sngStrike" ); } if ( isUnderline ) { writer.attribute( "u", "sng" ); } writer.attribute( "sz", (int) ( fontSize * 100 ) ); boolean isItalic = ( fontStyle & Font.ITALIC ) != 0; boolean isBold = ( fontStyle & Font.BOLD ) != 0; if ( isItalic ) { writer.attribute( "i", 1 ); } if ( isBold ) { writer.attribute( "b", 1 ); } setBackgroundColor( color ); setTextFont( fontName ); setHyperlink( link ); writer.closeTag( "a:rPr" ); }
Example 8
Source File: FactoryProperties.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
public Font getFont(ChainedProperties props) { String face = props.getProperty(ElementTags.FACE); if (face != null) { StringTokenizer tok = new StringTokenizer(face, ","); while (tok.hasMoreTokens()) { face = tok.nextToken().trim(); if (face.startsWith("\"")) face = face.substring(1); if (face.endsWith("\"")) face = face.substring(0, face.length() - 1); if (fontImp.isRegistered(face)) break; } } int style = 0; if (props.hasProperty(HtmlTags.I)) style |= Font.ITALIC; if (props.hasProperty(HtmlTags.B)) style |= Font.BOLD; if (props.hasProperty(HtmlTags.U)) style |= Font.UNDERLINE; if (props.hasProperty(HtmlTags.S)) style |= Font.STRIKETHRU; String value = props.getProperty(ElementTags.SIZE); float size = 12; if (value != null) size = Float.parseFloat(value); Color color = Markup.decodeColor(props.getProperty("color")); String encoding = props.getProperty("encoding"); if (encoding == null) encoding = BaseFont.WINANSI; return fontImp.getFont(face, encoding, true, size, style, color); }
Example 9
Source File: PdfOutline.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Returns the PDF representation of this <CODE>PdfOutline</CODE>. * * @param writer the encryption information * @param os * @throws IOException */ @Override public void toPdf(PdfWriter writer, OutputStream os) throws IOException { if (color != null && !color.equals(Color.black)) { put(PdfName.C, new PdfArray(new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f })); } int flag = 0; if ((style & Font.BOLD) != 0) { flag |= 2; } if ((style & Font.ITALIC) != 0) { flag |= 1; } if (flag != 0) { put(PdfName.F, new PdfNumber(flag)); } if (parent != null) { put(PdfName.PARENT, parent.indirectReference()); } if (destination != null && destination.hasPage()) { put(PdfName.DEST, destination); } if (action != null) { put(PdfName.A, action); } if (count != 0) { put(PdfName.COUNT, new PdfNumber(count)); } super.toPdf(writer, os); }
Example 10
Source File: FontHandler.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * If the BaseFont can NOT find the correct physical glyph, we need to * simulate the proper style for the font. The "simulate" flag will be set * if we need to simulate it. */ private boolean needSimulate( BaseFont font ) { if ( fontStyle == Font.NORMAL ) { return false; } String[][] fullNames = bf.getFullFontName( ); String fullName = getEnglishName( fullNames ); String lcf = fullName.toLowerCase( ); int fs = Font.NORMAL; if ( lcf.indexOf( "bold" ) != -1 ) { fs |= Font.BOLD; } if ( lcf.indexOf( "italic" ) != -1 || lcf.indexOf( "oblique" ) != -1 ) { fs |= Font.ITALIC; } if ( ( fontStyle & Font.BOLDITALIC ) == fs ) { if ( fontWeight > 400 && fontWeight != 700 ) { // not a regular bold font. return true; } else { return false; } } return true; }
Example 11
Source File: AutomaticTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Automatic grouping and nesting. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("automatic.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Automatic layer grouping and nesting", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l12 = new PdfLayer("Layer nesting", writer); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer title = PdfLayer.createTitle("Layer grouping", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayer l4 = new PdfLayer("Layer 4", writer); l12.addChild(l1); l12.addChild(l2); title.addChild(l3); title.addChild(l4); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2"); Phrase p3 = new Phrase("Text in layer 3"); Phrase p4 = new Phrase("Text in layer 4"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(l2); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.beginLayer(l4); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0); cb.endLayer(); cb.sanityCheck(); // step 5 document.close(); }
Example 12
Source File: OdpPage.java From birt with Eclipse Public License 1.0 | 4 votes |
protected void drawText( String text, float textX, float textY, float baseline, float width, float height, TextStyle textStyle ) { // width of text is enlarged by 1 point because the text will be // automatically wrapped if the width of textbox equals to the width of // text exactly. FontInfo fontInfo = textStyle.getFontInfo( ); float descend = fontInfo.getBaseFont( ).getFontDescriptor( BaseFont.DESCENT, fontInfo.getFontSize( ) ); StyleEntry style = StyleBuilder.createEmptyStyleEntry( StyleConstant.TYPE_TEXT ); style.setProperty( StyleConstant.DIRECTION_PROP, textStyle.getDirection( ) ); style.setProperty( StyleConstant.COLOR_PROP, OdpUtil.getColorString( textStyle.getColor( ) ) ); style.setProperty( StyleConstant.LETTER_SPACING, new FloatValue( FloatValue.CSS_PT, textStyle.getLetterSpacing( ) / PDFConstants.LAYOUT_TO_PDF_RATIO ) ); if ( fontInfo != null ) { BaseFont baseFont = fontInfo.getBaseFont( ); String fontName = OdpUtil.getFontName( baseFont ); style.setProperty( StyleConstant.FONT_FAMILY_PROP, fontName ); style.setProperty( StyleConstant.FONT_SIZE_PROP, Double.valueOf( fontInfo.getFontSize( ) ) ); if (( fontInfo.getFontStyle( ) & Font.BOLD ) != 0 ) { style.setProperty( StyleConstant.FONT_WEIGHT_PROP, "bold" ); } if (( fontInfo.getFontStyle( ) & Font.ITALIC ) != 0) { style.setProperty( StyleConstant.FONT_STYLE_PROP, "italic" ); } if ( textStyle.isLinethrough( ) ) { style.setProperty( StyleConstant.TEXT_LINE_THROUGH_PROP, true ); } if ( textStyle.isOverline( ) ) { style.setProperty( StyleConstant.TEXT_OVERLINE_PROP, true ); } if ( textStyle.isUnderline( ) ) { style.setProperty( StyleConstant.TEXT_UNDERLINE_PROP, true ); } } // TODO: hyperlink context.addStyle( style ); writer.drawText( text, textX, textY, width, height + descend * 0.6f, textFrameStyle, style, link ); }
Example 13
Source File: PostscriptWriter.java From birt with Eclipse Public License 1.0 | 4 votes |
public void drawString( String str, float x, float y, FontInfo fontInfo, float letterSpacing, float wordSpacing, Color color, boolean linethrough, boolean overline, boolean underline, CSSValue align ) { y = transformY( y ); String text = str; boolean needSimulateItalic = false; boolean needSimulateBold = false; boolean hasSpace = wordSpacing != 0 || letterSpacing != 0; float offset = 0; if ( fontInfo != null ) { float fontSize = fontInfo.getFontSize( ); int fontStyle = fontInfo.getFontStyle( ); if ( fontInfo.getSimulation( ) ) { if ( fontStyle == Font.BOLD || fontStyle == Font.BOLDITALIC ) { offset = (float) ( fontSize * Math.log10( fontSize ) / 100 ); needSimulateBold = true; } if ( fontStyle == Font.ITALIC || fontStyle == Font.BOLDITALIC ) { needSimulateItalic = true; } } BaseFont baseFont = fontInfo.getBaseFont( ); String fontName = baseFont.getPostscriptFontName( ); text = applyFont( fontName, fontStyle, fontSize, text ); } outputColor( color ); out.print( x + " " + y + " " ); if ( hasSpace ) out.print( wordSpacing + " " + letterSpacing + " " ); out.print( text + " " ); if ( needSimulateBold ) out.print( offset + " " ); String command = getCommand( hasSpace, needSimulateBold, needSimulateItalic ); out.println( command ); }
Example 14
Source File: ContentGroupsTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrates how to group optional content. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "contentgroups.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.sanityCheck(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); PdfArray group = new PdfArray(); group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE)); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5 document.close(); }
Example 15
Source File: NestedLayersTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrates the use of nested layers * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("nestedlayers.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer nesting", new Font( Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l23 = new PdfLayer("Top Layer 2 3", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(l23); cb.beginLayer(l2); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.endLayer(); cb.sanityCheck(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); order.add(l23.getRef()); PdfArray group = new PdfArray(); group.add(l2.getRef()); group.add(l3.getRef()); order.add(group); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5 document.close(); }
Example 16
Source File: LayersTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Layer radio group and zoom. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "layers.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Layer radio group and zoom", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer title = PdfLayer.createTitle("Layer radio group", writer); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayer l4 = new PdfLayer("Layer 4", writer); title.addChild(l1); title.addChild(l2); title.addChild(l3); l4.setZoom(2, -1); l4.setOnPanel(false); l4.setPrint("Print", true); l2.setOn(false); l3.setOn(false); ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>(); radio.add(l1); radio.add(l2); radio.add(l3); writer.addOCGRadioGroup(radio); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2"); Phrase p3 = new Phrase("Text in layer 3"); Phrase p4 = new Phrase("Text in layer 4"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(l2); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.beginLayer(l4); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0); cb.endLayer(); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("<< Zoom here!", new Font(Font.COURIER, 12, Font.NORMAL, Color.blue)), 150, 450, 0); // step 5 document.close(); }
Example 17
Source File: OrderedLayersTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrates how to order optional content groups. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("orderedlayers.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase("Ordered layers", new Font( Font.HELVETICA, 20, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); cb.sanityCheck(); PdfOCProperties p = writer.getOCProperties(); PdfArray order = new PdfArray(); order.add(l1.getRef()); order.add(l2.getRef()); order.add(l3.getRef()); PdfDictionary d = new PdfDictionary(); d.put(PdfName.ORDER, order); p.put(PdfName.D, d); // step 5 document.close(); }
Example 18
Source File: HtmlWriter.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Writes the representation of a <CODE>Font</CODE>. * * @param font a <CODE>Font</CODE> * @param styleAttributes the style of the font * @throws IOException */ protected void write(Font font, Properties styleAttributes) throws IOException { if (font == null || !isOtherFont(font) /* || styleAttributes == null*/) return; write(" "); write(HtmlTags.STYLE); write("=\""); if (styleAttributes != null) { String key; for (Enumeration e = styleAttributes.propertyNames(); e.hasMoreElements(); ) { key = (String)e.nextElement(); writeCssProperty(key, styleAttributes.getProperty(key)); } } if (isOtherFont(font)) { writeCssProperty(Markup.CSS_KEY_FONTFAMILY, font.getFamilyname()); if (font.getSize() != Font.UNDEFINED) { writeCssProperty(Markup.CSS_KEY_FONTSIZE, font.getSize() + "pt"); } if (font.getColor() != null) { writeCssProperty(Markup.CSS_KEY_COLOR, HtmlEncoder.encode(font.getColor())); } int fontstyle = font.getStyle(); BaseFont bf = font.getBaseFont(); if (bf != null) { String ps = bf.getPostscriptFontName().toLowerCase(); if (ps.indexOf("bold") >= 0) { if (fontstyle == Font.UNDEFINED) fontstyle = 0; fontstyle |= Font.BOLD; } if (ps.indexOf("italic") >= 0 || ps.indexOf("oblique") >= 0) { if (fontstyle == Font.UNDEFINED) fontstyle = 0; fontstyle |= Font.ITALIC; } } if (fontstyle != Font.UNDEFINED && fontstyle != Font.NORMAL) { switch (fontstyle & Font.BOLDITALIC) { case Font.BOLD: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); break; case Font.ITALIC: writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; case Font.BOLDITALIC: writeCssProperty(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); writeCssProperty(Markup.CSS_KEY_FONTSTYLE, Markup.CSS_VALUE_ITALIC); break; } // CSS only supports one decoration tag so if both are specified // only one of the two will display if ((fontstyle & Font.UNDERLINE) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_UNDERLINE); } if ((fontstyle & Font.STRIKETHRU) > 0) { writeCssProperty(Markup.CSS_KEY_TEXTDECORATION, Markup.CSS_VALUE_LINETHROUGH); } } } write("\""); }
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: FactoryProperties.java From gcs with Mozilla Public License 2.0 | 4 votes |
public Font getFont(ChainedProperties props) { String face = props.getProperty(ElementTags.FACE); if (face != null) { StringTokenizer tok = new StringTokenizer(face, ","); while (tok.hasMoreTokens()) { face = tok.nextToken().trim(); if (face.startsWith("\"")) { face = face.substring(1); } if (face.endsWith("\"")) { face = face.substring(0, face.length() - 1); } if (fontImp.isRegistered(face)) { break; } } } int style = 0; if (props.hasProperty(HtmlTags.I)) { style |= Font.ITALIC; } if (props.hasProperty(HtmlTags.B)) { style |= Font.BOLD; } if (props.hasProperty(HtmlTags.U)) { style |= Font.UNDERLINE; } if (props.hasProperty(HtmlTags.S)) { style |= Font.STRIKETHRU; } String value = props.getProperty(ElementTags.SIZE); float size = 12; if (value != null) { size = Float.parseFloat(value); } Color color = Markup.decodeColor(props.getProperty("color")); String encoding = props.getProperty("encoding"); if (encoding == null) { encoding = BaseFont.WINANSI; } return fontImp.getFont(face, encoding, true, size, style, color); }