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


Java PdfFormField类代码示例

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


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

示例1: rotateAnnotations

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
    PdfArray array = new PdfArray();
    int rotation = pageSize.getRotation() % 360;
    int currentPage = writer.getCurrentPageNumber();
    for (int k = 0; k < annotations.size(); ++k) {
        PdfAnnotation dic = (PdfAnnotation)annotations.get(k);
        int page = dic.getPlaceInPage();
        if (page > currentPage) {
            delayedAnnotations.add(dic);
            continue;
        }
        if (dic.isForm()) {
            if (!dic.isUsed()) {
                HashMap templates = dic.getTemplates();
                if (templates != null)
                    acroForm.addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField)dic;
            if (field.getParent() == null)
                acroForm.addDocumentField(field.getIndirectReference());
        }
        if (dic.isAnnotation()) {
            array.add(dic.getIndirectReference());
            if (!dic.isUsed()) {
                PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT);
                if (rect != null) {
                	switch (rotation) {
                    	case 90:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				pageSize.getTop() - rect.bottom(),
						rect.left(),
						pageSize.getTop() - rect.top(),
						rect.right()));
                    		break;
                    	case 180:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				pageSize.getRight() - rect.left(),
						pageSize.getTop() - rect.bottom(),
						pageSize.getRight() - rect.right(),
						pageSize.getTop() - rect.top()));
                    		break;
                    	case 270:
                    		dic.put(PdfName.RECT, new PdfRectangle(
                    				rect.bottom(),
						pageSize.getRight() - rect.left(),
						rect.top(),
						pageSize.getRight() - rect.right()));
                    		break;
                	}
                }
            }
        }
        if (!dic.isUsed()) {
            dic.setUsed();
            try {
                writer.addToBody(dic, dic.getIndirectReference());
            }
            catch (IOException e) {
                throw new ExceptionConverter(e);
            }
        }
    }
    return array;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:65,代码来源:PdfAnnotationsImp.java

示例2: onGenericTag

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document,
		Rectangle rect, String text) {
	rect.setBottom(rect.getBottom() - 3);
	PdfFormField field = (PdfFormField) genericChunkFields.get(text);
	if (field == null) {
		TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
		tf.setFontSize(14);
		try {
			field = tf.getTextField();
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
	}
	else {
		field.put(PdfName.RECT,  new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	}
	if (parent == null)
		writer.addAnnotation(field);
	else
		parent.addKid(field);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:FieldPositioningEvents.java

示例3: 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

示例4: addCell_WithDropDownListField

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
private void addCell_WithDropDownListField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName, String[] optionList,
    String[] valueList ) throws IOException, DocumentException
{
    TextField textList = new TextField( writer, rect, strfldName );

    textList.setChoices( optionList );
    textList.setChoiceExports( valueList );

    textList.setBorderWidth( 1 );
    textList.setBorderColor( Color.BLACK );
    textList.setBorderStyle( PdfBorderDictionary.STYLE_SOLID );
    textList.setBackgroundColor( COLOR_BACKGROUDTEXTBOX );

    PdfFormField dropDown = textList.getComboField();

    cell.setCellEvent( new PdfFieldCell( dropDown, rect.getWidth(), rect.getHeight(), writer ) );

    table.addCell( cell );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:20,代码来源:DefaultPdfDataEntryFormService.java

示例5: setCheckboxAppearance

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
private void setCheckboxAppearance( PdfFormField checkboxfield, PdfContentByte canvas, float width )
{
    PdfAppearance[] onOff = new PdfAppearance[2];
    onOff[0] = canvas.createAppearance( width + 2, width + 2 );
    onOff[0].rectangle( 1, 1, width, width );
    onOff[0].stroke();
    onOff[1] = canvas.createAppearance( width + 2, width + 2 );
    onOff[1].setRGBColorFill( 255, 128, 128 );
    onOff[1].rectangle( 1, 1, width, width );
    onOff[1].fillStroke();
    onOff[1].moveTo( 1, 1 );
    onOff[1].lineTo( width + 1, width + 1 );
    onOff[1].moveTo( 1, width + 1 );
    onOff[1].lineTo( width + 1, 1 );
    onOff[1].stroke();

    checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0] );
    checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1] );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:20,代码来源:DefaultPdfDataEntryFormService.java

