com.lowagie.text.pdf.PdfPTable Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfPTable. 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: SplitTableTest.java    From itext2 with GNU Lesser General Public License v3.0 8 votes vote down vote up
/**
 * Break a large table up into several smaller tables for memory management
 * purposes.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 10, 10, 10, 10);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
	// step3
	document.open();
	// step4

	PdfContentByte cb = writer.getDirectContent();
	PdfPTable table = new PdfPTable(10);
	for (int k = 1; k <= 100; ++k) {
		table.addCell("The number " + k);
	}
	table.setTotalWidth(800);
	table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
	document.newPage();
	table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
	document.close();

	// step5
	document.close();
}
 
Example #2
Source File: SimpleCell.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
 *      com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
@Override
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
	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;
	}
	Rectangle rect = new Rectangle(position.getLeft(sp_left), position.getBottom(sp_bottom), position.getRight(sp_right), position.getTop(sp_top));
	rect.cloneNonPositionParameters(this);
	canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
	rect.setBackgroundColor(null);
	canvases[PdfPTable.LINECANVAS].rectangle(rect);
}
 
Example #3
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void insertTable_DataSet( PdfPTable mainTable, PdfWriter writer, DataSet dataSet )
    throws IOException, DocumentException
{
    Rectangle rectangle = new Rectangle( TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

    if ( dataSet.getSections().size() > 0 )
    {
        for ( Section section : dataSet.getSections() )
        {
            insertTable_DataSetSections( mainTable, writer, rectangle, section.getDataElements(), section.getDisplayName() );
        }
    }
    else
    {
        insertTable_DataSetSections( mainTable, writer, rectangle, dataSet.getDataElements(), "" );
    }
}
 
Example #4
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void insertTable_ProgramStage( PdfPTable mainTable, PdfWriter writer, ProgramStage programStage )
    throws IOException, DocumentException
{
    Rectangle rectangle = new Rectangle( TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

    // Add Program Stage Sections
    if ( programStage.getProgramStageSections().size() > 0 )
    {
        // Sectioned Ones
        for ( ProgramStageSection section : programStage.getProgramStageSections() )
        {
            insertTable_ProgramStageSections( mainTable, rectangle, writer, section.getDataElements() );
        }
    }
    else
    {
        // Default one
        insertTable_ProgramStageSections( mainTable, rectangle, writer, programStage.getDataElements() );
    }
}
 
Example #5
Source File: SimpleCell.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @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) {
	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;
	Rectangle rect = new Rectangle(position.getLeft(sp_left), position.getBottom(sp_bottom), position.getRight(sp_right), position.getTop(sp_top));
	rect.cloneNonPositionParameters(this);
	canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
	rect.setBackgroundColor(null);
	canvases[PdfPTable.LINECANVAS].rectangle(rect);
}
 
Example #6
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 #7
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 #8
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void insertTable_TextRow( PdfWriter writer, PdfPTable mainTable, String text, Font font )
{
    boolean hasBorder = false;

    // Add Organization ID/Period textfield
    // Create A table to add for each group AT HERE
    PdfPTable table = new PdfPTable( 1 );
    table.setHorizontalAlignment( Element.ALIGN_LEFT );

    addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), text, Element.ALIGN_LEFT, font );

    // Add to the main table
    PdfPCell cell_withInnerTable = new PdfPCell( table );

    cell_withInnerTable.setBorder( Rectangle.NO_BORDER );

    mainTable.addCell( cell_withInnerTable );
}
 
Example #9
Source File: ImageCellTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * A cell with an image.
 * 
 */
@Test
public void main() throws Exception {

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

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

	// step 3: we open the document
	document.open();
	Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	float[] widths = { 1f, 4f };
	PdfPTable table = new PdfPTable(widths);
	table.addCell("This is my dog");
	table.addCell(image);
	table.addCell("This two");
	table.addCell(new PdfPCell(image, true));
	table.addCell("This three");
	table.addCell(new PdfPCell(image, false));
	document.add(table);

	// step 5: we close the document
	document.close();
}
 
