com.lowagie.text.pdf.PdfContentByte Java Examples

The following examples show how to use com.lowagie.text.pdf.PdfContentByte. 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: FormComboTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Generates an Acroform with a Combobox
 */
@Test
public void main() throws Exception {

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

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

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

	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	String options[] = { "Red", "Green", "Blue" };
	PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
	field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
	field.setFieldName("ACombo");
	field.setValueAsString("Red");
	writer.addAnnotation(field);

	// step 5: we close the document
	document.close();
}
 
Example #2
Source File: ArabicTextTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draws arabic text using java.awt.Graphics2D.
    */
@Test
public void main() throws Exception {
   	// step 1
       Document document = new Document(PageSize.A4, 50, 50, 50, 50);
       try {
       	// step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "arabictext.pdf"));
           // step 3
           document.open();
           // step 4
           String text1 = "This text has \u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631 123,456 \u0645\u0646 (Arabic)";
           java.awt.Font font = new java.awt.Font("arial", 0, 18);
           PdfContentByte cb = writer.getDirectContent();
           java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
           g2.setFont(font);
           g2.drawString(text1, 100, 100);
           g2.dispose();
           cb.sanityCheck();
           // step 5
           document.close();
       }
       catch (Exception de) {
           de.printStackTrace();
       }
   }
 
Example #3
Source File: SimplePdfTextRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void initialize(
	JRPdfExporter pdfExporter, 
	PdfContentByte pdfContentByte,
	JRPrintText text, 
	JRStyledText styledText, 
	int offsetX,
	int offsetY
	)
{
	super.initialize(
		pdfExporter, 
		pdfContentByte,
		text, 
		styledText, 
		offsetX,
		offsetY
		);
	
	yLine = 
		pdfExporter.getCurrentPageFormat().getPageHeight()
			- y
			- topPadding
			- verticalAlignOffset
			- text.getLeadingOffset();
}
 
Example #4
Source File: PurapPdf.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Overrides the method in PdfPageEventHelper from itext to write the headerTable, compose the footer and show the
 * footer.
 *
 * @param writer    The PdfWriter for this document.
 * @param document  The document.
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    LOG.debug("onEndPage() started.");
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    // write the headerTable
    headerTable.setTotalWidth(document.right() - document.left());
    headerTable.writeSelectedRows(0, -1, document.left(), document.getPageSize().height() - 10, cb);
    // compose the footer
    String text = "Page " + writer.getPageNumber() + " of ";
    float textSize = helv.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();
    cb.setFontAndSize(helv, 12);
    // show the footer
    float adjust = helv.getWidthPoint("0", 12);
    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);
    cb.endText();
    cb.addTemplate(tpl, document.right() - adjust, textBase);
    cb.saveState();
}
 
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: Image.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets an instance of a Image from a java.awt.Image.
 * The image is added as a JPEG with a user defined quality.
 *
 * @param cb
 *            the <CODE>PdfContentByte</CODE> object to which the image will be added
 * @param awtImage
 *            the <CODE>java.awt.Image</CODE> to convert
 * @param quality
 *            a float value between 0 and 1
 * @return an object of type <CODE>PdfTemplate</CODE>
 * @throws BadElementException
 *             on error
 * @throws IOException
 */
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException {
    java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage,
            0, 0, -1, -1, true);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new IOException(
                "java.awt.Image Interrupted waiting for pixels!");
    }
    if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) {
        throw new IOException("java.awt.Image fetch aborted or errored");
    }
    int w = pg.getWidth();
    int h = pg.getHeight();
    PdfTemplate tp = cb.createTemplate(w, h);
    Graphics2D g2d = tp.createGraphics(w, h, true, quality);
    g2d.drawImage(awtImage, 0, 0, null);
    g2d.dispose();
    return getInstance(tp);
}
 
Example #7
Source File: PdfEventHandler.java    From unitime with Apache License 2.0 6 votes vote down vote up
/**
   * Print footer string on each page
   * @param writer
   * @param document
   */
  public void onEndPage(PdfWriter writer, Document document) {
   
  	if(getDateTime() == null) {
  		setDateTime(new Date());
  	}
  	
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), 
	    document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), 
	    document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
		(document.left() + document.right()) / 2, 20, 0);
cb.endText();
	
      return;
  }
 
Example #8
Source File: LineSeparator.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draws a horizontal line.
 * @param canvas	the canvas to draw on
 * @param leftX		the left x coordinate
 * @param rightX	the right x coordindate
 * @param y			the y coordinate
 */
