I am trying to generate a PDF document but don't know how to control the Page size. As the printout is most likely A4, I would like to print it horizontally in order to fit my table in. The following is my code snippet. The first few rows of the table are the header.
// ----------------------------------------------
// Print Request Test Schedule Allocation
// -----------------------------------------------
private void cmdPrint_Click(object sender, EventArgs e)
{
FixedContentEditor editor;
RadFixedDocument document;
RadFixedPage page;
document = new RadFixedDocument();
page = document.Pages.AddPage();
editor = new FixedContentEditor(page, new SimplePosition());
Table table = new Table();
table.BorderCollapse = BorderCollapse.Separate;
table.LayoutType = TableLayoutType.AutoFit;
table.Margin = new System.Windows.Thickness(50);
table = SetTableHeader(table);
editor.DrawTable(table)
TableRow tableRow;
foreach (KeyValuePair<string, TDFCollection> tDFObject in T.FileList)
{
Block block = new Block();
string name = tDFObject.Value.TDFName;
string desc = tDFObject.Value.TDFDescription;
string requester = tDFObject.Value.Requester;
string duration = tDFObject.Value.Duration.ToString();
tableRow = table.Rows.AddTableRow();
tableRow.Cells.AddTableCell().PreferredWidth = 20;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.InsertText(name);
tableRow.Cells.AddTableCell().PreferredWidth = 30;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.InsertText(desc);
tableRow.Cells.AddTableCell().PreferredWidth = 35;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.InsertText(requester);
tableRow.Cells.AddTableCell().PreferredWidth = 5;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
block.TextProperties.FontSize = 12;
block.InsertText(duration);
}
editor.DrawTable(table);
int index = 0;
string agendaFile = null;
while (true)
{
index++;
agendaFile = T.TEST_Scheduling + "Request Allocation" + " (" + index.ToString() + ").pdf";
if (!File.Exists(agendaFile)) break;
}
PdfFormatProvider provider = new PdfFormatProvider();
try
{
using (Stream output = File.OpenWrite(agendaFile))
{
provider.Export(document, output);
}
}
catch (Exception ex)
{
T.WriteLine("PDF Stream Write Exception : " + ex.Message);
MessageBox.Show(ex.Message, "PDF Output Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Test Schedule Allocation Requests PDF is created", "Print Test Allocation Requests", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
// ---------------
// Set PDF Header
// ---------------
private Table SetTableHeader(Table table)
{
TableRow tableRow;
tableRow = table.Rows.AddTableRow();
tableRow.Cells.AddTableCell().PreferredWidth = 30;
Block block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize= 14;
block.GraphicProperties.FillColor = new RgbColor(0, 0, 139);
block.InsertText("TEST SCHEDULING REQUESTS");
tableRow = table.Rows.AddTableRow();
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.InsertText(" ");
tableRow = table.Rows.AddTableRow();
tableRow.Cells.AddTableCell().PreferredWidth = 30;
block.TextProperties.FontSize = 12;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.GraphicProperties.FillColor = new RgbColor(0, 0, 139);
block.TextProperties.UnderlineColor = new RgbColor(0, 0, 139);
block.InsertText("Test Definition");
block.InsertLineBreak();
tableRow.Cells.AddTableCell().PreferredWidth = 30;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.GraphicProperties.FillColor = new RgbColor(0, 0, 139);
block.TextProperties.UnderlineColor = new RgbColor(0, 0, 139);
block.InsertText("Description");
tableRow.Cells.AddTableCell().PreferredWidth = 35;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.GraphicProperties.FillColor = new RgbColor(0, 0, 139);
block.TextProperties.UnderlineColor = new RgbColor(0, 0, 139);
block.InsertText("Requester");
tableRow.Cells.AddTableCell().PreferredWidth = 5;
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.GraphicProperties.FillColor = new RgbColor(0, 0, 139);
block.TextProperties.UnderlineColor = new RgbColor(0, 0, 139);
block.InsertText("Duration");
block = tableRow.Cells.AddTableCell().Blocks.AddBlock();
block.TextProperties.FontSize = 12;
block.InsertText(" ");
return table;
}
}