Java Code Examples for com.lowagie.text.Font#HELVETICA

The following examples show how to use com.lowagie.text.Font#HELVETICA . 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: RtfFont.java    From itext2 with GNU Lesser General Public License v3.0 8 votes vote down vote up
/**
 * Sets the correct font name from the family name.
 * 
 * @param familyname The family name to set the name to.
 */
private void setToDefaultFamily(String familyname){
    switch (Font.getFamilyIndex(familyname)) {
        case Font.COURIER:
            this.fontName = "Courier";
            break;
        case Font.HELVETICA:
            this.fontName = "Arial";
            break;
        case Font.SYMBOL:
            this.fontName = "Symbol";
            this.charset = 2;
            break;
        case Font.TIMES_ROMAN:
            this.fontName = "Times New Roman";
            break;
        case Font.ZAPFDINGBATS:
            this.fontName = "Windings";
            break;
        default:
            this.fontName = familyname;
    }
}
 
Example 2
Source File: OptionalContentTest.java    From itext2 with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * 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 3
Source File: StandardType1FontsTest.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
 * 
 */
@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("StandardType1Fonts.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:

	// the 14 standard fonts in PDF: do not use this Font constructor!
	// this is for demonstration purposes only, use FontFactory!
	Font[] fonts = new Font[14];
	fonts[0] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.NORMAL);
	fonts[1] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.ITALIC);
	fonts[2] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD);
	fonts[3] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD | Font.ITALIC);
	fonts[4] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.NORMAL);
	fonts[5] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC);
	fonts[6] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD);
	fonts[7] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLDITALIC);
	fonts[8] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL);
	fonts[9] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.ITALIC);
	fonts[10] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD);
	fonts[11] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC);
	fonts[12] = new Font(Font.SYMBOL);
	fonts[13] = new Font(Font.ZAPFDINGBATS);
	// 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 4
Source File: OrderedLayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 5
Source File: LayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * 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 6
Source File: AutomaticTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 7
Source File: NestedLayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 8
Source File: ContentGroupsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * 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 9
Source File: LayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates some Layer functionality.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Layers.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	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();
	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: we close the document
	document.close();
}