Example #1
0
        private static DocumentData GetData()
        {
            var data = new DocumentData();

            //Prepare the data for the table
            var documentDataTable = new DocumentDataTable("MyTable");
            var totalSum          = 0;

            for (var i = 0; i < 100; i++)
            {
                var val = i * 70;
                totalSum += val;

                documentDataTable.AddRow(new Dictionary <string, string>
                {
                    { "FirstCol", "Col 1 Row " + i },
                    { "SecondCol", val.ToString("#,##0.00") },
                    { "ThirdCol", new string((char)(65 + (i / 4)), 1 + (i % 20)) }
                });
            }

            data.Add(documentDataTable);

            //Prepare some other data
            data.Add("SomeOtherData", "This is some custom data");
            data.Add("TotalSum", totalSum.ToString("#,##0.00"));

            return(data);
        }
        protected override void Arrange()
        {
            _table = new Table();
            _table.AddColumn(new TableColumn {
                Value = "A1", Title = "A2"
            });
            _table.AddColumn(new TableColumn {
                Value = "B1", Title = "B2"
            });

            _documentData = new DocumentData();
            _documentData.Add("A1", "Data_A1");
            _documentData.Add("A2", "Data_A2");
            _documentData.Add("B1", "Data_B1");
            _documentData.Add("B2", "Data_B2");

            _graphicsMock = new Mock <IGraphics>(MockBehavior.Strict);
            _graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XStringFormat>())).Returns(new XSize());
            _graphicsMock.Setup(x => x.DrawLine(It.IsAny <XPen>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>()));

            _renderDataMock = new Mock <IRenderData>(MockBehavior.Strict);
            _renderDataMock.Setup(x => x.ParentBounds).Returns(It.IsAny <XRect>());
            _renderDataMock.SetupSet(x => x.ElementBounds = It.IsAny <XRect>());
            _renderDataMock.Setup(x => x.ElementBounds).Returns(It.IsAny <XRect>());
            _renderDataMock.Setup(x => x.Section).Returns(new Section());
            _renderDataMock.Setup(x => x.Graphics).Returns(_graphicsMock.Object);
            _renderDataMock.Setup(x => x.DocumentData).Returns(_documentData);
        }
        public void When_using_onte_template_and_rendering_several_times_with_different_data()
        {
            var graphicsMock = new Mock <IGraphics>(MockBehavior.Strict);

            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>())).Returns(new XSize());
            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XStringFormat>())).Returns(new XSize());
            graphicsMock.Setup(x => x.DrawString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XBrush>(), It.IsAny <XPoint>(), It.IsAny <XStringFormat>()));

            var graphicsFactoryMock = new Mock <IGraphicsFactory>(MockBehavior.Strict);

            graphicsFactoryMock.Setup(x => x.PrepareGraphics(It.IsAny <PdfPage>(), It.IsAny <DocumentRenderer>(), It.IsAny <int>())).Returns(graphicsMock.Object);

            //Arrange
            var section = new Section();

            section.Pane.ElementList.Add(new TextBox {
                Value = "{Data}", Width = "2cm", Height = "2cm"
            });
            var templage = new Template(section);
            var data1    = new DocumentData();

            data1.Add("Data", "AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM NNN OOO PPP QQQ RRR SSS TTT");
            var renderer1 = new Renderer(graphicsFactoryMock.Object, templage, data1);
            var binary1   = renderer1.GetPdfBinary();

            var data2 = new DocumentData();

            data2.Add("Data", "AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM NNN OOO PPP QQQ RRR SSS TTT UUU VVV XXX YYY ZZZ");
            var renderer2 = new Renderer(graphicsFactoryMock.Object, templage, data2);

            //Act
            var binary2 = renderer2.GetPdfBinary();

            //Assert
        }
