Java Code Examples for com.lowagie.text.pdf.PdfPTable#setHorizontalAlignment()

The following examples show how to use com.lowagie.text.pdf.PdfPTable#setHorizontalAlignment() . 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 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 2
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 3
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 4
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 5
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 6
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 7
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private static PdfPTable createJavaInformationsTable() throws DocumentException {
	final PdfPTable table = new PdfPTable(2);
	table.setHorizontalAlignment(Element.ALIGN_LEFT);
	table.setWidthPercentage(100);
	table.setWidths(new int[] { 2, 8 });
	table.getDefaultCell().setBorder(0);
	return table;
}
 
Example 8
Source File: SimpleTable.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a PdfPTable object based on this TableAttributes object.
 * 
 * @return a com.lowagie.text.pdf.PdfPTable object
 * @throws DocumentException
 */
public PdfPTable createPdfPTable() throws DocumentException {
	if (content.isEmpty()) {
		throw new BadElementException("Trying to create a table without rows.");
	}
	SimpleCell row = (SimpleCell) content.get(0);
	SimpleCell cell;
	int columns = 0;
	for (Iterator i = row.getContent().iterator(); i.hasNext();) {
		cell = (SimpleCell) i.next();
		columns += cell.getColspan();
	}
	float[] widths = new float[columns];
	float[] widthpercentages = new float[columns];
	PdfPTable table = new PdfPTable(columns);
	table.setTableEvent(this);
	table.setHorizontalAlignment(alignment);
	int pos;
	for (Iterator rows = content.iterator(); rows.hasNext();) {
		row = (SimpleCell) rows.next();
		pos = 0;
		for (Iterator cells = row.getContent().iterator(); cells.hasNext();) {
			cell = (SimpleCell) cells.next();
			if (Float.isNaN(cell.getSpacing_left())) {
				cell.setSpacing_left(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_right())) {
				cell.setSpacing_right(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_top())) {
				cell.setSpacing_top(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_bottom())) {
				cell.setSpacing_bottom(cellspacing / 2f);
			}
			cell.setPadding(cellpadding);
			table.addCell(cell.createPdfPCell(row));
			if (cell.getColspan() == 1) {
				if (cell.getWidth() > 0) {
					widths[pos] = cell.getWidth();
				}
				if (cell.getWidthpercentage() > 0) {
					widthpercentages[pos] = cell.getWidthpercentage();
				}
			}
			pos += cell.getColspan();
		}
	}
	float sumWidths = 0f;
	for (int i = 0; i < columns; i++) {
		if (widths[i] == 0) {
			sumWidths = 0;
			break;
		}
		sumWidths += widths[i];
	}
	if (sumWidths > 0) {
		table.setTotalWidth(sumWidths);
		table.setWidths(widths);
	} else {
		for (int i = 0; i < columns; i++) {
			if (widthpercentages[i] == 0) {
				sumWidths = 0;
				break;
			}
			sumWidths += widthpercentages[i];
		}
		if (sumWidths > 0) {
			table.setWidths(widthpercentages);
		}
	}
	if (width > 0) {
		table.setTotalWidth(width);
	}
	if (widthpercentage > 0) {
		table.setWidthPercentage(widthpercentage);
	}
	return table;
}
 
Example 9
Source File: SimpleTable.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a PdfPTable object based on this TableAttributes object.
 * @return a com.lowagie.text.pdf.PdfPTable object
 * @throws DocumentException
 */
public PdfPTable createPdfPTable() throws DocumentException {
	if (content.isEmpty()) throw new BadElementException("Trying to create a table without rows.");
	SimpleCell row = (SimpleCell)content.get(0);
	SimpleCell cell;
	int columns = 0;
	for (Iterator i = row.getContent().iterator(); i.hasNext(); ) {
		cell = (SimpleCell)i.next();
		columns += cell.getColspan();
	}
	float[] widths = new float[columns];
	float[] widthpercentages = new float[columns];
	PdfPTable table = new PdfPTable(columns);
	table.setTableEvent(this);
	table.setHorizontalAlignment(alignment);
	int pos;
	for (Iterator rows = content.iterator(); rows.hasNext(); ) {
		row = (SimpleCell)rows.next();
		pos = 0;
		for (Iterator cells = row.getContent().iterator(); cells.hasNext(); ) {
			cell = (SimpleCell)cells.next();
			if (Float.isNaN(cell.getSpacing_left()))	{
				cell.setSpacing_left(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_right()))	{
				cell.setSpacing_right(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_top()))	{
				cell.setSpacing_top(cellspacing / 2f);
			}
			if (Float.isNaN(cell.getSpacing_bottom()))	{
				cell.setSpacing_bottom(cellspacing / 2f);
			}
			cell.setPadding(cellpadding);
			table.addCell(cell.createPdfPCell(row));
			if (cell.getColspan() == 1) {
				if (cell.getWidth() > 0) widths[pos] = cell.getWidth();
				if (cell.getWidthpercentage() > 0) widthpercentages[pos] = cell.getWidthpercentage();
			}
			pos += cell.getColspan();
		}
	}
	float sumWidths = 0f;
	for(int i = 0; i < columns; i++) {
		if (widths[i] == 0) {
			sumWidths = 0;
			break;
		}
		sumWidths += widths[i];
	}
	if (sumWidths > 0) {
		table.setTotalWidth(sumWidths);
		table.setWidths(widths);
	}
	else {
		for(int i = 0; i < columns; i++) {
			if (widthpercentages[i] == 0) {
				sumWidths = 0;
				break;
			}
			sumWidths += widthpercentages[i];
		}
		if (sumWidths > 0) {
			table.setWidths(widthpercentages);
		}
	}
	if (width > 0) {
		table.setTotalWidth(width);
	}
	if (widthpercentage > 0) {
		table.setWidthPercentage(widthpercentage);
	}
	return table;
}
 
