Пример #1
0
        private void DoThePrint()
        {
            FlowDocument copy = mathBox.CloneDocument();

            foreach (var mathBox in copy.FindChildren <MathBox>())
            {
                mathBox.BorderThickness = new Thickness(0);
            }
            // Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog,
            // and allowing the user to select a printer.

            // get information about the dimensions of the seleted printer+media.
            System.Printing.PrintDocumentImageableArea ia        = null;
            System.Windows.Xps.XpsDocumentWriter       docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);

            if (docWriter != null && ia != null)
            {
                DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator;

                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                Thickness t = new Thickness(72);  // copy.PagePadding;
                copy.PagePadding = new Thickness(
                    Math.Max(ia.OriginWidth, t.Left),
                    Math.Max(ia.OriginHeight, t.Top),
                    Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
                    Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));

                copy.ColumnWidth = double.PositiveInfinity;
                //copy.PageWidth = 528; // allow the page to be the natural with of the output device

                // Send content to the printer.
                docWriter.Write(paginator);
            }
        }
Пример #2
0
        private void DoThePrint(FlowDocument copy)
        {
            // Clone the source document's content into a new FlowDocument.
            // This is because the pagination for the printer needs to be
            // done differently than the pagination for the displayed page.
            // We print the copy, rather that the original FlowDocument.
            //System.IO.MemoryStream s = new System.IO.MemoryStream();
            //TextRange source = new TextRange(document.ContentStart, document.ContentEnd);
            //source.Save(s, DataFormats.Xaml);
            //FlowDocument copy = new FlowDocument();
            //TextRange dest = new TextRange(copy.ContentStart, copy.ContentEnd);
            //dest.Load(s, DataFormats.Xaml);

            // Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog,
            // and allowing the user to select a printer.

            var theme  = ThemeManager.GetAppTheme(Hub.Instance.Settings.Theme);
            var accent = ThemeManager.GetAccent("VSLight");

            ThemeManager.ChangeAppStyle(copy.Resources, accent, theme);

            // get information about the dimensions of the seleted printer+media.
            System.Printing.PrintDocumentImageableArea ia        = null;
            System.Windows.Xps.XpsDocumentWriter       docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);

            if (docWriter != null && ia != null)
            {
                DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator;

                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                Thickness t = new Thickness(72);                  // copy.PagePadding;
                copy.PagePadding = new Thickness(
                    Math.Max(ia.OriginWidth, t.Left),
                    Math.Max(ia.OriginHeight, t.Top),
                    Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
                    Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));

                copy.ColumnWidth = double.PositiveInfinity;
                //copy.PageWidth = 528; // allow the page to be the natural with of the output device

                // Send content to the printer.
                docWriter.Write(paginator);
            }
        }
        private void btnPrintRTB_Click(object sender, RoutedEventArgs e)
        {
            //Print RTB file
            try
            {
                FlowDocument document = rtbEditor.Document;

                //Make copy of FlowDocument for pritning - witch pictures
                string       copyString        = XamlWriter.Save(rtbEditor.Document);
                FlowDocument kopiaFlowDocument = XamlReader.Parse(copyString) as FlowDocument;
                MemoryStream memorySrteam      = new MemoryStream();                                                                //Przygotowanie się do przechowywania zawartości w pamięci

                System.Printing.PrintDocumentImageableArea ia        = null;
                System.Windows.Xps.XpsDocumentWriter       docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);  //tu następuje otwarcie okno dialogowego drukowania który zwraca prarametr - referencje: ia
                                                                                                                                    //parametr (ia) reprezentuje informacje o obszarze obrazowania i wymiarze nośnika.
                if (docWriter != null && ia != null)
                {
                    DocumentPaginator paginator = ((IDocumentPaginatorSource)kopiaFlowDocument).DocumentPaginator;                  ///Dzielenie zawartości na strony.
                    //Change size PageSize and PagePadding of document - for CanvasSize
                    paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);                                           //Ustawia rozmiar stron zgodnie z wymiarem fizycznym kartki papieru. (793/1122)
                    Thickness t = new Thickness(margines + kopiaFlowDocument.PagePadding.Left);                                     //Ustawiam marginesy wydruku w PagePadding. Należy zastosować korektę o starowy margines drukarki . Tu daje tyle co RichTextBox Domyślnie pobiera z drukarki i wynoszą (5,0,5,0) piksela
                    kopiaFlowDocument.PagePadding = new Thickness(                                                                  //Ustawienie nowego obszaru zadrukowania strony PagePadding
                        Math.Max(ia.OriginWidth, t.Left),
                        Math.Max(ia.OriginHeight, t.Top),
                        Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
                        Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));
                    kopiaFlowDocument.ColumnWidth = double.PositiveInfinity;                                                        //Ustawienie szerokości kolumny drukowanej. double.PositiveInfinity - reprezentuje nieskończoności dodatniej. To pole jest stałe.
                    // Send content to the printer.
                    docWriter.Write(paginator);
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                memorySrteam.Dispose();
            }

            catch (Exception ex)
            {
                ErrorMessage(ex);
            }
        }
        private void DoThePrint(FlowDocument document)
        {
            // Clone the source document's content into a new FlowDocument.
            // This is because the pagination for the printer needs to be
            // done differently than the pagination for the displayed page.
            // We print the copy, rather that the original FlowDocument.
            MemoryStream s      = new MemoryStream();
            TextRange    source = new TextRange(document.ContentStart, document.ContentEnd);

            source.Save(s, DataFormats.Xaml);

            FlowDocument doc = GetPrintFlowDocument();

            ForceRenderFlowDocument(doc);

            // get information about the dimensions of the seleted printer+media.
            System.Printing.PrintDocumentImageableArea ia        = null;
            System.Windows.Xps.XpsDocumentWriter       docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);

            if (docWriter != null && ia != null)
            {
                DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;

                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                Thickness t = new Thickness(72);  // copy.PagePadding;
                doc.PagePadding = new Thickness(
                    Math.Max(ia.OriginWidth, t.Left),
                    Math.Max(ia.OriginHeight, t.Top),
                    Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
                    Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));

                doc.ColumnWidth = double.PositiveInfinity;
                //copy.PageWidth = 528; // allow the page to be the natural with of the output device

                // Send content to the printer.
                docWriter.Write(paginator);
            }
        }
Пример #5
0
        private void Print()
        {
            // create header
            var cntlHeader = new TechDataHeaderControl();

            cntlHeader.SetContents(this.thePackage, this.theDefs, this.theDefaultLang, this.theSubmodel);

            // create footer
            var cntlFooter = new TechDataFooterControl();

            cntlFooter.SetContents(this.thePackage, this.theDefs, this.theDefaultLang, this.theSubmodel);

            // render this
            var bitmapHeader = RenderControl(cntlHeader, 600, 200, false);
            var bitmapFooter = RenderControl(cntlFooter, 600, 100, false);

            // create middle part
            var cntlProps = new TechDataPropertiesControl();

            cntlProps.SetContents(this.thePackage, this.theDefs, this.theDefaultLang, this.theSubmodel);
            var document = cntlProps.CreateFlowDocument(
                this.thePackage, this.theDefs, this.theDefaultLang, this.theSubmodel);

            // Clone the source document's content into a new FlowDocument.
            // This is because the pagination for the printer needs to be
            // done differently than the pagination for the displayed page.
            // We print the copy, rather that the original FlowDocument.
            System.IO.MemoryStream s = new System.IO.MemoryStream();
            TextRange source         = new TextRange(document.ContentStart, document.ContentEnd);

            source.Save(s, DataFormats.Xaml);
            FlowDocument copy = new FlowDocument();
            TextRange    dest = new TextRange(copy.ContentStart, copy.ContentEnd);

            dest.Load(s, DataFormats.Xaml);

            // Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog,
            // and allowing the user to select a printer.

            // get information about the dimensions of the seleted printer+media.
            System.Printing.PrintDocumentImageableArea ia        = null;
            System.Windows.Xps.XpsDocumentWriter       docWriter =
                System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);

            if (docWriter != null && ia != null)
            {
                // some more definitions
                var pdefs = new PimpedPaginator.Definition();
                pdefs.PageSize           = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                pdefs.HeaderHeight       = 200;
                pdefs.FooterHeight       = 100;
                pdefs.RepeatTableHeaders = true;

                // draw header
                pdefs.Header = (DrawingContext context, Rect bounds, int pageNr) =>
                {
                    context.DrawImage(bitmapHeader, bounds);
                };

                // draw footer
                pdefs.Footer = (DrawingContext context, Rect bounds, int pageNr) =>
                {
                    context.DrawImage(bitmapFooter, bounds);
                };

                // make suitable paginator
                var paginator = new PimpedPaginator(copy, pdefs);

                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                Thickness t = new Thickness(72);
                copy.PagePadding = new Thickness(
                    Math.Max(ia.OriginWidth, t.Left),
                    Math.Max(ia.OriginHeight, t.Top),
                    Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
                    Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));

                copy.ColumnWidth = double.PositiveInfinity;

                // Send content to the printer.
                docWriter.Write(paginator);
            }
        }