* @throws IOException If there is an error writing the data.
*/
public void doIt( String message, String outfile ) throws IOException
{
// the document
PDDocument doc = null;
try
{
doc = new PDDocument();
// Page 1
PDFont font = PDType1Font.HELVETICA;
PDPage page = new PDPage(PDRectangle.A4);
doc.addPage(page);
float fontSize = 12.0f;
PDRectangle pageSize = page.getMediaBox();
float centeredXPosition = (pageSize.getWidth() - fontSize/1000f)/2f;
float stringWidth = font.getStringWidth( message );
float centeredYPosition = (pageSize.getHeight() - (stringWidth*fontSize)/1000f)/3f;
PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, false);
contentStream.setFont( font, fontSize );
contentStream.beginText();
// counterclockwise rotation
for (int i=0;i<8;i++)
{
contentStream.setTextRotation(i*Math.PI*0.25, centeredXPosition,
pageSize.getHeight()-centeredYPosition);
contentStream.drawString( message + " " + i);
}
// clockwise rotation
for (int i=0;i<8;i++)
{
contentStream.setTextRotation(-i*Math.PI*0.25, centeredXPosition, centeredYPosition);
contentStream.drawString( message + " " + i);
}
contentStream.endText();
contentStream.close();
// Page 2
page = new PDPage(PDRectangle.A4);
doc.addPage(page);
fontSize = 1.0f;
contentStream = new PDPageContentStream(doc, page, false, false);
contentStream.setFont( font, fontSize );
contentStream.beginText();
// text scaling
for (int i=0;i<10;i++)
{
contentStream.setTextScaling(12+(i*6), 12+(i*6), 100, 100+i*50);
contentStream.drawString( message + " " +i);
}
contentStream.endText();
contentStream.close();
// Page 3
page = new PDPage(PDRectangle.A4);
doc.addPage(page);
fontSize = 1.0f;
contentStream = new PDPageContentStream(doc, page, false, false);
contentStream.setFont( font, fontSize );
contentStream.beginText();
int i = 0;
// text scaling combined with rotation
contentStream.setTextMatrix(12, 0, 0, 12, centeredXPosition, centeredYPosition*1.5);
contentStream.drawString( message + " " +i++);
contentStream.setTextMatrix(0, 18, -18, 0, centeredXPosition, centeredYPosition*1.5);
contentStream.drawString( message + " " +i++);
contentStream.setTextMatrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition*1.5);
contentStream.drawString( message + " " +i++);
contentStream.setTextMatrix(0, -30, 30, 0, centeredXPosition, centeredYPosition*1.5);
contentStream.drawString( message + " " +i++);
contentStream.endText();
contentStream.close();
doc.save( outfile );
}
finally
{
if( doc != null )
{
doc.close();
}
}
}