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

The following examples show how to use org.apache.pdfbox.pdmodel.PDPageContentStream#setTextMatrix() . 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: VerticalTextCellDrawer.java    From easytable with 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
Source File: PDFCreator.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
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 File: CompatibilityHelper.java    From pdfbox-layout with 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));
   }