public void drawLine(PdfContentByte canvas, float leftX, float rightX, float y) {
	float w;
    if (getPercentage() < 0)
        w = -getPercentage();
    else
        w = (rightX - leftX) * getPercentage() / 100.0f;
    float s;
    switch (getAlignment()) {
        case Element.ALIGN_LEFT:
            s = 0;
            break;
        case Element.ALIGN_RIGHT:
            s = rightX - leftX - w;
            break;
        default:
            s = (rightX - leftX - w) / 2;
            break;
    }
    canvas.setLineWidth(getLineWidth());
    if (getLineColor() != null)
        canvas.setColorStroke(getLineColor());
    canvas.moveTo(s + leftX, y + offset);
    canvas.lineTo(s + w + leftX, y + offset);
    canvas.stroke();
}
 
Example #9
Source File: OddEvenTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
 * 
 * @param args
 *            [0] the file with the odd pages [1] the file with the even
 *            pages [2] the resulting file
 */
public void main(String... args) throws Exception {
	if (args.length < 3) {
		System.err.println("OddEven needs 3 Arguments.");
		System.out
				.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
		return;
	}
	RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
	RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
	Image img = TiffImage.getTiffImage(odd, 1);
	Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
	for (int c = 0; c < count; ++c) {

		Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
		Image imgEven = TiffImage.getTiffImage(even, count - c);
		document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
		document.newPage();
		imgOdd.setAbsolutePosition(0, 0);
		cb.addImage(imgOdd);
		document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
		document.newPage();
		imgEven.setAbsolutePosition(0, 0);
		cb.addImage(imgEven);

	}
	odd.close();
	even.close();
	document.close();

}
 
Example #10
Source File: FloatingBoxesTest.java    From itext2 with GNU Lesser General Public License v3.0 5 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 x1 = position.getLeft() + 2;
	float x2 = position.getRight() - 2;
	float y1 = position.getTop() - 2;
	float y2 = position.getBottom() + 2;
	PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
	canvas.setRGBColorStroke(0xFF, 0x00, 0x00);
	canvas.rectangle(x1, y1, x2 - x1, y2 - y1);
	canvas.stroke();
	canvas.resetRGBColorStroke();
}
 
Example #11
Source File: DottedLineSeparator.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
 */
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
	canvas.saveState();
	canvas.setLineWidth(lineWidth);
	canvas.setLineCap(PdfContentByte.LINE_CAP_ROUND);
	canvas.setLineDash(0, gap, gap / 2);
       drawLine(canvas, llx, urx, y);
	canvas.restoreState();
}
 
Example #12
Source File: PDFPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void simulateBold( PdfContentByte cb, int fontWeight )
{
	cb.setTextRenderingMode( PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE );
	if ( fontWeightLineWidthMap.containsKey( fontWeight ) )
	{
		cb.setLineWidth( fontWeightLineWidthMap.get( fontWeight ) );
	}
	else
	{
		cb.setLineWidth( 0.225f );
	}
	cb.setTextMatrix( 0, 0 );
}
 
Example #13
Source File: SimpleRegistrationFormTest.java    From itext2 with GNU Lesser General Public License v3.0 5 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) {
	TextField tf = new TextField(writer, position, fieldname);
	tf.setFontSize(12);
	try{
		PdfFormField field = tf.getTextField();
		writer.addAnnotation(field);
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
Example #14
Source File: PDFPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void drawTotalPage( String text, int textX, int textY, int width,
		int height, TextStyle textInfo, float scale )
{
	PdfTemplate template = pageDevice.getPDFTemplate( scale );
	if ( template != null )
	{
		PdfContentByte tempCB = this.contentByte;
		this.containerHeight = template.getHeight( );
		this.contentByte = template;
		drawText( text, textX, textY, width, height, textInfo );
		this.contentByte = tempCB;
		this.containerHeight = pageHeight;
	}
}
 
Example #15
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void upperLeftAlignmentMark(final PdfContentByte cb) {
    cb.saveState();
    cb.rectangle(ALIGNMENT_MARGIN,
                 (LETTER.height() + TOP_MARGIN) - ALIGNMENT_MARK_HEIGHT - ALIGNMENT_MARGIN,
                 ALIGNMENT_MARK_WIDTH,
                 ALIGNMENT_MARK_HEIGHT);
    cb.setColorFill(BLACK);
    cb.fill();
    cb.restoreState();
}
 
Example #16
Source File: SimpleTable.java    From gcs with Mozilla Public License 2.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[])
 */
@Override
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(this);
	int bd = rect.getBorder();
	rect.setBorder(Rectangle.NO_BORDER);
	canvases[PdfPTable.BACKGROUNDCANVAS].rectangle(rect);
	rect.setBorder(bd);
	rect.setBackgroundColor(null);
	canvases[PdfPTable.LINECANVAS].rectangle(rect);
}
 
Example #17
Source File: ChunksTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Demonstrates some Chunk functionality.
 */
