当前位置: 首页>>代码示例>>Java>>正文


Java PdfFormField.setValueAsString方法代码示例

本文整理汇总了Java中com.lowagie.text.pdf.PdfFormField.setValueAsString方法的典型用法代码示例。如果您正苦于以下问题:Java PdfFormField.setValueAsString方法的具体用法?Java PdfFormField.setValueAsString怎么用?Java PdfFormField.setValueAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.pdf.PdfFormField的用法示例。


在下文中一共展示了PdfFormField.setValueAsString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.lowagie.text.pdf.PdfFormField; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a Combobox
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("combo.pdf"));

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

	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	String options[] = { "Red", "Green", "Blue" };
	PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
	field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
	field.setFieldName("ACombo");
	field.setValueAsString("Red");
	writer.addAnnotation(field);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:FormComboTest.java

示例2: main

import com.lowagie.text.pdf.PdfFormField; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a Combobox
 * 
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {

	System.out.println("Combo");

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4);

	try {

		// step 2:
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "combo.pdf"));

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

		// step 4:
		PdfContentByte cb = writer.getDirectContent();
		cb.moveTo(0, 0);
		String options[] = { "Red", "Green", "Blue" };
		PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
		field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
		field.setFieldName("ACombo");
		field.setValueAsString("Red");
		writer.addAnnotation(field);

	} catch (DocumentException de) {
		System.err.println(de.getMessage());
	} catch (IOException ioe) {
		System.err.println(ioe.getMessage());
	}

	// step 5: we close the document
	document.close();
}
 
开发者ID:fc-dream,项目名称:PDFTestForAndroid,代码行数:41,代码来源:FormCombo.java

示例3: main

import com.lowagie.text.pdf.PdfFormField; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a TextField
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("textfield.pdf"));

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

	// step 4:
	BaseFont helv = BaseFont.createFont("Helvetica", "winansi", false);
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	String text = "Some start text";
	float fontSize = 12;
	Color textColor = new GrayColor(0f);
	PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
	field.setWidget(new Rectangle(171, 750, 342, 769), PdfAnnotation.HIGHLIGHT_INVERT);
	field.setFlags(PdfAnnotation.FLAGS_PRINT);
	field.setFieldName("ATextField");
	field.setValueAsString(text);
	field.setDefaultValueAsString(text);
	field.setBorderStyle(new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID));
	field.setPage();
	PdfAppearance tp = cb.createAppearance(171, 19);
	PdfAppearance da = (PdfAppearance) tp.getDuplicate();
	da.setFontAndSize(helv, fontSize);
	da.setColorFill(textColor);
	field.setDefaultAppearanceString(da);
	tp.beginVariableText();
	tp.saveState();
	tp.rectangle(2, 2, 167, 15);
	tp.clip();
	tp.newPath();
	tp.beginText();
	tp.setFontAndSize(helv, fontSize);
	tp.setColorFill(textColor);
	tp.setTextMatrix(4, 5);
	tp.showText(text);
	tp.endText();
	tp.restoreState();
	tp.endVariableText();
	field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
	writer.addAnnotation(field);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:55,代码来源:FormTextFieldTest.java

示例4: main

import com.lowagie.text.pdf.PdfFormField; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a list
 * 
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {

	System.out.println("List");

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4);

	try {

		// step 2:
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "list.pdf"));

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

		// step 4:
		PdfContentByte cb = writer.getDirectContent();
		cb.moveTo(0, 0);
		String options[] = { "Red", "Green", "Blue" };
		PdfFormField field = PdfFormField.createList(writer, options, 0);
		PdfAppearance app = cb.createAppearance(80, 60);
		app.rectangle(1, 1, 78, 58);
		app.setGrayFill(0.8f);
		app.fill();
		app.resetGrayFill();
		field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
		field.setWidget(new Rectangle(100, 700, 180, 760), PdfAnnotation.HIGHLIGHT_OUTLINE);
		field.setFieldName("AList");
		field.setValueAsString("Red");
		writer.addAnnotation(field);

	} catch (DocumentException de) {
		System.err.println(de.getMessage());
	} catch (IOException ioe) {
		System.err.println(ioe.getMessage());
	}

	// step 5: we close the document
	document.close();
}
 
开发者ID:fc-dream,项目名称:PDFTestForAndroid,代码行数:47,代码来源:FormList.java

示例5: main

import com.lowagie.text.pdf.PdfFormField; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a TextField
 * 
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {

	System.out.println("Textfield");

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4);

	try {

		// step 2:
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "textfield.pdf"));

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

		// step 4:
		BaseFont helv = BaseFont.createFont("Helvetica", "winansi", false);
		PdfContentByte cb = writer.getDirectContent();
		cb.moveTo(0, 0);
		String text = "Some start text";
		float fontSize = 12;
		Color textColor = new GrayColor(0f);
		PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
		field.setWidget(new Rectangle(171, 750, 342, 769), PdfAnnotation.HIGHLIGHT_INVERT);
		field.setFlags(PdfAnnotation.FLAGS_PRINT);
		field.setFieldName("ATextField");
		field.setValueAsString(text);
		field.setDefaultValueAsString(text);
		field.setBorderStyle(new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID));
		field.setPage();
		PdfAppearance tp = cb.createAppearance(171, 19);
		PdfAppearance da = (PdfAppearance) tp.getDuplicate();
		da.setFontAndSize(helv, fontSize);
		da.setColorFill(textColor);
		field.setDefaultAppearanceString(da);
		tp.beginVariableText();
		tp.saveState();
		tp.rectangle(2, 2, 167, 15);
		tp.clip();
		tp.newPath();
		tp.beginText();
		tp.setFontAndSize(helv, fontSize);
		tp.setColorFill(textColor);
		tp.setTextMatrix(4, 5);
		tp.showText(text);
		tp.endText();
		tp.restoreState();
		tp.endVariableText();
		field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
		writer.addAnnotation(field);

	} catch (DocumentException de) {
		System.err.println(de.getMessage());
	} catch (IOException ioe) {
		System.err.println(ioe.getMessage());
	}

	// step 5: we close the document
	document.close();
}
 
开发者ID:fc-dream,项目名称:PDFTestForAndroid,代码行数:67,代码来源:FormTextField.java


注:本文中的com.lowagie.text.pdf.PdfFormField.setValueAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。