Java Code Examples for org.apache.pdfbox.pdmodel.PDPageContentStream#setTextMatrix()

The following examples show how to use org.apache.pdfbox.pdmodel.PDPageContentStream#setTextMatrix() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: easytable   File: VerticalTextCellDrawer.java    License: MIT License 6 votes vote down vote up
protected void drawText(String text, PDFont font, int fontSize, Color color, float x, float y, PDPageContentStream contentStream) throws IOException {
    // Rotate by 90 degrees counter clockwise
    final AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
    transform.concatenate(AffineTransform.getRotateInstance(Math.PI * 0.5));
    transform.concatenate(AffineTransform.getTranslateInstance(-x, -y - fontSize));

    contentStream.moveTo(x, y);
    contentStream.beginText();

    // Do the transformation :)
    contentStream.setTextMatrix(transform);

    contentStream.setNonStrokingColor(color);
    contentStream.setFont(font, fontSize);
    contentStream.newLineAtOffset(x, y);
    contentStream.showText(text);
    contentStream.endText();
    contentStream.setCharacterSpacing(0);
}
 
Example 2
private static void writeText(PDPageContentStream contentStream, Color color, PDFont font, float fontSize, boolean rotate, float x, float y, String... text)
		throws IOException {
	contentStream.beginText();
	// set font and font size
	contentStream.setFont(font, fontSize);
	// set text color
	contentStream.setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
	if (rotate) {
		// rotate the text according to the page rotation
		contentStream.setTextMatrix(Matrix.getRotateInstance(Math.PI / 2, x, y));
	} else {
		contentStream.setTextMatrix(Matrix.getTranslateInstance(x, y));
	}
	if (text.length > 1) {
		contentStream.setLeading(25f);

	}
	for (String line : text) {
		contentStream.showText(line);
		contentStream.newLine();
	}
	contentStream.endText();
}
 
Example 3
Source Project: pdfbox-layout   File: CompatibilityHelper.java    License: MIT License 4 votes vote down vote up
public static void setTextTranslation(
    final PDPageContentStream contentStream, final float x,
    final float y) throws IOException {
contentStream.setTextMatrix(Matrix.getTranslateInstance(x, y));
   }