@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
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Chunks.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Chunk fox = new Chunk("quick brown fox");
	float superscript = 8.0f;
	fox.setTextRise(superscript);
	fox.setBackground(new Color(0xFF, 0xDE, 0xAD));
	Chunk jumps = new Chunk(" jumps over ");
	Chunk dog = new Chunk("the lazy dog");
	float subscript = -8.0f;
	dog.setTextRise(subscript);
	dog.setUnderline(new Color(0xFF, 0x00, 0x00), 3.0f, 0.0f, -5.0f + subscript, 0.0f,
			PdfContentByte.LINE_CAP_ROUND);
	document.add(fox);
	document.add(jumps);
	document.add(dog);

	// step 5: we close the document
	document.close();
}
 
Example #18
Source File: CashReceiptCoverSheetServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Responsible for creating a new PDF page and workspace through <code>{@link PdfContentByte}</code> for direct writing to the
 * PDF.
 *
 * @param writer The PDF writer used to write to the new page with.
 * @param reader The PDF reader used to read information from the PDF file.
 * @param pageNumber The current number of pages in the PDF file, which will be incremented by one inside this method.
 *
 * @return The PDFContentByte used to access the new PDF page.
 * @exception DocumentException
 * @exception IOException
 */
protected PdfContentByte startNewPage(PdfWriter writer, PdfReader reader, ModifiableInteger pageNumber) throws DocumentException, IOException {
    PdfContentByte retval;
    PdfContentByte under;
    Rectangle pageSize;
    Document pdfDoc;
    PdfImportedPage newPage;

    pageNumber.increment();
    pageSize = reader.getPageSize(FRONT_PAGE);
    retval = writer.getDirectContent();
    // under = writer.getDirectContentUnder();

    if (pageNumber.getInt() > FRONT_PAGE) {
        newPage = writer.getImportedPage(reader, CHECK_PAGE_NORMAL);
        setCurrentRenderingYPosition(pageSize.top(TOP_MARGIN + CHECK_DETAIL_HEADING_HEIGHT));
    }
    else {
        newPage = writer.getImportedPage(reader, FRONT_PAGE);
        setCurrentRenderingYPosition(pageSize.top(TOP_FIRST_PAGE));
    }

    pdfDoc = retval.getPdfDocument();
    pdfDoc.newPage();
    retval.addTemplate(newPage, 0, 0);
    retval.setFontAndSize(getTextFont(), 8);

    return retval;
}
 
Example #19
Source File: FieldPositioningEvents.java    From itext2 with GNU Lesser General Public License v3.0 5 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 rect, PdfContentByte[] canvases) {
	if (cellField == null || (fieldWriter == null && parent == null)) throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
	cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	if (parent == null)
		fieldWriter.addAnnotation(cellField);
	else
		parent.addKid(cellField);
}
 
Example #20
Source File: ItextPDFWatermarkWriter.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
private int getOrientation(PdfContentByte canvas, int pageNumber) {
	Rectangle pageSize = document.getPageSize(pageNumber);
	if (pageSize.getHeight() > pageSize.getWidth()) {
		return PAGE_ORIENTATION_PORTRAIT;
	} else {
		return PAGE_ORIENTATION_LANDSCAPE;
	}
}
 
Example #21
Source File: PdfGlyphGraphics2D.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PdfGlyphGraphics2D(PdfContentByte pdfContentByte, JRPdfExporter pdfExporter, Locale locale)
{
	super(pdfContentByte, 
			pdfExporter.getCurrentPageFormat().getPageWidth(), pdfExporter.getCurrentPageFormat().getPageHeight(), 
			null, true, false, 0);		
	this.initialized = true;
	this.pdfContentByte = pdfContentByte;
	this.pdfExporter = pdfExporter;
	this.locale = locale;
}
 
Example #22
Source File: PageNumbersWatermarkTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onStartPage(PdfWriter writer, Document document) {
    if (writer.getPageNumber() < 3) {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(Color.pink);
        cb.beginText();
        cb.setFontAndSize(helv, 48);
        cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
        cb.endText();
        cb.restoreState();
    }
}
 
Example #23
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
protected void exportBox(JRLineBox box, JRPrintElement element)
{
	exportTopPen(box.getTopPen(), box.getLeftPen(), box.getRightPen(), element);
	exportLeftPen(box.getTopPen(), box.getLeftPen(), box.getBottomPen(), element);
	exportBottomPen(box.getLeftPen(), box.getBottomPen(), box.getRightPen(), element);
	exportRightPen(box.getTopPen(), box.getBottomPen(), box.getRightPen(), element);

	pdfContentByte.setLineDash(0f);
	pdfContentByte.setLineCap(PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
}
 
Example #24
Source File: FloatingBoxesTest.java    From itext2 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[][] width, float[] height, int headerRows, int rowStart,
		PdfContentByte[] canvases) {
	float widths[] = width[0];
	float x1 = widths[0];
	float x2 = widths[widths.length - 1];
	float y1 = height[0];
	float y2 = height[height.length - 1];
	PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
	canvas.setRGBColorStroke(0x00, 0x00, 0xFF);
	canvas.rectangle(x1, y1, x2 - x1, y2 - y1);
	canvas.stroke();
	canvas.resetRGBColorStroke();
}
 