示例6: addAnnotation

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
public void addAnnotation(PdfAnnotation annot) {
    if (annot.isForm()) {
        PdfFormField field = (PdfFormField)annot;
        if (field.getParent() == null)
            addFormFieldRaw(field);
    }
    else
        annotations.add(annot);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:10,代码来源:PdfAnnotationsImp.java

示例7: addFormFieldRaw

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
void addFormFieldRaw(PdfFormField field) {
    annotations.add(field);
    ArrayList kids = field.getKids();
    if (kids != null) {
        for (int k = 0; k < kids.size(); ++k)
            addFormFieldRaw((PdfFormField)kids.get(k));
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:9,代码来源:PdfAnnotationsImp.java

示例8: FieldPositioningEvents

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. 
    * @throws DocumentException
    * @throws IOException*/
   public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text) throws IOException, DocumentException {
   	this.parent = parent;
   	TextField tf = new TextField(writer, new Rectangle(0, 0), text);
	tf.setFontSize(14);
	cellField = tf.getTextField();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:10,代码来源:FieldPositioningEvents.java

示例9: main

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:82,代码来源:OptionalContentTest.java

示例10: cellLayout

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
	TextField tf = new TextField(writer, position, fieldname);
	tf.setFontSize(12);
	try{
		PdfFormField field = tf.getTextField();
		writer.addAnnotation(field);
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:15,代码来源:SimpleRegistrationFormTest.java

示例11: main

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

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

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

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

	// step 4:
	PdfFormField pushbutton = PdfFormField.createPushButton(writer);
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	PdfAppearance normal = cb.createAppearance(100, 50);
	normal.setColorFill(Color.GRAY);
	normal.rectangle(5, 5, 90, 40);
	normal.fill();
	PdfAppearance rollover = cb.createAppearance(100, 50);
	rollover.setColorFill(Color.RED);
	rollover.rectangle(5, 5, 90, 40);
	rollover.fill();
	PdfAppearance down = cb.createAppearance(100, 50);
	down.setColorFill(Color.BLUE);
	down.rectangle(5, 5, 90, 40);
	down.fill();
	pushbutton.setFieldName("PushMe");
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, normal);
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_ROLLOVER, rollover);
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_DOWN, down);
	pushbutton.setWidget(new Rectangle(100, 700, 200, 750), PdfAnnotation.HIGHLIGHT_PUSH);
	writer.addAnnotation(pushbutton);

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

示例12: exportElement

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
@Override
	public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element)
	{
		PdfWriter writer = exporterContext.getPdfWriter();
		JasperPrint jasperPrint = exporterContext.getExportedReport();
		
		JRPrintText printText = (JRPrintText)element.getParameterValue(TextInputElement.PARAMETER_PRINT_TEXT_ELEMENT);
		if (printText == null) //FIXMEINPUT deal with xml serialization
		{
			return;
		}
		
		Rectangle rectangle = new Rectangle(
				element.getX() + exporterContext.getOffsetX(),
				jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY(),
				element.getX() + exporterContext.getOffsetX() + element.getWidth(),
				jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()
				);
		TextField text = new TextField(writer, rectangle, getFieldName(element));
		Color backColor = printText.getBackcolor();
		if(backColor != null){
			text.setBackgroundColor(backColor);
		}
		Color forecolor = printText.getForecolor();
		if(forecolor != null){
			text.setTextColor(forecolor);
		}
		text.setText(printText.getFullText());
		text.setDefaultText("default:" + printText.getFullText());
//		text.setBackgroundColor(element.getBackcolor());
//		text.setTextColor(element.getForecolor());
//		text.setText(getText(element));
//		text.setDefaultText(getDefaultText(element));

		//FIXME: dynamic settings below:
		
//		text.setAlignment(Element.ALIGN_LEFT);
//		text.setBorderColor(Color.BLACK);
//		text.setBorderWidth(TextField.BORDER_WIDTH_THIN);
//		text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);

//		text.setChoiceExports(null);
//		text.setChoices(null);
//		text.setChoiceSelection(0);
//		text.setExtensionFont(null);
//		text.setExtraMargin(0, 0);
//		try{
//			text.setFont(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1250, true));
//		}catch(Exception e){
//			throw new JRRuntimeException(e);
//		}
		text.setFontSize(printText.getFontsize());
		if (Boolean.TRUE.equals(element.getParameterValue(TextInputElement.PARAMETER_MULTI_LINE)))
		{
			text.setOptions(TextField.MULTILINE);
		}
//		text.setRotation(90);
		text.setVisibility(TextField.VISIBLE);
		
		try{
			PdfFormField field = text.getTextField();
			writer.addAnnotation(field);
		}catch(Exception e){
			throw new JRRuntimeException(e);
		}
		
	}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:68,代码来源:TextInputElementPdfHandler.java

示例13: PdfFieldCell

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
public PdfFieldCell( PdfFormField formField, float width, float height, PdfWriter writer )
{
    this.formField = formField;
    this.width = width;
    this.height = height;
    this.writer = writer;
    this.type = TYPE_DEFAULT;
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:9,代码来源:PdfFieldCell.java

示例14: addCell_WithRadioButton

import com.lowagie.text.pdf.PdfFormField; //导入依赖的package包/类
@SuppressWarnings( "unused" )
private void addCell_WithRadioButton( PdfPTable table, PdfWriter writer, PdfPCell cell, String strfldName )
{
    PdfFormField radiogroupField = PdfFormField.createRadioButton( writer, true );
    radiogroupField.setFieldName( strfldName );

    cell.setCellEvent( new PdfFieldCell( radiogroupField, new String[]{ "Yes", "No", "null" }, new String[]{
        "true", "false", "" }, "", 30.0f, PdfDataEntryFormUtil.UNITSIZE_DEFAULT, PdfFieldCell.TYPE_RADIOBUTTON, writer ) );

    table.addCell( cell );

    writer.addAnnotation( radiogroupField );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:14,代码来源:DefaultPdfDataEntryFormService.java

示例15: 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


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