Example #10
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeGraph() throws IOException, DocumentException {
	final JRobin jrobin = collector.getJRobin(graphName);
	if (jrobin != null) {
		final byte[] img = jrobin.graph(range, 960, 400);
		final Image image = Image.getInstance(img);
		image.scalePercent(50);

		final PdfPTable table = new PdfPTable(1);
		table.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.setWidthPercentage(100);
		table.getDefaultCell().setBorder(0);
		table.addCell("\n");
		table.addCell(image);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		table.addCell(new Phrase(getString("graph_units"), cellFont));
		addToDocument(table);
	} else {
		// just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document
		addToDocument(new Phrase("\n", cellFont));
	}
}
 
Example #11
Source File: EndPageTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	try {
		Rectangle page = document.getPageSize();
		PdfPTable head = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			head.addCell("head " + k);
		head.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		head.writeSelectedRows(
				0,
				-1,
				document.leftMargin(),
				page.getHeight() - document.topMargin()
						+ head.getTotalHeight(), writer.getDirectContent());
		PdfPTable foot = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			foot.addCell("foot " + k);
		foot.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		foot.writeSelectedRows(0, -1, document.leftMargin(),
				document.bottomMargin(), writer.getDirectContent());
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
Example #12
Source File: ContractsGrantsInvoiceReportServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method is used to set the headers for the CG LOC review Document
 *
 * @param table
 */
protected void addAccountsHeaders(PdfPTable table) {
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.ACCOUNT_DESCRIPTION));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.ACCOUNT_NUMBER));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.ACCOUNT_EXPIRATION_DATE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.AWARD_BUDGET_AMOUNT));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.CLAIM_ON_CASH_BALANCE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.AMOUNT_TO_DRAW));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.FUNDS_NOT_DRAWN));
}
 
Example #13
Source File: Table.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
    * @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
	 */
public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
	float[] width = widths[0];
	Rectangle rect = new Rectangle(width[0], heights[heights.length - 1], width[width.length - 1], heights[0]);
	rect.cloneNonPositionParameters(rectangle);
	canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
	rect.setBackgroundColor(null);
	canvases[PdfPTable.LINECANVAS].rectangle(rect);
}
 
Example #14
Source File: PDFPrinter.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public void printHeader(String... fields) {
	iTable = new PdfPTable(fields.length - iHiddenColumns.size());
	iMaxWidth = new float[fields.length];
	iTable.setHeaderRows(1);
	iTable.setWidthPercentage(100);

	for (int idx = 0; idx < fields.length; idx++) {
		if (iHiddenColumns.contains(idx)) continue;
		String f = fields[idx];
		
		PdfPCell cell = new PdfPCell();
		cell.setBorder(Rectangle.BOTTOM);
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(Element.ALIGN_LEFT);
		
		Font font = PdfFont.getFont(true);
		Paragraph ch = new Paragraph(f, font);
		ch.setLeading(0f, 1f);
		cell.addElement(ch);		
		iTable.addCell(cell);
		
		float width = 0; 
		if (f.indexOf('\n')>=0) {
			for (StringTokenizer s = new StringTokenizer(f,"\n"); s.hasMoreTokens();)
				width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
		} else 
			width = Math.max(width,font.getBaseFont().getWidthPoint(f, font.getSize()));
		iMaxWidth[idx] = width;
	}
}
 
Example #15
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
private void createTable(boolean keepTogether) {
    iPdfTable = new PdfPTable(getNrColumns());
    iPdfTable.setWidthPercentage(100);
    iPdfTable.getDefaultCell().setPadding(3);
    iPdfTable.getDefaultCell().setBorderWidth(1);
    iPdfTable.setSplitRows(false);
    iPdfTable.setSpacingBefore(10);
    iPdfTable.setKeepTogether(keepTogether);
}
 
