resources = new PDResources();
page.setResources( resources );
}
//Setup page content stream and paint background/title
PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, false);
PDFont font = PDType1Font.HELVETICA_BOLD;
contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
contentStream.beginText();
float fontSize = 96;
contentStream.setFont(font, fontSize);
String text = "OVERLAY";
//float sw = font.getStringWidth(text);
//Too bad, base 14 fonts don't return character metrics.
PDRectangle crop = page.getCropBox();
float cx = crop.getWidth() / 2f;
float cy = crop.getHeight() / 2f;
AffineTransform transform = new AffineTransform();
transform.translate(cx, cy);
transform.rotate(Math.toRadians(45));
transform.translate(-190 /* sw/2 */, 0);
contentStream.setTextMatrix(transform);
contentStream.drawString(text);
contentStream.endText();
contentStream.close();
doc.save(targetFile.getAbsolutePath());
}
finally
{