PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:57 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
 Post subject: Table not showing up
PostPosted: Sat Jan 18, 2014 7:25 am 
Offline

Joined: Sat Jan 18, 2014 7:21 am
Posts: 1
I get my template loaded and the strings intro, title and person are rendered properly, but my table doesn't show up. Any ideas as to what I'm doing wrong?

Code:
class Program
    {
        static void Main(string[] args)
        {
            SIMSEntities db = new SIMSEntities();
            Guid id = Guid.Parse("1D883A82-76B7-4B25-8F5C-5680118C779B");
            Deliverable deliverable = db.Deliverables.Single(i => i.id == id);

            PdfDocument pdf = new PdfDocument();

            //create the first page
            PdfPage pg = new PdfPage();
            PdfDocument template = PdfReader.Open(@"Z:/myTemplate.pdf", PdfDocumentOpenMode.Import);
            pg = pdf.AddPage(template.Pages[0]);
            XGraphics graphic = XGraphics.FromPdfPage(pg);
            XTextFormatter tf = new XTextFormatter(graphic);


            //Introduction to every page
            string intro = "The following quality controls were documented in the SIMS Deliverable tool.";
            string title = "Title: " + deliverable.title;
            string person = "Person Responsible: " + deliverable.Person.FullName;

            Document doc = new Document();
            Section section = doc.AddSection();
            Paragraph para = section.AddParagraph();
            para.Format.Font.Name = "Verdana";
            para.Format.Font.Size = 8;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            para.AddText(intro);
            para.AddLineBreak();
            para.AddLineBreak();
            para.AddText(title);
            para.AddLineBreak();
            para.AddText(person);

            var table = section.AddTable();
            table.Borders.Width = 0.25;
            table.Rows.LeftIndent = 0;
            Column column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;
            column = table.AddColumn("4cm");
            column.Format.Alignment = ParagraphAlignment.Left;
            column = table.AddColumn("6cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Type of Review");
            row.Cells[0].MergeDown = 1;
            row.Cells[1].AddParagraph("Date Required");
            row.Cells[2].AddParagraph("Date Completed");

            row = table.AddRow();
            row.Cells[1].AddParagraph("Comments");
            row.Cells[1].MergeRight = 1;

            table.SetEdge(0, 0, table.Columns.Count, table.Rows.Count, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);

            //int numberOrRows = 0;
            //var actions = deliverable.DeliverableActions.ToList();
            //foreach (DeliverableAction a in actions)
            //{
            //    row = table.AddRow();
            //    row.HeadingFormat = false;
            //    row.Cells[0].AddParagraph(a.TypeAction.type_name);
            //    row.Cells[1].AddParagraph(((a.date_required_completed.HasValue) ? a.date_required_completed.Value.ToString("dd/mm/yyyy") : ""));
            //    row.Cells[2].AddParagraph(((a.date_completed.HasValue) ? a.date_completed.Value.ToString("dd/mm/yyyy") : ""));
            //    row = table.AddRow();
            //    row.Cells[1].AddParagraph(a.comments);
            //    numberOrRows = numberOrRows + 2;
            //}//end DA loop
            //table.SetEdge(0, 0, table.Columns.Count, table.Rows.Count, Edge.Box, BorderStyle.Single, 0.75);

            MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRenderer.PrepareDocument();
            docRenderer.RenderObject(graphic, XUnit.FromCentimeter(2), XUnit.FromCentimeter(4), "18cm", para);

            // string SaveLocationPdf = ServerSavePath + deliverable.id.ToString() + "_Report.pdf";
            string SaveLocationPdf = "qac_" + deliverable.title + ".pdf";
            pdf.Save(@"Z:\" + SaveLocationPdf);
            pdf.Close();
        }


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 130 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