Example #16
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
private void createTable() {
	iPdfTable = new PdfPTable(getNrColumns());
	iPdfTable.setWidthPercentage(100);
	iPdfTable.getDefaultCell().setPadding(3);
	iPdfTable.getDefaultCell().setBorderWidth(1);
	iPdfTable.setSplitRows(false);
	iPdfTable.setSpacingBefore(10);
	if (iTable.isDispModePerWeek()) {
		iPdfTable.setKeepTogether(true);
	}
}
 
Example #17
Source File: PdfExportService.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private void addRowToTable(PdfPTable table, List<String> columns, boolean isHeader) {
    final Font font = fontCreator.createFont();

    for (String column : columns) {
        PdfPCell cell = new PdfPCell(new Phrase(column, font));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (isHeader) {
            cell.setBackgroundColor(Color.LIGHT_GRAY);
        }

        table.addCell(cell);
    }
}
 
Example #18
Source File: PdfExportService.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private <T> PdfPTable createTable(List<T> data, RowCallback<T> rowCallback, PdfTableData pdfTableData) {
    PdfPTable table = new PdfPTable(pdfTableData.getColumnWidths());
    table.setWidthPercentage(100);

    addRowToTable(table, pdfTableData.getHeaderColumns(), true);

    data.forEach(dataEntry -> {
        RowContentAdder rowContentAdder = new RowContentAdder();
        rowCallback.onRow(rowContentAdder, dataEntry);
        List<String> rowContent = rowContentAdder.getRowContent();
        addRowToTable(table, rowContent, false);
    });
    return table;
}
 
Example #19
Source File: PurchaseOrderQuotePdf.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * A helper method to create a blank row of 6 cells in the items table.
 *
 * @param itemsTable
 */
private void createBlankRowInItemsTable(PdfPTable itemsTable) {
    // We're adding 6 cells because each row in the items table
    // contains 6 columns.
    for (int i = 0; i < 6; i++) {
        itemsTable.addCell(" ");
    }
}
 
Example #20
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Adds a table to a document.
 *
 * @param document The document to add the table to.
 * @param table    The table to add to the document.
 */
public static void addTableToDocument( Document document, PdfPTable table )
{
    try
    {
        document.add( table );
    }
    catch ( DocumentException ex )
    {
        throw new RuntimeException( "Failed to add table to document", ex );
    }
}
 
Example #21
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequestRumData() throws DocumentException {
	final CounterRequestRumData rumData = request.getRumData();
	final DecimalFormat percentFormat = I18N.createPercentFormat();
	final int networkTimeMean = rumData.getNetworkTimeMean();
	final int serverMean = request.getMean();
	final int domProcessingMean = rumData.getDomProcessingMean();
	final int pageRenderingMean = rumData.getPageRenderingMean();
	final int totalTime = networkTimeMean + serverMean + domProcessingMean + pageRenderingMean;
	final double networkPercent = 100d * networkTimeMean / totalTime;
	final double serverPercent = 100d * serverMean / totalTime;
	final double domProcessingPercent = 100d * domProcessingMean / totalTime;
	final double pageRenderingPercent = 100d * pageRenderingMean / totalTime;

	final PdfPTable table = new PdfPTable(2);
	table.setHorizontalAlignment(Element.ALIGN_LEFT);
	table.setWidthPercentage(25);
	table.getDefaultCell().setBorderWidth(0);
	table.addCell(new Phrase(I18N.getString("Network"), cellFont));
	table.addCell(new Phrase(integerFormat.format(networkTimeMean) + " ms ("
			+ percentFormat.format(networkPercent) + "%)", cellFont));
	table.addCell(new Phrase(I18N.getString("Server"), cellFont));
	table.addCell(new Phrase(integerFormat.format(serverMean) + " ms ("
			+ percentFormat.format(serverPercent) + "%)", cellFont));
	table.addCell(new Phrase(I18N.getString("DOM_processing"), cellFont));
	table.addCell(new Phrase(integerFormat.format(domProcessingMean) + " ms ("
			+ percentFormat.format(domProcessingPercent) + "%)", cellFont));
	table.addCell(new Phrase(I18N.getString("Page_rendering"), cellFont));
	table.addCell(new Phrase(integerFormat.format(pageRenderingMean) + " ms ("
			+ percentFormat.format(pageRenderingPercent) + "%)", cellFont));
	addToDocument(table);
	addToDocument(new Phrase("\n", cellFont));
}
 