Example #4
0
        public void When_serializing_and_deserializing_data_with_group_lines()
        {
            //Arrange
            var originalDocumentData = new DocumentData();
            var tableData            = new DocumentDataTable("A");

            tableData.AddGroup("Group1");
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1A" }, { "Col2", "Data2A" }
            });
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1B" }, { "Col2", "Data2B" }
            });
            tableData.AddGroup("Group2");
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1C" }, { "Col2", "Data2C" }
            });
            originalDocumentData.Add(tableData);
            var xmlDocumentData = originalDocumentData.ToXml();

            //Act
            var loadedDocumentData = DocumentData.Load(xmlDocumentData);

            //Assert
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count, loadedDocumentData.GetDataTable("A").Rows.Count);
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData));
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup));
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value);
        }
        public void Document_with_table()
        {
            //Arrange
            var documentData = new DocumentData();
            var t            = new DocumentDataTable("TableA");
            var row          = new Dictionary <string, string>();

            row.Add("Row1A", "RowData1A");
            row.Add("Row1B", "RowData1B");
            row.Add("Row1C", "RowData1C");
            t.AddRow(row);

            var row2 = new Dictionary <string, string>();

            row2.Add("Row2A", "RowData2A");
            row2.Add("Row2B", "RowData2A");
            row2.Add("Row2C", "RowData2A");
            t.AddRow(row2);

            documentData.Add(t);
            var xml = documentData.ToXml();

            //Act
            var other = DocumentData.Load(xml);

            //Assert
            Assert.AreEqual(documentData.Get("A"), other.Get("A"));
            Assert.AreEqual(documentData.GetDataTable("TableA").Rows.Count, other.GetDataTable("TableA").Rows.Count);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Key);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Value);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Key);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Value);
            Assert.AreEqual(xml.OuterXml, other.ToXml().OuterXml);
        }
        private DocumentData GetData(string language)
        {
            var documentData = new DocumentData();

            switch (language)
            {
            case "English":
                documentData.Add("Title", "Manual for Tharga Reporter");
                break;

            case "Svenska":
                documentData.Add("Title", "Manual för Tharga Reporter");
                break;
            }

            return(documentData);
        }
Example #7
0
        protected override void Arrange()
        {
            _dataPart  = "DataX";
            _dataValue = "DataValue";
            _input     = string.Format("ABC {{{0}}}", _dataPart);

            _documentData = new DocumentData();
            _documentData.Add(_dataPart, _dataValue);
        }
        public override async Task <bool> InvokeAsync(string paramList)
        {
            var bgImage = @"C:\skalleberg_v1.png"; //_settingBusiness.GetSetting("BackgroundImageUrl");
            var image   = new Image
            {
                Source       = bgImage,
                Top          = "48%",
                Height       = "48%",
                IsBackground = true
            };

            var section = new Section {
                Margin = new UnitRectangle {
                    Left = "6mm", Top = "2mm", Bottom = "2mm", Right = "6mm"
                }
            };

            section.Pane.ElementList.Add(new BarCode {
                Code = "{BarCode}", Top = "10%", Left = "20%", Width = "75%", Height = "60%"
            });
            section.Pane.ElementList.Add(image);
            section.Pane.ElementList.Add(new Text {
                Value = "Begonia", Font = new Font {
                    Size = 18
                }
            });
            section.Pane.ElementList.Add(new Text {
                Value = "100.00 Kr", Font = new Font {
                    Size = 18
                }, TextAlignment = TextBase.Alignment.Right
            });
            section.Pane.ElementList.Add(new Text {
                Value = "Holland", TextAlignment = TextBase.Alignment.Right, Left = "100%", Top = "90%"
            });
            var template = new Template(section);

            var documentProperties = new DocumentProperties
            {
            };

            var sampleData = new DocumentData();

            sampleData.Add("BarCode", "A");

            var pageSizeInfo = new PageSizeInfo("89mm", "36mm");

            await PdfCommand.RenderPdfAsync(template, documentProperties, sampleData, pageSizeInfo, false, true);

            //var renderer = new Renderer(template, sampleData, documentProperties, pageSizeInfo, false);
            //var printerSettings = new PrinterSettings { };
            //renderer.Print(printerSettings, true);

            return(true);
        }
