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"
            });
            var template = new Template(section);

            var documentProperties = new DocumentProperties
            {
            };

            var sampleData = new DocumentData();

            var pageSizeInfo = new PageSizeInfo("A4");

            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, true);

            return(true);
        }
        static PaperKindItem ConvertToPaperKindItem(PaperKindData paperKindData)
        {
            float dpi       = DevExpress.XtraPrinting.GraphicsDpi.UnitToDpi(paperKindData.Unit);
            var   paperKind = (PaperKind)paperKindData.EnumId;
            SizeF size      = paperKind == PaperKind.Custom
                ? new SizeF(paperKindData.Width, paperKindData.Height)
                : PageSizeInfo.GetPageSizeF(paperKind, dpi, PageSizeInfo.DefaultSize);

            return(new PaperKindItem(paperKindData.Name, size, paperKindData.Id, paperKind, dpi, paperKindData.IsRollPaper));
        }
Beispiel #3
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var section = new Section();

            section.Pane.ElementList.Add(new Text {
                Value = "My label"
            });
            var template = new Template(section);

            var documentProperties = new DocumentProperties();

            var sampleData = new DocumentData();

            DocumentData documentData = null;

            var debug = false;

            var dialog = new System.Windows.Controls.PrintDialog
            {
                UserPageRangeEnabled = false,
                SelectedPagesEnabled = false,
            };

            if (dialog.ShowDialog() == true)
            {
                var printerSettings = new PrinterSettings
                {
                    Copies      = (short)(dialog.PrintTicket.CopyCount ?? 1),
                    PrinterName = dialog.PrintQueue.FullName,
                };

                PageSizeInfo pageSizeInfo  = null;
                var          pageMediaSize = dialog.PrintTicket.PageMediaSize;
                if (pageMediaSize.PageMediaSizeName != null)
                {
                    try
                    {
                        pageSizeInfo = new PageSizeInfo(pageMediaSize.PageMediaSizeName.Value.ToString());
                    }
                    catch (ArgumentException)
                    {
                        pageSizeInfo = new PageSizeInfo((pageMediaSize.Width / 96) + "inch", (pageMediaSize.Height / 96) + "inch");
                    }
                }

                var renderer = new Renderer(template, documentData, documentProperties, pageSizeInfo, debug);

                //Send document to the printer
                renderer.Print(printerSettings);

                //Create a pdf for the same document
                var data = renderer.GetPdfBinary();
            }
        }
        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);
        }
Beispiel #5
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);
        }
        private static void RenderPdf(Template template, DocumentProperties documentProperties = null, DocumentData documentData = null, PageSizeInfo pageSizeInfo = null, bool debug = true, bool portrait = true)
        {
            var renderer = new Renderer(template, documentData, documentProperties, pageSizeInfo, debug);
            var bytes    = renderer.GetPdfBinary(true, portrait);

            Task.Factory.StartNew(() => ExecuteFile(bytes));
        }
 public static async Task RenderPdfAsync(Template template, DocumentProperties documentProperties = null, DocumentData documentData = null, PageSizeInfo pageSizeInfo = null, bool debug = true, bool portrait = true)
 {
     await Task.Factory.StartNew(() => RenderPdf(template, documentProperties, documentData, pageSizeInfo, debug, portrait));
 }
        private static void RenderPrinter(Template template, DocumentProperties documentProperties = null, DocumentData documentData = null, PageSizeInfo pageSizeInfo = null, bool debug = true, bool portrait = true)
        {
            var renderer        = new Renderer(template, documentData, documentProperties, pageSizeInfo, debug);
            var printerSettings = new PrinterSettings {
            };

            var sw = new Stopwatch();

            sw.Start();

            renderer.Print(printerSettings, true);

            sw.Stop();
            System.Console.WriteLine(sw.Elapsed.TotalMilliseconds.ToString("0.0000"));
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }