{
// 1. Add the page to the document!
Page page = new Page(document); // Instantiates the page inside the document context.
document.getPages().add(page); // Puts the page in the pages collection.
Dimension2D pageSize = page.getSize();
// 2. Create a content composer for the page!
PrimitiveComposer composer = new PrimitiveComposer(page);
// 3. Inserting contents...
// Set the font to use!
try
{
composer.setFont(
new StandardType1Font(
document,
StandardType1Font.FamilyEnum.Courier,
true,
false
),
32
);
}
catch(Exception e)
{}
EnumSet<AlignmentXEnum> xAlignments = EnumSet.allOf(AlignmentXEnum.class);
EnumSet<AlignmentYEnum> yAlignments = EnumSet.allOf(AlignmentYEnum.class);
int step = (int)(pageSize.getHeight()) / ((xAlignments.size()-1) * yAlignments.size()+1);
BlockComposer blockComposer = new BlockComposer(composer);
Rectangle2D frame = new Rectangle2D.Double(
30,
0,
pageSize.getWidth()-60,
step/2
);
blockComposer.begin(frame,AlignmentXEnum.Center,AlignmentYEnum.Middle);
blockComposer.showText(
"Simple text alignment"
);
blockComposer.end();
frame = new Rectangle2D.Double(
30,
pageSize.getHeight()-step/2,
pageSize.getWidth()-60,
step/2 -10
);
blockComposer.begin(frame,AlignmentXEnum.Left,AlignmentYEnum.Bottom);
composer.setFont(composer.getState().getFont(),10);
blockComposer.showText(
"NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
+ "NOTE: The rotation parameter can be freely defined as a floating point value."
);
blockComposer.end();
composer.setFont(composer.getState().getFont(),12);
int x = 30;
int y = step;
int alignmentIndex = 0;
for(AlignmentXEnum alignmentX
: EnumSet.allOf(AlignmentXEnum.class))
{
/*
NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
applying the justified alignment has no effect (it degrades to center alignment);
in order to get such an effect, use BlockComposer instead.
*/
if(alignmentX.equals(AlignmentXEnum.Justify))
continue;
for(AlignmentYEnum alignmentY
: EnumSet.allOf(AlignmentYEnum.class))
{
if(alignmentIndex % 2 == 0)
{
composer.beginLocalState();
composer.setFillColor(BackColor);
composer.drawRectangle(
new Rectangle2D.Double(
0,
y-step/2,
pageSize.getWidth(),
step
)
);
composer.fill();
composer.end();
}
composer.showText(
alignmentX + " " + alignmentY + ":",
new Point2D.Double(x,y),
AlignmentXEnum.Left,
AlignmentYEnum.Middle,
0
);
y+=step;
alignmentIndex++;
}
}
float rotationStep = 0;
float rotation = 0;
for(
int columnIndex = 0;
columnIndex < 2;
columnIndex++
)
{
switch(columnIndex)
{
case 0:
x = 200;
rotationStep = 0;
break;
case 1:
x = (int)pageSize.getWidth() / 2 + 100;
rotationStep = 360 / ((xAlignments.size()-1) * yAlignments.size()-1);
break;
}
y = step;
rotation = 0;