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

The following examples show how to use com.lowagie.text.pdf.PdfPCell#setPaddingTop() . 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: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeRequests() throws IOException, DocumentException {
	final Map<String, Long> childRequests = request.getChildRequestsExecutionsByRequestId();
	final boolean hasChildren = !childRequests.isEmpty();
	final Counter parentCounter = getCounterByRequestId(request);
	final boolean allChildHitsDisplayed = parentCounter != null
			&& parentCounter.getChildCounterName() != null && request.hasChildHits();

	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setLeading(2, 1);
	defaultCell.setPaddingTop(0);

	nextRow();
	writeRequest(request, -1, allChildHitsDisplayed);

	if (hasChildren) {
		writeChildRequests(childRequests, allChildHitsDisplayed);
	}
}
 
Example 2
Source File: PdfCounterRequestContextReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeRequests(List<CounterRequestContext> contexts)
		throws DocumentException, IOException {
	final PdfPCell defaultCell = getDefaultCell();
	final PdfPCell requestCell = new PdfPCell();
	final Paragraph phrase = new Paragraph("", cellFont);
	int margin = 0;
	for (final CounterRequestContext context : contexts) {
		writeRequest(context, requestCell, margin);
		margin += 5;
	}
	// on utilise ici PdfPCell et addElement pour que les propriétés
	// leading et indentationLeft des paragraphes soient prises en compte
	requestCell.addElement(phrase);
	requestCell.setGrayFill(defaultCell.getGrayFill());
	requestCell.setPaddingTop(defaultCell.getPaddingTop());
	addCell(requestCell);
}
 
Example 3
Source File: PDFUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static PdfPCell resetPaddings( PdfPCell cell, float top, float bottom, float left, float right )
{
    cell.setPaddingTop( top );
    cell.setPaddingBottom( bottom );
    cell.setPaddingLeft( left );
    cell.setPaddingRight( right );

    return cell;
}
 
Example 4
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequest childRequest, float executionsByRequest,
		boolean allChildHitsDisplayed) throws IOException, DocumentException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
	if (executionsByRequest != -1) {
		paragraph.setIndentationLeft(5);
	}
	final Counter parentCounter = getCounterByRequestId(childRequest);
	if (parentCounter != null && parentCounter.getIconName() != null) {
		paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
	}
	paragraph.add(new Phrase(childRequest.getName(), cellFont));
	final PdfPCell requestCell = new PdfPCell();
	requestCell.addElement(paragraph);
	requestCell.setGrayFill(defaultCell.getGrayFill());
	requestCell.setPaddingTop(defaultCell.getPaddingTop());
	addCell(requestCell);

	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	if (executionsByRequest != -1) {
		addCell(nbExecutionsFormat.format(executionsByRequest));
	} else {
		final boolean hasChildren = !request.getChildRequestsExecutionsByRequestId().isEmpty();
		if (hasChildren) {
			addCell("");
		}
	}
	writeRequestValues(childRequest, allChildHitsDisplayed);
}
 
Example 5
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 6
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 7
Source File: ExampleEAN128Test.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Example Barcode EAN128.
 */
@Test
public void main() throws Exception {

	// step 1
	Document document = new Document();
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ean128.pdf"));
	// step 3
	document.open();
	// step 4
	PdfContentByte cb = writer.getDirectContent();
	PdfPTable pageTot = new PdfPTable(1);
	pageTot.getDefaultCell().setPadding(0f);
	pageTot.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	pageTot.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	pageTot.setWidthPercentage(100f);
	// Data for the barcode : it is composed of 3 blocks whith AI 402, 90
	// and 421
	// The blocks whith the type 402 and 90 are of variable size so you must
	// put a FNC1
	// to delimitate the block
	String code402 = "24132399420058289" + Barcode128.FNC1;
	String code90 = "3700000050" + Barcode128.FNC1;
	String code421 = "422356";
	String data = code402 + code90 + code421;

	PdfPTable cell = new PdfPTable(1);
	cell.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	cell.getDefaultCell().setPadding(0f);

	PdfPCell info = new PdfPCell(new Phrase("Barcode EAN 128"));
	info.setBorder(Rectangle.NO_BORDER);
	pageTot.addCell(info);

	Barcode128 shipBarCode = new Barcode128();
	shipBarCode.setX(0.75f);
	shipBarCode.setN(1.5f);
	shipBarCode.setChecksumText(true);
	shipBarCode.setGenerateChecksum(true);
	shipBarCode.setSize(10f);
	shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
	shipBarCode.setBaseline(10f);
	shipBarCode.setCode(data);
	shipBarCode.setBarHeight(50f);

	Image imgShipBarCode = shipBarCode.createImageWithBarcode(cb, Color.black, Color.blue);
	PdfPCell shipment = new PdfPCell(new Phrase(new Chunk(imgShipBarCode, 0, 0)));
	shipment.setFixedHeight(shipBarCode.getBarcodeSize().getHeight() + 16f);
	shipment.setPaddingTop(5f);
	shipment.setPaddingBottom(10f);
	shipment.setBorder(Rectangle.BOX);
	shipment.setVerticalAlignment(Element.ALIGN_TOP);
	shipment.setHorizontalAlignment(Element.ALIGN_CENTER);
	cell.addCell(shipment);

	pageTot.addCell(cell);

	document.add(pageTot);

	// step 5
	document.close();
}