Example #25
Source File: RenderingTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Special rendering of Chunks.
 * 
 */
@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
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Rendering.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Paragraph p = new Paragraph("Text Rendering:");
	document.add(p);
	Chunk chunk = new Chunk("rendering test");
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL, 100f, new Color(0xFF, 0x00, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.3f, new Color(0xFF, 0x00, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, 100f, new Color(0x00, 0xFF, 0x00));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_STROKE, 0.3f, new Color(0x00, 0x00, 0xFF));
	document.add(chunk);
	document.add(Chunk.NEWLINE);
	Chunk bold = new Chunk("This looks like Font.BOLD");
	bold.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.5f, new Color(0x00, 0x00, 0x00));
	document.add(bold);

	// step 5: we close the document
	document.close();
}
 
Example #26
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void lowerRightAlignmentMark(final PdfContentByte cb) {
    cb.saveState();
    cb.rectangle(LETTER.width() - (ALIGNMENT_MARGIN * 4) - ALIGNMENT_MARK_WIDTH,
                 ALIGNMENT_MARGIN,
                 ALIGNMENT_MARK_WIDTH,
                 ALIGNMENT_MARK_HEIGHT);
    cb.setColorFill(BLACK);
    cb.fill();
    cb.restoreState();
}
 
Example #27
Source File: GroupsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Prints 3 circles in different colors that intersect with eachother.
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
public static void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
	PdfGState gs = new PdfGState();
	gs.setBlendMode(PdfGState.BM_SOFTLIGHT);
	gs.setFillOpacity(0.7f);
	cb.setGState(gs);
    cb.setColorFill(Color.gray);
    cb.circle(x + 70, y + 70, 50);
    cb.fill();
    cb.circle(x + 100, y + 130, 50);
    cb.fill();
    cb.circle(x + 130, y + 70, 50);
    cb.fill();
}
 
Example #28
Source File: TransparencyTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Prints a square and fills half of it with a gray rectangle.
 * 
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
private static void pictureBackdrop(float x, float y, PdfContentByte cb)
		throws Exception {
	cb.setColorStroke(Color.black);
	cb.setColorFill(Color.gray);
	cb.rectangle(x, y, 100, 200);
	cb.fill();
	cb.setLineWidth(2);
	cb.rectangle(x, y, 200, 200);
	cb.stroke();
}
 
Example #29
Source File: VerticalTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writing vertical text.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	texts[3] = convertCid(texts[0]);
	texts[4] = convertCid(texts[1]);
	texts[5] = convertCid(texts[2]);
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("vertical.pdf"));
	int idx = 0;
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	for (int j = 0; j < 2; ++j) {
		BaseFont bf = BaseFont.createFont("KozMinPro-Regular", encs[j],	false);
		cb.setRGBColorStroke(255, 0, 0);
		cb.setLineWidth(0);
		float x = 400;
		float y = 700;
		float height = 400;
		float leading = 30;
		int maxLines = 6;
		for (int k = 0; k < maxLines; ++k) {
			cb.moveTo(x - k * leading, y);
			cb.lineTo(x - k * leading, y - height);
		}
		cb.rectangle(x, y, -leading * (maxLines - 1), -height);
		cb.stroke();
		VerticalText vt = new VerticalText(cb);
		vt.setVerticalLayout(x, y, height, maxLines, leading);
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20)));
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20, 0, Color.blue)));
		vt.go();
		vt.setAlignment(Element.ALIGN_RIGHT);
		vt.addText(new Chunk(texts[idx++],	new Font(bf, 20, 0, Color.orange)));
		vt.go();
		document.newPage();
	}
	document.close();

}
 
Example #30
Source File: PdfLogicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected PdfTextSpec( final StyleSheet layoutContext, final PdfOutputProcessorMetaData metaData,
    final PdfGraphics2D g2, final BaseFontFontMetrics fontMetrics, final PdfContentByte cb ) {
  super( layoutContext, metaData, g2 );
  if ( fontMetrics == null ) {
    throw new NullPointerException();
  }
  if ( cb == null ) {
    throw new NullPointerException();
  }
  this.fontMetrics = fontMetrics;
  this.contentByte = cb;
}