PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Mar 29, 2024 9:04 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Oct 29, 2013 10:31 am 
Offline

Joined: Thu Aug 08, 2013 9:18 pm
Posts: 4
Hi all,

This is an extension of a question I had here: viewtopic.php?f=2&t=2618

I 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.png

But I need to be able to generate this: http://i.imgur.com/bv374Kd.png

With 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.png

in to a PDF almost exactly as it looks there.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 162 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group