Example #9
0
        public async override Task <bool> InvokeAsync(string paramList)
        {
            var section = new Section();

            section.Pane.ElementList.Add(new Rectangle {
                BorderColor = Color.Black, Left = "1cm", Top = "1cm", Bottom = "1cm", Right = "1cm"
            });
            section.Pane.ElementList.Add(new Line {
                Top = "0", Left = "0", Bottom = "0", Right = "0"
            });
            section.Pane.ElementList.Add(new Image {
                Source = "{Img1}", Height = "150", Top = "50", Left = "50", Width = "250"
            });
            section.Pane.ElementList.Add(new Image {
                Source = "{Img2}", Height = "150", Top = "200", Left = "50"
            });
            var template = new Template(section);

            var documentProperties = new DocumentProperties
            {
            };

            //Image from url
            var sampleData = new DocumentData();

            sampleData.Add("Img1", "http://www.thargelion.se/Images/Logotype/Thargelion-White-Icon-150.pngx");

            //Image from byte[]. Convert to string with Encoding Windows-1252
            var imageAsbyteArrayData         = GetImageAsbyteArrayData();
            var dataAsStringToSendToReporter = Encoding.GetEncoding(1252).GetString(imageAsbyteArrayData);

            sampleData.Add("Img2", dataAsStringToSendToReporter);

            var pageSizeInfo = new PageSizeInfo("A4");

            await PdfCommand.RenderPdfAsync(template, documentProperties, sampleData, pageSizeInfo, false, true);

            return(true);
        }
        public void Document_with_data()
        {
            //Arrange
            var documentData = new DocumentData();

            documentData.Add("A", "DataA");
            var xml = documentData.ToXml();

            //Act
            var other = DocumentData.Load(xml);

            //Assert
            Assert.AreEqual(documentData.Get("A"), other.Get("A"));
            Assert.AreEqual(documentData.GetDataTable("TableA"), other.GetDataTable("TableA"));
            Assert.AreEqual(xml.OuterXml, other.ToXml().OuterXml);
        }
Example #11
0
        public override async Task <bool> InvokeAsync(string paramList)
        {
            var section = new Section();

            section.Margin = new UnitRectangle {
                Left = "2cm", Top = "1cm", Bottom = "1cm", Right = "1cm"
            };
            section.Header.Height = "3cm";
            section.Footer.Height = "3cm";

            var r1 = new ReferencePoint();

            section.Pane.ElementList.Add(r1);
            var cellTitleFont = new Font {
                Size = 6
            };
            var cellDataFont = new Font {
                Size = 16
            };

            r1.ElementList.Add(new Rectangle {
                Height = "1cm", Width = "60mm"
            });
            r1.ElementList.Add(new Text {
                Top = "1mm", Left = "1mm", Value = "Name", Font = cellTitleFont
            });
            r1.ElementList.Add(new Text {
                Top = "3mm", Left = "1mm", Value = "{NameData}", Font = cellDataFont
            });

            r1.ElementList.Add(new Rectangle {
                Height = "1cm", Width = "60mm", Left = "60mm"
            });
            r1.ElementList.Add(new Text {
                Top = "1mm", Left = "61mm", Value = "Address", Font = cellTitleFont
            });
            r1.ElementList.Add(new Text {
                Top = "3mm", Left = "61mm", Value = "{AddressData}", Font = cellDataFont
            });

            r1.ElementList.Add(new Rectangle {
                Height = "1cm", Width = "20mm", Left = "120mm"
            });
            r1.ElementList.Add(new Text {
                Top = "1mm", Left = "121mm", Value = "Country", Font = cellTitleFont
            });
            r1.ElementList.Add(new Text {
                Top = "3mm", Left = "121mm", Value = "{CountryData}", Font = cellDataFont
            });

            //Make a copy and change it...
            var r2 = r1.Clone();

            section.Pane.ElementList.Add(r2);
            r2.Top += "1cm";

            //Create a content box.
            var r3 = new ReferencePoint {
                Top = "25mm"
            };

            section.Pane.ElementList.Add(r3);
            r3.ElementList.Add(new Rectangle {
                Height = "3cm", Width = "10cm"
            });

            //Create a checkbox with text
            var rc1 = new ReferencePoint();

            r3.ElementList.Add(rc1);
            rc1.ElementList.Add(new Rectangle {
                Left = "2mm", Width = "5mm", Height = "5mm", Top = "2mm"
            });
            rc1.ElementList.Add(new Line {
                Left = "2mm", Width = "5mm", Height = "5mm", Top = "2mm"
            });
            rc1.ElementList.Add(new Line {
                Left = "2mm", Width = "5mm", Height = "-5mm", Top = "7mm"
            });
            rc1.ElementList.Add(new Text {
                Left = "1cm", Top = "3mm", Value = "This value has been selected.", Font = cellDataFont
            });

            //Copy the checkbox and change text
            var rc2 = rc1.Clone();

            rc2.Top += "1cm";
            (rc2.ElementList.Last() as Text).Value = "Some other option.";
            r3.ElementList.Add(rc2);

            //Copy the checkbox and change text
            var rc3 = rc2.Clone();

            rc3.Top += "1cm";
            (rc2.ElementList.Last() as Text).Value = "Yet another option.";
            r3.ElementList.Add(rc3);


            var template           = new Template(section);
            var documentProperties = new DocumentProperties();
            var sampleData         = new DocumentData();

            sampleData.Add("NameData", "Kalle Anka");
            sampleData.Add("AddressData", "Storgatan 1");
            sampleData.Add("CountryData", "SE");

            var pageSizeInfo = new PageSizeInfo("A4");
            await PdfCommand.RenderPdfAsync(template, documentProperties, sampleData, pageSizeInfo, false, true);

            return(true);
        }
