PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Performance
http://forum.pdfsharp.com/viewtopic.php?f=2&t=461
Page 1 of 1

Author:  archdukefranz [ Wed Sep 03, 2008 11:18 am ]
Post subject:  Performance

Its taking a minute and a half to create a pdf with about 181 rows

Is that normal, seems excessive to me... here is my code anyway




Code:
        public static MigraDoc.DocumentObjectModel.Document createPdfDocument(ListView objectList)
        {

            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
            document.Info.Title = objectList.ListTitle;
            document.Info.Author = "ObjectViews";
            MigraDoc.DocumentObjectModel.Style style;

            // Get the predefined style Normal.
            style = document.Styles["Normal"];
            // Because all styles are derived from Normal, the next line changes the
            // font of the whole document. Or, more exactly, it changes the font of
            // all styles and paragraphs that do not redefine the font.

            style.Font.Name = "Verdana";
            style.Font.Name = "Times New Roman";
            style.Font.Size = 10;

            MigraDoc.DocumentObjectModel.Section section = document.AddSection();
            section.PageSetup.LeftMargin = new MigraDoc.DocumentObjectModel.Unit(0);
            section.PageSetup.TopMargin = new MigraDoc.DocumentObjectModel.Unit(0);
            section.PageSetup.BottomMargin = new MigraDoc.DocumentObjectModel.Unit(0);
            MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
            table.Borders.Width = 0.25;
            table.Borders.Left.Width = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent = 0;




            for (int i = 0; i < objectList.ListMap.ColumnCount; i++)
            {
                if (objectList.ListMap[i].Type != "display")
                    continue;
                Column column = objectList.ListMap[i];
                MigraDoc.DocumentObjectModel.Tables.Column c = table.AddColumn(new MigraDoc.DocumentObjectModel.Unit(double.Parse(column.Width), MigraDoc.DocumentObjectModel.UnitType.Point));
            }
            MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
            for (int i = 0; i < objectList.ListMap.ColumnCount; i++)
            {
                if (objectList.ListMap[i].Type != "display")
                    continue;
                Column column = objectList.ListMap[i];
                row.Cells[i].AddParagraph(objectList.ObjectViewManager.GetString(column.Label));
            }
            for (int j = 0; j < objectList.list.Count; j++)
            {
                object entity = objectList.list[j];
                row = table.AddRow();
                for (int i = 0; i < objectList.ListMap.ColumnCount; i++)
                {
                    if (objectList.ListMap[i].Type != "display")
                        continue;
                    Column column = objectList.ListMap[i];
                    object value = ObjectViewUtils.GetValue(entity, column.Member);
                    if (value == null) row.Cells[i].AddParagraph("");
                    else if (value.GetType().Name == "DateTime") row.Cells[i].AddParagraph(((DateTime)value).ToString(column.Format));
                    else row.Cells[i].AddParagraph(value.ToString());
                }
            }
            return document;
        }


Code:
                        pdfRenderer.Document = createPdfDocument(objectList);
                        pdfRenderer.RenderDocument();
                        MemoryStream stream = new MemoryStream();
                        pdfRenderer.Save(stream, false);
                        Page.Response.Clear();
                        Page.Response.ContentType = "application/pdf";
                        Page.Response.AddHeader("content-length", stream.Length.ToString());
                        Page.Response.BinaryWrite(stream.ToArray());
                        Page.Response.Flush();
                        stream.Close();
                        Page.Response.End();

Author:  Thomas Hoevel [ Wed Sep 03, 2008 2:03 pm ]
Post subject: 

This is a known MigraDoc problem with the rendering of tables.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/