Java Code Examples for com.lowagie.text.pdf.PdfPCell#setCellEvent()

The following examples show how to use com.lowagie.text.pdf.PdfPCell#setCellEvent() . 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: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addCell_WithTextField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName,
    int fieldCellType, String value )
    throws IOException, DocumentException
{
    TextField nameField = new TextField( writer, rect, strfldName );

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

    nameField.setText( value );

    nameField.setAlignment( Element.ALIGN_RIGHT );
    nameField.setFont( pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ).getBaseFont() );

    cell.setCellEvent( new PdfFieldCell( nameField.getTextField(), rect.getWidth(), rect.getHeight(), fieldCellType, writer ) );

    table.addCell( cell );
}
 
Example 2
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 );
}
 
Example 3
Source File: CellEventsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * General example using cell events.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
	// step3
	document.open();
	// step4
	CellEventsTest event = new CellEventsTest();
	Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	im.setRotationDegrees(30);
	PdfPTable table = new PdfPTable(4);
	table.addCell("text 1");
	PdfPCell cell = new PdfPCell(im, true);
	cell.setCellEvent(event);
	table.addCell(cell);
	table.addCell("text 3");
	im.setRotationDegrees(0);
	table.addCell(im);
	table.setTotalWidth(300);
	PdfContentByte cb = writer.getDirectContent();
	table.writeSelectedRows(0, -1, 50, 600, cb);
	table.setHeaderRows(3);
	document.add(table);

	// step5
	document.close();
}
 
Example 4
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 );
}
 
Example 5
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCell_WithPushButtonField( PdfPTable table, PdfWriter writer, PdfPCell cell, String strfldName, String jsAction )
{
    cell.setCellEvent( new PdfFieldCell( null, jsAction, "BTN_SAVEPDF", "Save PDF", PdfFieldCell.TYPE_BUTTON,
        writer ) );

    table.addCell( cell );
}
 
Example 6
Source File: SimpleCell.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a PdfPCell with these attributes.
 * 
 * @param rowAttributes
 * @return a PdfPCell based on these attributes.
 */
public PdfPCell createPdfPCell(SimpleCell rowAttributes) {
	PdfPCell cell = new PdfPCell();
	cell.setBorder(NO_BORDER);
	SimpleCell tmp = new SimpleCell(CELL);
	tmp.setSpacing_left(spacing_left);
	tmp.setSpacing_right(spacing_right);
	tmp.setSpacing_top(spacing_top);
	tmp.setSpacing_bottom(spacing_bottom);
	tmp.cloneNonPositionParameters(rowAttributes);
	tmp.softCloneNonPositionParameters(this);
	cell.setCellEvent(tmp);
	cell.setHorizontalAlignment(rowAttributes.horizontalAlignment);
	cell.setVerticalAlignment(rowAttributes.verticalAlignment);
	cell.setUseAscender(rowAttributes.useAscender);
	cell.setUseBorderPadding(rowAttributes.useBorderPadding);
	cell.setUseDescender(rowAttributes.useDescender);
	cell.setColspan(colspan);
	if (horizontalAlignment != Element.ALIGN_UNDEFINED) {
		cell.setHorizontalAlignment(horizontalAlignment);
	}
	if (verticalAlignment != Element.ALIGN_UNDEFINED) {
		cell.setVerticalAlignment(verticalAlignment);
	}
	if (useAscender) {
		cell.setUseAscender(useAscender);
	}
	if (useBorderPadding) {
		cell.setUseBorderPadding(useBorderPadding);
	}
	if (useDescender) {
		cell.setUseDescender(useDescender);
	}
	float p;
	float sp_left = spacing_left;
	if (Float.isNaN(sp_left)) {
		sp_left = 0f;
	}
	float sp_right = spacing_right;
	if (Float.isNaN(sp_right)) {
		sp_right = 0f;
	}
	float sp_top = spacing_top;
	if (Float.isNaN(sp_top)) {
		sp_top = 0f;
	}
	float sp_bottom = spacing_bottom;
	if (Float.isNaN(sp_bottom)) {
		sp_bottom = 0f;
	}
	p = padding_left;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingLeft(p + sp_left);
	p = padding_right;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingRight(p + sp_right);
	p = padding_top;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingTop(p + sp_top);
	p = padding_bottom;
	if (Float.isNaN(p)) {
		p = 0f;
	}
	cell.setPaddingBottom(p + sp_bottom);
	Element element;
	for (Iterator i = content.iterator(); i.hasNext();) {
		element = (Element) i.next();
		cell.addElement(element);
	}
	return cell;
}
 