Example #12
0
        public void When_rendering_several_times_with_the_same_template()
        {
            //Arrange
            var table1 = new Table {
                Name = "TableA", Top = "2cm", Height = "5cm"
            };

            table1.AddColumn(new TableColumn {
                Value = "ColumnA1", Title = "Column A", Width = "2cm", WidthMode = Table.WidthMode.Auto, Align = Table.Alignment.Left, HideValue = string.Empty
            });
            var section = new Section();

            section.Pane.ElementList.Add(table1);
            var template      = new Template(section);
            var documentData1 = new DocumentData();
            var tbl1          = new DocumentDataTable("TableA");

            documentData1.Add(tbl1);
            for (var i = 0; i < 30; i++)
            {
                var row1 = new Dictionary <string, string>();
                row1.Add("ColumnA1", "DataA" + i);
                tbl1.AddRow(row1);
            }

            var documentData2 = new DocumentData();
            var tbl2          = new DocumentDataTable("TableA");

            documentData2.Add(tbl2);
            for (var i = 0; i < 10; i++)
            {
                var row2 = new Dictionary <string, string>();
                row2.Add("ColumnA1", "DataA" + i);
                tbl2.AddRow(row2);
            }

            var documentData3 = new DocumentData();
            var tbl3          = new DocumentDataTable("TableA");

            documentData3.Add(tbl3);
            for (var i = 0; i < 20; i++)
            {
                var row3 = new Dictionary <string, string>();
                row3.Add("ColumnA1", "DataA" + i);
                tbl3.AddRow(row3);
            }

            var graphicsMock = new Mock <IGraphics>(MockBehavior.Strict);

            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>())).Returns(new XSize());
            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XStringFormat>())).Returns(new XSize());
            graphicsMock.Setup(x => x.DrawString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XBrush>(), It.IsAny <XPoint>(), It.IsAny <XStringFormat>()));

            var graphicsFactoryMock = new Mock <IGraphicsFactory>(MockBehavior.Strict);

            graphicsFactoryMock.Setup(x => x.PrepareGraphics(It.IsAny <PdfPage>(), It.IsAny <DocumentRenderer>(), It.IsAny <int>())).Returns(graphicsMock.Object);

            var renderer1 = new Renderer(graphicsFactoryMock.Object, template, documentData1);
            var renderer2 = new Renderer(graphicsFactoryMock.Object, template, documentData2);
            var renderer3 = new Renderer(graphicsFactoryMock.Object, template, documentData3);

            //Act
            var data1 = renderer1.GetPdfBinary();
            var data2 = renderer2.GetPdfBinary();
            var data3 = renderer3.GetPdfBinary();

            //Assert
            //Assert.AreEqual(data1, data2);
        }
