Java Code Examples for com.lowagie.text.pdf.ColumnText#setSimpleColumn()

The following examples show how to use com.lowagie.text.pdf.ColumnText#setSimpleColumn() . 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: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void writePageAnchor(int pageIndex) throws DocumentException 
{
	Map<Attribute,Object> attributes = new HashMap<Attribute,Object>();
	fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider()));
	Font pdfFont = getFont(attributes, getLocale(), false);
	Chunk chunk = new Chunk(" ", pdfFont);
	
	chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

	tagHelper.startPageAnchor();
	
	ColumnText colText = new ColumnText(pdfContentByte);
	colText.setSimpleColumn(
		new Phrase(chunk),
		0,
		pageFormat.getPageHeight(),
		1,
		1,
		0,
		Element.ALIGN_LEFT
		);

	colText.go();

	tagHelper.endPageAnchor();
}
 
Example 2
Source File: PdfLogicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ColumnText reconfigure( PdfContentByte cb, Phrase p ) {
  float filledWidth = ColumnText.getWidth( p, runDirection, 0 ) + 0.5f;
  ColumnText ct = new ColumnText( cb );
  ct.setRunDirection( runDirection );
  if ( alignment == Element.ALIGN_LEFT ) {
    ct.setSimpleColumn( llx, lly, llx + filledWidth, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_RIGHT ) {
    ct.setSimpleColumn( urx - filledWidth, lly, urx, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_CENTER ) {
    float delta = ( ( urx - llx ) - filledWidth ) / 2;
    ct.setSimpleColumn( urx + delta, lly, urx - delta, ury, leading, alignment );
  } else {
    ct.setSimpleColumn( llx, lly, urx, ury, leading, alignment );
  }
  return ct;
}
 
Example 3
Source File: ColumnSimpleTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrating the use of ColumnText
 */
@Test
public void main() throws Exception {

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

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("columnsimple.pdf"));

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

	// step 4:

	// we grab the ContentByte and do some stuff with it
	PdfContentByte cb = writer.getDirectContent();

	BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
	Font font = new Font(bf, 11, Font.NORMAL);

	ColumnText ct = new ColumnText(cb);
	ct.setSimpleColumn(60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
	ct.addText(new Phrase(15, "UNI\n", font));
	for (int i = 0; i < 27; i++) {
		ct.addText(new Phrase(15, uni[i] + "\n", font));
	}
	ct.go();
	cb.rectangle(103, 295, 52, 8 + 28 * 15);
	cb.stroke();
	ct.setSimpleColumn(105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
	ct.addText(new Phrase(15, "char\n", font));
	for (int i = 0; i < 27; i++) {
		ct.addText(new Phrase(15, code[i] + "\n", font));
	}
	ct.go();
	ct.setSimpleColumn(160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
	ct.addText(new Phrase(15, "NAME" + "\n", font));
	for (int i = 0; i < 27; i++) {
		ct.addText(new Phrase(15, name[i] + "\n", font));
	}
	ct.go();

	// step 5: we close the document
	document.close();
}
 
Example 4
Source File: ColumnTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrating the use of ColumnText
 */
@Test
public void main() throws Exception {

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

	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("column.pdf"));

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

	// step 4:

	// we create some content
	BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
	Font font = new Font(bf, 11, Font.NORMAL);

	Phrase unicodes = new Phrase(15, "UNI\n", font);
	Phrase characters = new Phrase(15, "\n", font);
	Phrase names = new Phrase(15, "NAME\n", font);

	for (int i = 0; i < 27; i++) {
		unicodes.add(uni[i] + "\n");
		characters.add(code[i] + "\n");
		names.add(name[i] + "\n");
	}

	// we grab the ContentByte and do some stuff with it
	PdfContentByte cb = writer.getDirectContent();

	ColumnText ct = new ColumnText(cb);
	ct.setSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
	ct.go();
	cb.rectangle(103, 295, 52, 8 + 28 * 15);
	cb.stroke();
	ct.setSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
	ct.go();
	ct.setSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
	ct.go();

	// step 5: we close the document
	document.close();
}
 
Example 5
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
public void exportImage(JRPrintImage printImage) throws DocumentException, IOException,  JRException
{
	if (printImage.getModeValue() == ModeEnum.OPAQUE)
	{
		setFillColor(printImage.getBackcolor());
		pdfContentByte.rectangle(
			printImage.getX() + getOffsetX(),
			pageFormat.getPageHeight() - printImage.getY() - getOffsetY(),
			printImage.getWidth(),
			- printImage.getHeight()
			);
		pdfContentByte.fill();
		resetFillColor();
	}

	InternalImageProcessor imageProcessor =
		new InternalImageProcessor(printImage);
	
	Renderable renderer = printImage.getRenderer();

	if (
		renderer != null 
		&& imageProcessor.availableImageWidth > 0 
		&& imageProcessor.availableImageHeight > 0
		)
	{
		InternalImageProcessorResult imageProcessorResult = null;
		
		try
		{
			imageProcessorResult = imageProcessor.process(renderer);
		}
		catch (Exception e)
		{
			Renderable onErrorRenderer = getRendererUtil().handleImageError(e, printImage.getOnErrorTypeValue());
			if (onErrorRenderer != null)
			{
				imageProcessorResult = imageProcessor.process(onErrorRenderer);
			}
		}

		if (imageProcessorResult != null)
		{
			setAnchor(imageProcessorResult.chunk, printImage, printImage);
			setHyperlinkInfo(imageProcessorResult.chunk, printImage);

			tagHelper.startImage(printImage);
			
			ColumnText colText = new ColumnText(pdfContentByte);
			int upperY = pageFormat.getPageHeight() - printImage.getY() - imageProcessor.topPadding - getOffsetY() - imageProcessorResult.yoffset;
			int lowerX = printImage.getX() + imageProcessor.leftPadding + getOffsetX() + imageProcessorResult.xoffset;
			colText.setSimpleColumn(
				new Phrase(imageProcessorResult.chunk),
				lowerX,
				upperY,
				lowerX + imageProcessorResult.scaledWidth,
				upperY - imageProcessorResult.scaledHeight,
				0,
				Element.ALIGN_LEFT
				);

			colText.go();

			tagHelper.endImage();
		}
	}


	if (
		printImage.getLineBox().getTopPen().getLineWidth() <= 0f &&
		printImage.getLineBox().getLeftPen().getLineWidth() <= 0f &&
		printImage.getLineBox().getBottomPen().getLineWidth() <= 0f &&
		printImage.getLineBox().getRightPen().getLineWidth() <= 0f
		)
	{
		if (printImage.getLinePen().getLineWidth() > 0f)
		{
			exportPen(printImage.getLinePen(), printImage);
		}
	}
	else
	{
		/*   */
		exportBox(
			printImage.getLineBox(),
			printImage
			);
	}
}
 
Example 6
Source File: PdfTextRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void draw()
{
	TabSegment segment = segments.get(segmentIndex);
	
	float advance = segment.layout.getVisibleAdvance();//getAdvance();
	
	ColumnText colText = new ColumnText(pdfContentByte);
	colText.setSimpleColumn(
		pdfExporter.getPhrase(segment.as, segment.text, text),
		x + drawPosX + leftOffsetFactor * advance,// + leftPadding
		pdfExporter.getCurrentPageFormat().getPageHeight()
			- y
			- topPadding
			- verticalAlignOffset
			//- text.getLeadingOffset()
			+ lineHeight
			- drawPosY,
		x + drawPosX + advance + rightOffsetFactor * advance,// + leftPadding
		pdfExporter.getCurrentPageFormat().getPageHeight()
			- y
			- topPadding
			- verticalAlignOffset
			//- text.getLeadingOffset()
			-400//+ lineHeight//FIXMETAB
			- drawPosY,
		0,//text.getLineSpacingFactor(),// * text.getFont().getSize(),
		horizontalAlignment == Element.ALIGN_JUSTIFIED && (!segment.isLastLine || (isLastParagraph && justifyLastLine)) 
			? Element.ALIGN_JUSTIFIED_ALL : horizontalAlignment
		);

	//colText.setLeading(0, text.getLineSpacingFactor());// * text.getFont().getSize());
	colText.setLeading(lineHeight);
	colText.setRunDirection(
		text.getRunDirectionValue() == RunDirectionEnum.LTR
		? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_RTL
		);

	try
	{
		colText.go();
	}
	catch (DocumentException e)
	{
		throw new JRRuntimeException(e);
	}
}