Example 10
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setMainTable( PdfPTable mainTable )
{
    mainTable.setWidthPercentage( 100.0f );
    mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );
}
 
Example 11
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void insertTable_DataSetSections( PdfPTable mainTable, PdfWriter writer, Rectangle rectangle,
    Collection<DataElement> dataElements, String sectionName )
    throws IOException, DocumentException
{
    boolean hasBorder = true;

    // Add Section Name and Section Spacing
    insertTable_TextRow( writer, mainTable, TEXT_BLANK );

    if ( sectionName != null && !sectionName.isEmpty() )
    {
        insertTable_TextRow( writer, mainTable, sectionName,
            pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_SECTIONHEADER ) );
    }

    // Create A Table To Add For Each Section
    PdfPTable table = new PdfPTable( 2 );

    table.setWidths( new int[]{ 2, 1 } );
    table.setWidthPercentage( 100.0f );
    table.setHorizontalAlignment( Element.ALIGN_LEFT );


    // For each DataElement and Category Combo of the dataElement, create
    // row.
    for ( DataElement dataElement : dataElements )
    {
        for ( CategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos() )
        {
            String categoryOptionComboDisplayName = "";

            // Hide Default category option combo name
            if ( !categoryOptionCombo.isDefault() )
            {
                categoryOptionComboDisplayName = categoryOptionCombo.getDisplayName();
            }

            addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), dataElement.getFormNameFallback() + " " +
                categoryOptionComboDisplayName, Element.ALIGN_RIGHT );

            String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + dataElement.getUid() + "_"
                + categoryOptionCombo.getUid();

            ValueType valueType = dataElement.getValueType();

            // Yes Only case - render as check-box
            if ( ValueType.TRUE_ONLY == valueType )
            {
                addCell_WithCheckBox( table, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), strFieldLabel );
            }
            else if ( ValueType.BOOLEAN == valueType )
            {
                // Create Yes - true, No - false, Select..
                String[] optionList = new String[]{ "[No Value]", "Yes", "No" };
                String[] valueList = new String[]{ "", "true", "false" };

                // addCell_WithRadioButton(table, writer, strFieldLabel);
                addCell_WithDropDownListField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), strFieldLabel, optionList, valueList );
            }
            else if ( valueType.isNumeric() )
            {
                Rectangle rectNum = new Rectangle( TEXTBOXWIDTH_NUMBERTYPE, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

                addCell_WithTextField( table, rectNum, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER );
            }
            else
            {
                addCell_WithTextField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), strFieldLabel );
            }
        }
    }

    PdfPCell cell_withInnerTable = new PdfPCell( table );
    cell_withInnerTable.setBorder( Rectangle.NO_BORDER );

    mainTable.addCell( cell_withInnerTable );
}
 
Example 12
Source File: BulkReceivingPdf.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
private PdfPTable createVendorAndDeliveryDetailsTable(){
    
    PdfPCell cell;
    Paragraph p = new Paragraph();

    float[] infoWidths = { 0.50f, 0.50f };
    PdfPTable infoTable = new PdfPTable(infoWidths);

    infoTable.setWidthPercentage(100);
    infoTable.setHorizontalAlignment(Element.ALIGN_CENTER);
    infoTable.setSplitLate(false);
    
    infoTable.addCell(getPDFCell("Vendor", getFormattedVendorAddress()));
    infoTable.addCell(getPDFCell("Delivery", getFormattedDeliveryAddress()));
    infoTable.addCell(getPDFCell("Reference Number\n", blkRecDoc.getShipmentReferenceNumber()));
    
    if (blkRecDoc.getCarrier() != null){
        infoTable.addCell(getPDFCell("Carrier\n", blkRecDoc.getCarrier().getCarrierDescription()));
    }else{
        infoTable.addCell(getPDFCell("Carrier\n", StringUtils.EMPTY));
    }
    
    infoTable.addCell(getPDFCell("Tracking/Pro Number\n", blkRecDoc.getTrackingNumber()));
    
    if (blkRecDoc.getPurchaseOrderIdentifier() != null){
        infoTable.addCell(getPDFCell("PO\n", blkRecDoc.getPurchaseOrderIdentifier().toString()));
    }else{
        infoTable.addCell(getPDFCell("PO\n", StringUtils.EMPTY));
    }
    
    infoTable.addCell(getPDFCell("# of Pieces\n", "" + blkRecDoc.getNoOfCartons()));
    infoTable.addCell(getPDFCell("Shipment Received Date\n", blkRecDoc.getShipmentReceivedDate().toString()));

    if (blkRecDoc.getShipmentWeight() != null){
        infoTable.addCell(getPDFCell("Weight\n", blkRecDoc.getShipmentWeight().toString()));
    }else{
        infoTable.addCell(getPDFCell("Weight\n", StringUtils.EMPTY));
    }
    
    infoTable.addCell(getPDFCell("\n", StringUtils.EMPTY));

    return infoTable;
}