Hi all,
This is an extension of a question I had here:
viewtopic.php?f=2&t=2618I restructured the code to be like the example:
Code:
# region New PDF Code
public void createPDFDocument()
{
const string filename = "C:\\Users\\mkautzman\\Desktop\\Strasburg\\trunk\\Documents\\WorkingPDF.pdf";
Document tDoc = CreateDocument();
PdfDocumentRenderer tRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
tRenderer.Document = tDoc;
tRenderer.RenderDocument();
try
{
tRenderer.PdfDocument.Save(filename);
Process.Start(filename);
}
catch (Exception e)
{
Response.Write("A File with the same name is already open");
}
}
public static Document CreateDocument()
{
Document tDoc = new Document();
tDoc.Info.Title = "Strasburg Bank Financial Statement Report";
tDoc.Info.Author = "Strasburg Bank";
DefineStyles(tDoc);
DefineContentSection(tDoc);
BuildTables(tDoc);
return tDoc;
}
public static void DefineStyles(Document tDoc)
{
tDoc.DefaultPageSetup.TopMargin = MigraDoc.DocumentObjectModel.Unit.FromInch(0.75);
tDoc.DefaultPageSetup.BottomMargin = MigraDoc.DocumentObjectModel.Unit.FromInch(.6);
tDoc.DefaultPageSetup.LeftMargin = MigraDoc.DocumentObjectModel.Unit.FromInch(.5);
tDoc.DefaultPageSetup.RightMargin = MigraDoc.DocumentObjectModel.Unit.FromInch(.5);
tDoc.DefaultPageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
MigraDoc.DocumentObjectModel.Style style = tDoc.Styles["Normal"];
style.Font.Name = "Consolas";
style.Font.Size = 11;
}
public static void DefineContentSection(Document tDoc)
{
Section tSec = tDoc.AddSection();
tSec.PageSetup.StartingNumber = 1;
HeaderFooter header = tSec.Headers.FirstPage;
header.AddParagraph("Text goes here -- Primary Page Header");
}
public static void BuildTables(Document tDoc)
{
TableAddHeading(tDoc);
TableAddCurrentAssets(tDoc);
}
public static void TableAddHeading(Document tDoc)
{
MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table();
table.Borders.Width = 0.2;
table.Rows.LeftIndent = 0;
Column column = table.AddColumn("740pt");
column.Format.Alignment = ParagraphAlignment.Center;
Row row = table.AddRow();
row.HeadingFormat = true;
row.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xa2d2a2"));
row.Cells[0].AddParagraph("Balance Sheet/Financial Statement");
tDoc.LastSection.Add(table);
}
public static void TableAddCurrentAssets(Document tDoc)
{
MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table();
table.Borders.Width = 0.2;
table.Rows.LeftIndent = 0;
Column columnData = table.AddColumn("295pt");
columnData.Borders.Left.Visible = false;
Column columnValue = table.AddColumn("70pt");
Row rowA = table.AddRow();
rowA.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xa2a2d2"));
rowA.Cells[0].AddParagraph("CURRENT FARM ASSETS");
rowA.Cells[1].AddParagraph("$ Value");
rowA.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row1 = table.AddRow();
row1.Borders.Bottom.Visible = false;
row1.Cells[0].AddParagraph("Cash: Savings: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Savings + ") Checking: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Checking + ")");
row1.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.CashTotal);
row1.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row2 = table.AddRow();
row2.Borders.Bottom.Visible = false;
row2.Cells[0].AddParagraph("Invest: Time Cret $" + MP.FormFinancialStatement.CurrentStaticAssets.TimeCret + " Other: $" + MP.FormFinancialStatement.CurrentStaticAssets.OtherInvestments + "");
row2.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.InvestTotal);
row2.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row3 = table.AddRow();
row3.Borders.Bottom.Visible = false;
row3.Cells[0].AddParagraph("Replacement Account");
row3.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.ReplacementAccount);
row3.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row4 = table.AddRow();
row4.Cells[0].AddParagraph("Accouts and Notes Recievable");
row4.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.AccountsNotesReceivable);
row4.Cells[1].Format.Alignment = ParagraphAlignment.Right;
tDoc.LastSection.Add(table);
}
Which does generate a PDF proper, the problem I have now is I'm not sure how to place items in my right column. Currently, this will of course populate the left column appropriately, but it just builds down and I'm not sure I can force it to put stuff in a second column.
Basically, I get this (Table repeated several times to test page break):
http://i.imgur.com/0hqA4SF.pngBut I need to be able to generate this:
http://i.imgur.com/bv374Kd.pngWith all the 'Liabilities' tables, etc., in their position there current position. Is there a way to do that?
The end game here is that I basically need this (Currently an HTML form):
http://i.imgur.com/HHL373W.pngin to a PDF almost exactly as it looks there.