Example 7
Source File: SimpleCell.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a PdfPCell with these attributes.
 * @param rowAttributes
 * @return a PdfPCell based on these attributes.
 */
public PdfPCell createPdfPCell(SimpleCell rowAttributes) {
	PdfPCell cell = new PdfPCell();
	cell.setBorder(NO_BORDER);
	SimpleCell tmp = new SimpleCell(CELL);
	tmp.setSpacing_left(spacing_left);
	tmp.setSpacing_right(spacing_right);
	tmp.setSpacing_top(spacing_top);
	tmp.setSpacing_bottom(spacing_bottom);
	tmp.cloneNonPositionParameters(rowAttributes);
	tmp.softCloneNonPositionParameters(this);
	cell.setCellEvent(tmp);
	cell.setHorizontalAlignment(rowAttributes.horizontalAlignment);
	cell.setVerticalAlignment(rowAttributes.verticalAlignment);
	cell.setUseAscender(rowAttributes.useAscender);
	cell.setUseBorderPadding(rowAttributes.useBorderPadding);
	cell.setUseDescender(rowAttributes.useDescender);
	cell.setColspan(colspan);
	if (horizontalAlignment != Element.ALIGN_UNDEFINED)
		cell.setHorizontalAlignment(horizontalAlignment);
	if (verticalAlignment != Element.ALIGN_UNDEFINED)
		cell.setVerticalAlignment(verticalAlignment);
	if (useAscender)
		cell.setUseAscender(useAscender);
	if (useBorderPadding)
		cell.setUseBorderPadding(useBorderPadding);
	if (useDescender)
		cell.setUseDescender(useDescender);
	float p;
	float sp_left = spacing_left;
	if (Float.isNaN(sp_left)) sp_left = 0f;
	float sp_right = spacing_right;
	if (Float.isNaN(sp_right)) sp_right = 0f;
	float sp_top = spacing_top;
	if (Float.isNaN(sp_top)) sp_top = 0f;
	float sp_bottom = spacing_bottom;
	if (Float.isNaN(sp_bottom)) sp_bottom = 0f;
	p = padding_left;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingLeft(p + sp_left);
	p = padding_right;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingRight(p + sp_right);
	p = padding_top;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingTop(p + sp_top);
	p = padding_bottom;
	if (Float.isNaN(p)) p = 0f; 
	cell.setPaddingBottom(p + sp_bottom);
	Element element;
	for (Iterator i = content.iterator(); i.hasNext(); ) {
		element = (Element)i.next();
		cell.addElement(element);
	}
	return cell;
}
 
Example 8
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addCell_WithCheckBox( PdfPTable table, PdfWriter writer, PdfPCell cell, String strfldName )
    throws IOException, DocumentException
{
    float sizeDefault = PdfDataEntryFormUtil.UNITSIZE_DEFAULT;

    RadioCheckField checkbox = new RadioCheckField( writer, new Rectangle( sizeDefault, sizeDefault ), "Yes", "On" );

    checkbox.setBorderWidth( 1 );
    checkbox.setBorderColor( Color.BLACK );

    PdfFormField checkboxfield = checkbox.getCheckField();
    checkboxfield.setFieldName( strfldName + "_" + PdfFieldCell.TPYEDEFINE_NAME + PdfFieldCell.TYPE_CHECKBOX );

    setCheckboxAppearance( checkboxfield, writer.getDirectContent(), sizeDefault );

    cell.setCellEvent( new PdfFieldCell( checkboxfield, sizeDefault, sizeDefault, PdfFieldCell.TYPE_CHECKBOX, writer ) );

    table.addCell( cell );
}