using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.composition;
using it.stefanochizzolini.clown.documents.contents.fonts;
using it.stefanochizzolini.clown.files;
using System;
using System.Drawing;
namespace it.stefanochizzolini.clown.samples{
/**
<summary>This sample generates a series of pages from the default page formats available,
both in size and orientation.</summary>
*/
public class PageFormatSample
: ISample
{
#region dynamic
#region interface
#region public
#region ISample
public void Run(
SampleLoader loader
)
{
// 1. PDF file instantiation.
File file = new File();
// 2. Get the document associated to the file!
Document document = file.Document;
// 3. Populate the document!
Populate(document);
// (boilerplate metadata insertion -- ignore it)
loader.BuildAccessories(document,this.GetType(),"Page Format","page formats");
// 4. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
loader.Serialize(file,this.GetType().Name,false);
}
#endregion
#endregion
#region private
private void Populate(
Document document
)
{
StandardType1Font bodyFont = new StandardType1Font(
document,
StandardType1Font.FamilyNameEnum.Courier,
true,
false
);
Pages pages = document.Pages;
foreach(
PageFormat.SizeEnum pageFormat
in (PageFormat.SizeEnum[])Enum.GetValues(typeof(PageFormat.SizeEnum))
)
{
foreach(
PageFormat.OrientationEnum pageOrientation
in (PageFormat.OrientationEnum[])Enum.GetValues(typeof(PageFormat.OrientationEnum))
)
{
// Add a page to the document!
Page page = new Page(document); // Instantiates the page inside the document context.
pages.Add(page); // Puts the page in the pages collection.
// Set the page size!
page.Size = PageFormat.GetSize(
pageFormat,
pageOrientation
);
// Drawing the text label on the page...
SizeF pageSize = page.Size.Value;
PrimitiveFilter builder = new PrimitiveFilter(page);
builder.SetFont(bodyFont,32);
builder.ShowText(
pageFormat + " (" + pageOrientation + ")", // Text.
new PointF(
pageSize.Width / 2,
pageSize.Height / 2
), // Location: page center.
AlignmentXEnum.Center, // Place the text on horizontal center of the location.
AlignmentYEnum.Middle, // Place the text on vertical middle of the location.
45 // Rotate the text 45 degrees counterclockwise.
);
builder.Flush();
}
}
}
#endregion
#endregion
#endregion
}
}
|