Example #13
0
        public async override Task <bool> InvokeAsync(string paramList)
        {
            //TODO: Put code that creates an example invoice here
            var sections = GetSections();
            var template = new Template(sections.First());

            foreach (var section in sections.TakeAllButFirst())
            {
                template.SectionList.Add(section);
            }

            var documentProperties = new DocumentProperties();
            var sampleData         = new DocumentData();
            var documentDataTable  = new DocumentDataTable("OrderItems");

            documentDataTable.AddGroup("ABC");
            documentDataTable.AddRow(
                new Dictionary <string, string>
            {
                { "Description", "Begonina extrapris röda fina" },
                { "Details", "ABC123_xAB111x" },
                { "DateAdded", "2015-01-01" },
                { "AddedBy", "DB" },
                { "AmountDescription", "12x24" },
                { "Count", "1'000" },
                { "NetNormalItemPrice", "1'000.00" },
                { "DiscountPercentage", "10" },
                { "NetSaleItemPrice", "1'000.00" },
                { "NetSaleTotalPrice", "1'000.00" },
            });
            for (var i = 0; i < 60; i++)
            {
                documentDataTable.AddRow(
                    new Dictionary <string, string>
                {
                    { "Description", "A" },
                    { "Details", "" },
                    { "DateAdded", "C" },
                    { "AddedBy", "" },
                    { "AmountDescription", "E" },
                    { "Count", "F" },
                    { "NetNormalItemPrice", "G" },
                    { "DiscountPercentage", "H" },
                    { "NetSaleItemPrice", "" },
                    { "NetSaleTotalPrice", "J" },
                });
            }
            sampleData.Add(documentDataTable);

            var paymentDataTable = new DocumentDataTable("Payments");

            paymentDataTable.AddRow(new Dictionary <string, string>
            {
                { "PaymentMethod", "A1" },
                { "PaymentDate", "" },
                { "PaymentSum", "C1" }
            });

            paymentDataTable.AddRow(new Dictionary <string, string>
            {
                { "PaymentMethod", "A2" },
                { "PaymentDate", "B2" },
                { "PaymentSum", "C2" }
            });

            sampleData.Add(paymentDataTable);

            //System.IO.File.WriteAllText(@"C:\a.xml", template.ToXml().OuterXml);

            //await PdfCommand.RenderPrinterAsync(template, documentProperties, sampleData, null, false);

            var sw = new Stopwatch();

            sw.Start();

            //TODO: Time this function and try to make it as fast as possible
            var pageSizeInfo    = new PageSizeInfo("A4");
            var renderer        = new Renderer(template, sampleData, documentProperties, pageSizeInfo, false, PrinterInteractionMode.None);
            var printerSettings = new PrinterSettings {
                PrinterName = "Microsoft XPS Document Writer", PrintFileName = @"C:\temp\a.xps", PrintToFile = true
            };

            renderer.Print(printerSettings, true);

            OutputInformation("It took " + sw.Elapsed.TotalSeconds + "s to send to printer."); //BEFORE: 01 519,796ms

            return(true);
        }
Example #14
0
        public override async Task <bool> InvokeAsync(string paramList)
        {
            var section = new Section();
            var table   = new Table
            {
                Name   = "A",
                Top    = "100",
                Bottom = "100",
                Left   = "50",
                Right  = "50",

                HeaderBackgroundColor = Color.Pink,
                //HeaderBorderColor = Color.Blue,
                //ColumnBorderColor = Color.Green,
                //ContentBorderColor = Color.DeepPink,
                //GroupBorderColor = Color.Chocolate,

                SkipLine = new SkipLine
                {
                    Height      = "5",
                    Interval    = 3,
                    BorderColor = Color.Red
                }
            };

            table.AddColumn(new TableColumn {
                Title = "First", Value = "{A1}"
            });
            table.AddColumn(new TableColumn {
                Title = "Second", Value = "{A2}"
            });
            section.Pane.ElementList.Add(table);
            var template = new Template(section);

            var documentProperties = new DocumentProperties();

            var sampleData        = new DocumentData();
            var documentDataTable = new DocumentDataTable("A");

            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "Some stuff" }, { "A2", "Some stuff" },
            });
            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "Some stuff on the second row" }, { "A2", "Blah" },
            });
            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "And on the third row" }, { "A2", "blah blah blah" },
            });
            for (var i = 0; i < 10; i++)
            {
                documentDataTable.AddRow(new Dictionary <string, string> {
                    { "A1", i.ToString() }, { "A2", "hästmos" },
                });
            }

            sampleData.Add(documentDataTable);

            var pageSizeInfo = new PageSizeInfo("A4");

            await PdfCommand.RenderPdfAsync(template, documentProperties, sampleData, pageSizeInfo, false, true);

            return(true);
        }