예제 #1
0
        private void CreateLabelHelper()
        {
            //  Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate { View.StartSyncAnimation(); }, null);

            //  ReportEngine repEngine = _container.Resolve<ReportEngine>() as ReportEngine;
            List <WPFBarcode> wpfBarcode  = View.LabelData();
            LabelPrintHelper  printHelper = _container.Resolve <LabelPrintHelper>() as LabelPrintHelper;

            this.xpsRep = printHelper.CreateLabels(wpfBarcode, View.NumberAcross, View.NumberDown, View.TopMargin, View.SideMargin);
//            this.xpsRep = repEngine.CreateLabels(wpfBarcode, View.NumberAcross, View.NumberDown, View.TopMargin, View.SideMargin);

            this.DisplayLabels();
            //Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate { this.DisplayLabels(); }, null);
            //Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate { View.EndSyncAnimation(); }, null);
        }
예제 #2
0
        //int minimalOffset = 0;

        /// <summary>
        /// Helper method to create page header o footer from flow document template
        /// </summary>
        /// <param name="fd"></param>
        /// <param name="pageDef"></param>
        /// <returns></returns>
        public static XpsDocument CreateXpsDocument(FlowDocument fd, PageDefinition pageDef)
        {
            MemoryStream ms  = new MemoryStream();
            Package      pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);

            string pack = "pack://" + fd.Name + System.Guid.NewGuid().ToString() + ".xps";

            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument doc = new XpsDocument(pkg, CompressionOption.SuperFast, pack);

            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);

            DocumentPaginator paginator = ((IDocumentPaginatorSource)fd).DocumentPaginator;
            // Size size = new Size(800, 1024);
            // ReportPaginator rp = new ReportPaginator(paginator, PrintHelper.GetPageSize(), pageDef);
            // ReportPaginator rp = new ReportPaginator(paginator, size, pageDef);
            LabelPaginator rp = new LabelPaginator(paginator, LabelPrintHelper.GetPageSize(), pageDef);

            rsm.SaveAsXaml(rp);

            return(doc);
        }
예제 #3
0
        public XpsDocument CreateLabels(List <WPFBarcode> listBarcode, int numberAcross, int numberDown, double topMargin, double sideMargin)
        {
            //int pageWidth = 700;//just for testing !! get it from your printer
            int          pageWidth = (int)LabelPrintHelper.GetImagebleWidth(); //XpsPrintHelper.GetPageWidth();
            FlowDocument fd        = new FlowDocument();

            fd.ColumnWidth = pageWidth; //pageWidth-2*sideMargin*96;

            Table table1 = new Table();

            // ...and add it to the FlowDocument Blocks collection.
            fd.Blocks.Add(table1);

            // Set some global formatting properties for the table.
            table1.CellSpacing = 0;
            // table1.to



            // Create columns and add them to the table's Columns collection.
            /// Create a local print server

            double colWidth = (pageWidth - 2 * sideMargin * 96) / numberAcross;


            for (int x = 0; x < numberAcross; x++)
            {
                TableColumn tcol = new TableColumn();
                tcol.Width = new GridLength(colWidth);
                table1.Columns.Add(tcol);

                //For debuging only
                // Set alternating background colors for the middle colums.
                //  if (x % 2 == 0)
                //      table1.Columns[x].Background = Brushes.Beige;
                //  else
                //    table1.Columns[x].Background = Brushes.LightSteelBlue;
            }

            int row = -1;
            int col = numberAcross + 1;

            // Create and add an empty TableRowGroup to hold the table's Rows.
            table1.RowGroups.Add(new TableRowGroup());


            foreach (WPFBarcode b in listBarcode)
            {
                // Add the first (title) row.
                if (col >= numberAcross)
                {
                    row++;
                    table1.RowGroups[0].Rows.Add(new TableRow());
                    col = 0;
                }

                // Alias the current working row for easy reference.
                TableRow currentRow = table1.RowGroups[0].Rows[row];


                // Add the header row with content,
                try
                {
                    Image img = b.Encode();

                    TableCell tableCell = new TableCell(new BlockUIContainer(img));
                    //TableCell tableCell = new TableCell(new BlockUIContainer(b.Generate_vector_image_canvas()));
                    currentRow.Cells.Add(tableCell);
                    //tableCell.BorderBrush = Brushes.Red;
                    //tableCell.BorderThickness = new Thickness(.5);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                    break;
                }



                col++;
            }

            PageDefinition pd = new PageDefinition();

            pd.FooterHeight = 0;
            pd.Margin       = new Size(sideMargin * 96, topMargin * 96);
            pd.HeaderHeight = 0;

            return(LabelPaginator.CreateXpsDocument(fd, pd));
        }