Example #22
Source File: ContractsGrantsInvoiceReportServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method is used to set the headers for the CG LOC review Document
 *
 * @param table
 */
protected void addAwardHeaders(PdfPTable table) {
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.PROPOSAL_NUMBER));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.AWARD_DOCUMENT_NUMBER));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.AGENCY_NUMBER));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.CUSTOMER_NUMBER));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.AWARD_BEGINNING_DATE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, KFSPropertyConstants.AWARD_ENDING_DATE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.AWARD_BUDGET_AMOUNT));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.LETTER_OF_CREDIT_AMOUNT));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.CLAIM_ON_CASH_BALANCE));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.AMOUNT_TO_DRAW));
    table.addCell(getDataDictionaryService().getAttributeLabel(ContractsGrantsLetterOfCreditReviewDetail.class, ArPropertyConstants.FUNDS_NOT_DRAWN));
}
 
Example #23
Source File: PdfMBeansReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private static PdfPTable createAttributesTable() {
	final PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	final PdfPCell defaultCell = table.getDefaultCell();
	defaultCell.setPaddingLeft(2);
	defaultCell.setPaddingRight(2);
	defaultCell.setVerticalAlignment(Element.ALIGN_TOP);
	defaultCell.setBorder(0);
	return table;
}
 
Example #24
Source File: GridUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void addPdfTimestamp( Document document, boolean paddingTop )
{
    PdfPTable table = new PdfPTable(1);
    table.addCell( getEmptyCell( 1, ( paddingTop ? 30 : 0 ) ) );
    table.addCell( getTextCell( getGeneratedString() ) );
    addTableToDocument( document, table );
}
 
Example #25
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCell_Text( PdfPTable table, PdfPCell cell, String text, int horizontalAlignment, Font font )
{
    cell.setHorizontalAlignment( horizontalAlignment );

    cell.setPhrase( new Phrase( text, font ) );

    table.addCell( cell ); // TODO: change this with cellEvent?
}
 
Example #26
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void insertSaveAsButton( Document document, PdfWriter writer, String name, String dataSetName )
    throws DocumentException
{
    boolean hasBorder = false;

    // Button Table
    PdfPTable tableButton = new PdfPTable( 1 );

    tableButton.setWidthPercentage( 20.0f );
    float buttonHeight = PdfDataEntryFormUtil.UNITSIZE_DEFAULT + 5;

    tableButton.setHorizontalAlignment( Element.ALIGN_CENTER );

    //FIXME
    
    String jsAction = "var newFileName = this.getField(\"" + PdfDataEntryFormUtil.LABELCODE_PERIODID + "\").value + ' ' + "
        + "  this.getField(\"" + PdfDataEntryFormUtil.LABELCODE_ORGID + "\").value + ' ' + "
        + "  \"" + dataSetName + ".pdf\";"
        + "var returnVal = app.alert('This will save this PDF file as ' + newFileName + '.  Do you want to Continue?', 1, 2);"
        + "if(returnVal == 4) { "
        + "  var aMyPath = this.path.split(\"/\");"
        + "  aMyPath.pop();"
        + "  aMyPath.push(newFileName);"
        + "  this.saveAs(aMyPath.join(\"/\"));"
        + "  this.saveAs({cPath:cMyPath, bPromptToOverwrite:true});"
        + "  app.alert('File Saved.', 1);"
        + "} ";

    addCell_WithPushButtonField( tableButton, writer, PdfDataEntryFormUtil.getPdfPCell( buttonHeight, PdfDataEntryFormUtil.CELL_COLUMN_TYPE_ENTRYFIELD, hasBorder ), name, jsAction );

    document.add( tableButton );
}
 
Example #27
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void insertTable_OrgAndPeriod( PdfPTable mainTable, PdfWriter writer, List<Period> periods )
    throws IOException, DocumentException
{
    boolean hasBorder = false;
    float width = 220.0f;

    // Input TextBox size
    Rectangle rectangle = new Rectangle( width, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

    // Add Organization ID/Period textfield
    // Create A table to add for each group AT HERE
    PdfPTable table = new PdfPTable( 2 ); // Code 1
    table.setWidths( new int[]{ 1, 3 } );
    table.setHorizontalAlignment( Element.ALIGN_LEFT );


    addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), "Organization unit identifier", Element.ALIGN_RIGHT );
    addCell_WithTextField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), PdfDataEntryFormUtil.LABELCODE_ORGID,
        PdfFieldCell.TYPE_TEXT_ORGUNIT );

    String[] periodsTitle = getPeriodTitles( periods, format );
    String[] periodsValue = getPeriodValues( periods );

    addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), "Period", Element.ALIGN_RIGHT );
    addCell_WithDropDownListField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), PdfDataEntryFormUtil.LABELCODE_PERIODID, periodsTitle, periodsValue );

    // Add to the main table
    PdfPCell cell_withInnerTable = new PdfPCell( table );
    // cell_withInnerTable.setPadding(0);
    cell_withInnerTable.setBorder( Rectangle.NO_BORDER );

    cell_withInnerTable.setHorizontalAlignment( Element.ALIGN_LEFT );

    mainTable.addCell( cell_withInnerTable );
}
 
Example #28
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private PdfPTable getProgramStageMainTable()
{
    PdfPTable mainTable = new PdfPTable( 1 ); // Code 1

    mainTable.setTotalWidth( 800f );
    mainTable.setLockedWidth( true );
    mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );

    return mainTable;
}
 
Example #29
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setProgramStage_DocumentContent( Document document, PdfWriter writer, String programStageUid )
    throws Exception
{
    ProgramStage programStage = programStageService.getProgramStage( programStageUid );

    if ( programStage == null )
    {
        throw new RuntimeException( "Error - ProgramStage not found for UID " + programStageUid );
    }
    else
    {
        // Get Rectangle with TextBox Width to be used
        Rectangle rectangle = new Rectangle( 0, 0, TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

        // Create Main Layout table and set the properties
        PdfPTable mainTable = getProgramStageMainTable();

        // Generate Period List for ProgramStage
        List<Period> periods = getProgramStagePeriodList();

        // Add Org Unit, Period, Hidden ProgramStageID Field
        insertTable_OrgAndPeriod( mainTable, writer, periods );

        insertTable_TextRow( writer, mainTable, TEXT_BLANK );

        // Add ProgramStage Field - programStage.getId();
        insertTable_HiddenValue( mainTable, rectangle, writer,
            PdfDataEntryFormUtil.LABELCODE_PROGRAMSTAGEIDTEXTBOX, String.valueOf( programStage.getId() ) );

        // Add ProgramStage Content to PDF - [The Main Section]
        insertTable_ProgramStage( mainTable, writer, programStage );

        // Add the mainTable to document
        document.add( mainTable );
    }
}
 
Example #30
Source File: PdfNodeSerializer.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void startWriteRootNode( RootNode rootNode ) throws Exception
{
    for ( Node child : rootNode.getChildren() )
    {
        if ( child.isCollection() )
        {
            PdfPTable table = PDFUtils.getPdfPTable( true, 0.25f, 0.75f );
            boolean haveContent = false;

            for ( Node node : child.getChildren() )
            {
                for ( Node property : node.getChildren() )
                {
                    if ( property.isSimple() )
                    {
                        table.addCell( PDFUtils.getItalicCell( property.getName() ) );
                        table.addCell( PDFUtils.getTextCell( getValue( (SimpleNode) property ) ) );
                        haveContent = true;
                    }
                }

                if ( haveContent )
                {
                    table.addCell( PDFUtils.getEmptyCell( 2, 15 ) );
                    haveContent = false;
                }
            }

            document.add( table );
        }
    }
}