Example #1
1
        public override void DoPrint(FlowDocument document)
        {
            var ph = document.PageHeight;
            var pw = document.PageWidth;
            var pp = document.PagePadding;
            var cg = document.ColumnGap;
            var cw = document.ColumnWidth;

            var q = PrinterInfo.GetPrinter(Printer.ShareName);
            var pd = new PrintDialog { PrintQueue = q };
            if (pd.PrintQueue.FullName == Printer.ShareName || pd.ShowDialog().GetValueOrDefault(false))
            {
                document.PageHeight = pd.PrintableAreaHeight;
                document.PageWidth = pd.PrintableAreaWidth;
                document.PagePadding = new Thickness(25);
                document.ColumnGap = 0;
                document.ColumnWidth = (document.PageWidth -
                                       document.ColumnGap -
                                       document.PagePadding.Left -
                                       document.PagePadding.Right);
                pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
            }

            document.PageHeight = ph;
            document.PageWidth = pw;
            document.PagePadding = pp;
            document.ColumnGap = cg;
            document.ColumnWidth = cw;
        }
        //Imprimir

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Evento que se lanza al usar el menú Imprimir. </summary>
        ///
        /// <remarks>   Fidi, 11/16/2019. </remarks>
        ///
        /// <param name="sender">   Submenú Imprimir. </param>
        /// <param name="e">        Evento <b>Click</b> del menú Imprimir. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Print_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.PrintDialog prnt = new System.Windows.Controls.PrintDialog();
            if (prnt.ShowDialog() == true)
            {
                System.Windows.Size pageSize = new System.Windows.Size(prnt.PrintableAreaWidth, prnt.PrintableAreaHeight);
                canvasMain.Measure(pageSize);
                canvasMain.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));

                if (prnt.ShowDialog() == true)
                {
                    prnt.PrintVisual(canvasMain, "Printing Canvas");
                }
            }
        }
        public static void stampajUgovor()
        {
            PdfDocument pdf = PdfGenerator.GeneratePdf(
                @"<html>
                            <body style=""text-align:center;background-color:red"">
                                <p>
                                    <a href=""www.google.rs"">Hello World</a>
                                    This is html rendered text
                                </p>
                            </body>
                      </html>", PageSize.A4);

            pdf.Save("document.pdf");
            PrintDialog pDialog = new PrintDialog();

            pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;

            // Display the dialog. This returns true if the user presses the Print button.
            bool?print = pDialog.ShowDialog();

            Aspose.Pdf.Document.Convert("document.pdf", null, "hello.xps", new XpsSaveOptions());
            if (print == true)
            {
                XpsDocument           xpsDocument = new XpsDocument("hello.xps", FileAccess.ReadWrite);
                FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
            }
        }
        /// <summary>
        /// Prints this instance.
        /// </summary>
        public bool Print()
        {
            try
            {
                PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
                bool? results = printDlg.ShowDialog();
                if (results == null || results == false) return false;

                //get selected printer capabilities
                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                //get the size of the printer page
                System.Windows.Size printSize = new System.Windows.Size(
                    capabilities.PageImageableArea.ExtentHeight, capabilities.PageImageableArea.ExtentWidth);

                // Build print view
                this.Height = printSize.Height;
                this.Width = printSize.Width;
                Measure(printSize);
                Arrange(new System.Windows.Rect(printSize));
                XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue);
                printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

                xpsdw.WriteAsync(this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().Message, "Printing Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
            return true;
        }
        private void cmdPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            if (pd.ShowDialog().GetValueOrDefault())
            {
                PrintTicket ticket = pd.PrintTicket;

                if (cmboOrientation.SelectedIndex == 0)
                {
                    ticket.PageOrientation = PageOrientation.Landscape;
                }
                else
                {
                    ticket.PageOrientation = PageOrientation.Portrait;
                }
                pd.PrintTicket = ticket;


                mDoc.PageHeight = pd.PrintableAreaHeight;
                mDoc.PageWidth = pd.PrintableAreaWidth;
                mDoc.PagePadding = new Thickness(50);
                mDoc.ColumnGap = 0;
                mDoc.ColumnWidth = pd.PrintableAreaWidth;

                IDocumentPaginatorSource dps = mDoc;
                pd.PrintDocument(dps.DocumentPaginator, title);
            }
        }
        /// <summary>
        /// Prints this instance.
        /// </summary>
        public bool Print()
        {
            try
            {
                PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
                bool?       results  = printDlg.ShowDialog();
                if (results == null || results == false)
                {
                    return(false);
                }

                //get selected printer capabilities
                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                //get the size of the printer page
                System.Windows.Size printSize = new System.Windows.Size(
                    capabilities.PageImageableArea.ExtentHeight, capabilities.PageImageableArea.ExtentWidth);

                // Build print view
                this.Height = printSize.Height;
                this.Width  = printSize.Width;
                Measure(printSize);
                Arrange(new System.Windows.Rect(printSize));
                XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue);
                printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

                xpsdw.WriteAsync(this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().Message, "Printing Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            return(true);
        }
Example #7
0
        private void Печать_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
            dlg.PageRangeSelection   = PageRangeSelection.AllPages;
            dlg.UserPageRangeEnabled = true;

            Nullable <bool> result = dlg.ShowDialog();


            if (result == true)
            {
                // Create the print dialog object and set options
                PrintDialog pDialog = new PrintDialog();
                pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
                pDialog.UserPageRangeEnabled = true;

                // Display the dialog. This returns true if the user presses the Print button.
                //Nullable<Boolean> print = pDialog.ShowDialog();
                //if (print == true)
                //{
                //    XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
                //    FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                //    pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
                //}
            }
        }
Example #8
0
        public void PrintSnapshot()
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                //get selected printer capabilities
                PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                //Capture the image
                RenderTargetBitmap bmp = new RenderTargetBitmap((int)mainGrid.ActualWidth, (int)mainGrid.ActualHeight, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(this);

                //Place on a panel
                StackPanel myPanel = new StackPanel();
                myPanel.Margin = new Thickness(25);
                Image myImage = new Image();
                myImage.Stretch = Stretch.Uniform;
                myImage.Source  = bmp;
                myPanel.Children.Add(myImage);
                //TextBlock myBlock = new TextBlock();
                //myBlock.Text = "A Great Image.";
                //myBlock.TextAlignment = TextAlignment.Center;
                //myPanel.Children.Add(myBlock);

                myPanel.Measure(new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight));
                myPanel.Arrange(new Rect(new Point(0, 0), myPanel.DesiredSize));

                printDlg.PrintVisual(myPanel, "Map capture");
            }
        }
        public MoSo_PrintPreview_ViewModel(string MaSo, string TenKH, string Tien, string LTK, string CMND, string DiaChi)
        {
            NguoiTaoPhieu      = LoginViewModel.TaiKhoanSuDung.HoTen;
            this.MaSo          = MaSo;
            this.TenKH         = TenKH;
            SoTienGui          = Tien;
            NgayMoSo           = DateTime.Now.ToString("dd/MM/yyyy");
            LoaiTietKiem       = LTK;
            this.CMND          = CMND;
            this.DiaChi        = DiaChi;
            CloseWindowCommand = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) => {
                var ex = p as Window;
                ex.Close();
            });

            Print_Command = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) =>
            {
                var ex = p as Window;
                try
                {
                    System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(ex, "Print report");
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Cannot print");
                }
            });
        }
        private void PrintPreview_Click(object sender, RoutedEventArgs e)
        {
            var printdialog = new PrintDialog();
            if (printdialog.ShowDialog() != true) { return; }
            var doc = new FixedDocument();
            doc.DocumentPaginator.PageSize = new Size(printdialog.PrintableAreaWidth, printdialog.PrintableAreaHeight);
            var queue = printdialog.PrintQueue;
            var caps = queue.GetPrintCapabilities();
            var area = caps.PageImageableArea;
            var marginwidth = (printdialog.PrintableAreaWidth - caps.PageImageableArea.ExtentWidth) / 2.0;
            var marginheight = (printdialog.PrintableAreaHeight - caps.PageImageableArea.ExtentHeight) / 2.0;

            double gutter;
            if (!Double.TryParse(GutterWidthTextbox.Text, out gutter)) { gutter = 0.25; }
            // Translate inches to device independent pixels
            gutter *= 96.0;

            var opts = new PrintOptions
            {
                PrintableWidth = area.ExtentWidth,
                PrintableHeight = area.ExtentHeight,
                MarginWidth = marginwidth,
                MarginHeight = marginheight,
                Gutter = gutter
            };

            var category = (CardCategory)DataContext;
            category.AddPagesToDocument(doc, opts, category.SelectedCards);

            var preview = new PrintPreview();
            preview.Document = doc;
            preview.ShowDialog();
        }
Example #11
0
        private void PrintElement(Visual visual)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                //get selected printer capabilities
                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                //get the size of the printer page
                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

                VisualBrush b = new VisualBrush(visual)
                {
                    Stretch    = Stretch.Uniform,
                    AlignmentX = AlignmentX.Center,
                    AlignmentY = AlignmentY.Center,
                };

                Canvas c = new Canvas
                {
                    Height     = sz.Height,
                    Width      = sz.Width,
                    Background = b,
                };

                var skinDescription = (SkinDescription)Application.Current.Properties["CurrentSkinDescription"];

                var license = skinDescription.License;
                if (!string.IsNullOrEmpty(license))
                {
                    license = "License: " + license;
                }

                var notice = string.Format("{0}\n{1}", skinDescription.CopyrightNotice, license).Trim();

                if (!string.IsNullOrWhiteSpace(notice))
                {
                    var t = new TextBlock
                    {
                        Text                = notice,
                        FontSize            = 8,
                        Margin              = new Thickness(5),
                        HorizontalAlignment = HorizontalAlignment.Right,
                        VerticalAlignment   = VerticalAlignment.Bottom,
                        TextAlignment       = TextAlignment.Right,
                    };

                    Canvas.SetRight(t, 0);
                    Canvas.SetBottom(t, 0);

                    c.Children.Add(t);
                }

                c.Measure(sz);
                c.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                printDlg.PrintVisual(c, "Settlers Board Designer");
            }
        }
Example #12
0
        /// <summary>
        /// Print the current window ass best fit for a page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PrintScreen_Button_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

            if (printDlg.ShowDialog() == true)
            {
                //get selected printer capabilities
                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                //get scale of the print wrt to screen of WPF visual
                double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                                        this.ActualHeight);

                //Transform the Visual to scale
                this.LayoutTransform = new ScaleTransform(scale, scale);

                //get the size of the printer page
                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

                //update the layout of the visual to the printer page size.
                this.Measure(sz);
                this.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                //now print the visual to printer to fit on the one page.
                printDlg.PrintVisual(this, "Wpf controller");
            }
        }
        private void btnPrint_Click_1(object sender, RoutedEventArgs e)
        {
            var printControl = new SummaryControl();
            printControl.DataContext = _reservation;
            printControl.Width = 8.27 * 96;
            printControl.Height = 11.69 * 96;

            //Create a fixed Document and Print the document
            FixedDocument fixedDoc = new FixedDocument();
            PageContent pageContent = new PageContent();
            FixedPage fixedPage = new FixedPage();
            fixedPage.Height = 11.69 * 96;
            fixedPage.Width = 8.27 * 96;

            fixedPage.Children.Add(printControl);
            ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
            fixedDoc.Pages.Add(pageContent);

            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                //dialog.PrintVisual(_PrintCanvas, "My Canvas");
                dialog.PrintDocument(fixedDoc.DocumentPaginator, "Print label");
            }
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            //Show a Print Dialog
            PrintDialog dialog = new PrintDialog();
            dialog.MaxPage = this.pdfViewer1.PageCount > 0 ? (uint)this.pdfViewer1.PageCount : 1;
            dialog.MinPage = 1;
            dialog.UserPageRangeEnabled = true;

            bool? result = dialog.ShowDialog();

            if (result.Value)
            {
                try
                {
                    //Set print parnameters.
                    this.pdfViewer1.PrintDialog = dialog;
                    //Get the PrintDocument.
                    dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

        }
Example #15
0
        public override void DoPrint(FlowDocument document)
        {
            var ph = document.PageHeight;
            var pw = document.PageWidth;
            var pp = document.PagePadding;
            var cg = document.ColumnGap;
            var cw = document.ColumnWidth;

            var q = PrinterInfo.GetPrinter(Printer.ShareName);
            var pd = new PrintDialog { PrintQueue = q };
            if (pd.PrintQueue.FullName == Printer.ShareName || pd.ShowDialog().GetValueOrDefault(false))
            {
                document.FontFamily = new System.Windows.Media.FontFamily(LocalSettings.PrintFontFamily);
                document.Typography.EastAsianWidths = FontEastAsianWidths.Half;
                document.PageHeight = pd.PrintableAreaHeight;
                document.PageWidth = pd.PrintableAreaWidth;
                document.PagePadding = new Thickness(25);
                document.ColumnGap = 0;
                document.ColumnWidth = (document.PageWidth -
                                       document.ColumnGap -
                                       document.PagePadding.Left -
                                       document.PagePadding.Right);
                pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
            }

            document.PageHeight = ph;
            document.PageWidth = pw;
            document.PagePadding = pp;
            document.ColumnGap = cg;
            document.ColumnWidth = cw;
        }
Example #16
0
        protected override void OnPrintCommand()
        {
            PrintDialog printDialog = new PrintDialog();
            printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
            printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;

            printDialog.PrintTicket.PageOrientation = PageOrientation;

            if (printDialog.ShowDialog() == true)
            {
                // Code assumes this.Document will either by a FixedDocument or a FixedDocumentSequence
                FixedDocument fixedDocument = this.Document as FixedDocument;
                FixedDocumentSequence fixedDocumentSequence = this.Document as FixedDocumentSequence;

                if (fixedDocument != null)
                    fixedDocument.PrintTicket = printDialog.PrintTicket;

                if (fixedDocumentSequence != null)
                    fixedDocumentSequence.PrintTicket = printDialog.PrintTicket;

                XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);

                if (fixedDocument != null)
                    writer.WriteAsync(fixedDocument, printDialog.PrintTicket);

                if (fixedDocumentSequence != null)
                    writer.WriteAsync(fixedDocumentSequence, printDialog.PrintTicket);
            }
        }
Example #17
0
        public Task PrintCanvasAsync(Canvas canvas, CancellationToken token = default(CancellationToken))
        {
            System.Windows.Controls.PrintDialog     printDialog      = new System.Windows.Controls.PrintDialog();
            System.Drawing.Printing.PrinterSettings printer          = new System.Drawing.Printing.PrinterSettings();
            System.Printing.LocalPrintServer        localPrintServer = new System.Printing.LocalPrintServer();

            System.Printing.PrintTicket pt = new System.Printing.PrintTicket();
            System.Printing.PrintQueue  pq = new System.Printing.PrintQueue(localPrintServer, printer.PrinterName, System.Printing.PrintSystemDesiredAccess.UsePrinter);

            System.Printing.PageMediaSize PMS      = new System.Printing.PageMediaSize(canvas.ActualWidth + 20, canvas.ActualHeight + 20);
            System.Windows.Size           pageSize = new System.Windows.Size(canvas.ActualWidth + 20, canvas.ActualHeight + 20);
            canvas.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
            canvas.Measure(pageSize);

            pt.PageMediaSize = PMS;
            pt.PageMediaType = System.Printing.PageMediaType.Unknown;

            pq.DefaultPrintTicket.PageMediaSize = PMS;
            pq.DefaultPrintTicket.PageMediaType = System.Printing.PageMediaType.Unknown;

            printDialog.PrintQueue  = pq;
            printDialog.PrintTicket = pt;
            //printDialog.PrintQueue.Commit();

            if (printDialog.ShowDialog() == true)
            {
                printDialog.PrintVisual(canvas, "Состояние холста");
            }
            return(Task.FromResult(0)); //Task.CompletedTask;
        }
Example #18
0
        /// <summary>
        /// Invokes a System.Windows.Controls.PrintDialog to print the TextEditor.Document with specified title.
        /// </summary>
        public static void PrintDialog(this TextEditor textEditor, string title, bool withHighlighting)
        {
            PrintSettings settings = textEditor.Tag as PrintSettings;

            if (settings == null)
            {
                settings       = new PrintSettings();
                textEditor.Tag = settings;
            }

            settings.DocumentTitle = (title != null) ? title : String.Empty;
            System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
            printDialog.PrintQueue = settings.PrintQueue;

            if (settings.PageSettings.Landscape)
            {
                settings.PrintTicket.PageOrientation = PageOrientation.Landscape;
            }

            printDialog.PrintTicket = settings.PrintTicket;
            printDialog.PrintQueue.DefaultPrintTicket.PageOrientation = settings.PrintTicket.PageOrientation;
            if (printDialog.ShowDialog() == true)
            {
                settings.PrintQueue  = printDialog.PrintQueue;
                settings.PrintTicket = printDialog.PrintTicket;
                printDialog.PrintDocument(CreateDocumentPaginatorToPrint(textEditor, withHighlighting), "PrintJob");
            }
        }
        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();

            if (dlg.ShowDialog().GetValueOrDefault())
            {
                // Make sure orientation is Portrait.
                PrintTicket prntkt = dlg.PrintTicket;
                prntkt.PageOrientation = PageOrientation.Portrait;
                dlg.PrintTicket = prntkt;

                // Create new BannerDocumentPaginator object.
                BannerDocumentPaginator paginator = new BannerDocumentPaginator();

                // Set Text property from TextBox.
                paginator.Text = txtbox.Text;

                // Give it a PageSize property based on the paper dimensions.
                paginator.PageSize = new Size(dlg.PrintableAreaWidth,
                                              dlg.PrintableAreaHeight);

                // Call PrintDocument to print the document.
                dlg.PrintDocument(paginator, "Banner: " + txtbox.Text);
            }
        }
Example #20
0
        /// <summary>
        /// Invokes a System.Windows.Controls.PrintDialog to print the TextEditor.Document with specified title.
        /// </summary>
        public static void PrintDialog(this TextEditor textEditor, string title)
        {
            Printing.mDocumentTitle = title;

              Printing.InitPageSettings();

              System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();

              printDialog.PrintQueue = mPrintQueue;

              if (mPageSettings.Landscape)
            Printing.mPrintTicket.PageOrientation = PageOrientation.Landscape;

              printDialog.PrintTicket = mPrintTicket;
              printDialog.PrintQueue.DefaultPrintTicket.PageOrientation = mPrintTicket.PageOrientation;

              if (printDialog.ShowDialog() == true)
              {
            Printing.mPrintQueue = printDialog.PrintQueue;

            Printing.mPrintTicket = printDialog.PrintTicket;

            printDialog.PrintDocument(CreateDocumentPaginatorToPrint(textEditor), "PrintJob");
              }
        }
        protected override void OnPrintCommand()
        {
            // get a print dialog, defaulted to default printer and default printer's preferences.
            var printDialog = new PrintDialog();
            printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
            printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;

            string s = Document.GetType().ToString();

            // get a reference to the FixedDocumentSequence for the viewer.
            //FixedDocumentSequence docSeq = this.Document as FixedDocumentSequence;
            var docSeq = (FixedDocument) Document;

            // set the default page orientation based on the desired output.
            printDialog.PrintTicket = (PrintTicket) docSeq.PrintTicket;

            if (printDialog.ShowDialog() == true)
            {
                // set the print ticket for the document sequence and write it to the printer.
                docSeq.PrintTicket = printDialog.PrintTicket;

                var writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
                writer.WriteAsync(docSeq, printDialog.PrintTicket);
            }
        }
Example #22
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            //REFACTOR ME
            dtgParentReport.Update();
            System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
            Nullable <bool> print = printDialog.ShowDialog();

            if (print == true)
            {
                try
                {
                    XpsDocument           xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
                    FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                    printDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
                }
                catch (UnauthorizedAccessException e1)
                {
                    const string message =
                        "Unauthoried to access that printer.";
                    const string caption = "Unauthoried Access";
                    var          result  = MessageBox.Show(message, caption,
                                                           MessageBoxButtons.OK,
                                                           MessageBoxIcon.Error);
                }
                catch (PrintDialogException e2)
                {
                    const string message =
                        "Unknow error occurred.";
                    const string caption = "Error Printing";
                    var          result  = MessageBox.Show(message, caption,
                                                           MessageBoxButtons.OK,
                                                           MessageBoxIcon.Error);
                }
            }
        }
        private bool modifyPrinter(ListBoxPrinter printer)
        {
            if (printer == null)
            {
                return(false);
            }

            // Initialize PrintDialog to use printer's Queue and Ticket
            System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
            pd.PrintQueue = printer.Printer.Queue;
            // pd.PrintTicket = printer.Ticket;
            pd.UserPageRangeEnabled = false;

            if (pd.ShowDialog() == false)
            {
                return(false);
            }

            // TODO FIXME This doesn't check that the printer is actually the same printer! It could be an invalid ticket!
            printer.Printer.Ticket = pd.PrintTicket;

            /*
             * printer.Dialog.UserPageRangeEnabled = false;
             *
             * // Show the dialog; if the user clicks Cancel, return.
             * if (printer.Dialog.ShowDialog() == false) return false;
             *
             * var pc = printer.Dialog.PrintQueue.GetPrintCapabilities();
             * // Save the ticket only if the user hits Print
             * printer.Ticket = printer.Dialog.PrintTicket;
             */
            return(true);
        }
 private void btnPrint_Click(object sender, EventArgs e)
 {
     //REFACTOR ME
     dtgParentReport.Update();
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     Nullable<bool> print = printDialog.ShowDialog();
     if (print == true)
     {
         try
         {
             XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
             FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
             printDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
         }
         catch (UnauthorizedAccessException e1)
         {
             const string message =
                 "Unauthoried to access that printer.";
             const string caption = "Unauthoried Access";
             var result = MessageBox.Show(message, caption,
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
         }
         catch (PrintDialogException e2)
         {
             const string message =
                 "Unknow error occurred.";
             const string caption = "Error Printing";
             var result = MessageBox.Show(message, caption,
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
         }
     }
 }
Example #25
0
        public BaoCaoDoanhSo_PrintPreview_ViewModel(ObservableCollection <BaoCaoDS> listBaoCao, DateTime ngayBaoCao)
        {
            ListBaoCaoDoanhSo = listBaoCao;
            //for (int i = 0; i < listBaoCao.Count(); i++)
            //    ListBaoCaoDoanhSo[i].SoThuTu = i + 1;

            NgayBaoCao    = ngayBaoCao;
            NguoiTaoPhieu = LoginViewModel.TaiKhoanSuDung.HoTen;

            CloseWindowCommand = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) => {
                var ex = p as Window;
                ex.Close();
            });

            Print_Command = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) =>
            {
                var ex = p as Window;
                try
                {
                    System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(ex, "Print report");
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Cannot print");
                }
            });
        }
Example #26
0
        public static void PrintText(System.Windows.Controls.RichTextBox TxtBox)
        {
            string Text = new TextRange(TxtBox.Document.ContentStart, TxtBox.Document.ContentEnd).Text;

            System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                // Создать текст
                Run run = new Run(Text);

                // Поместить его в TextBlock
                TextBlock visual = new TextBlock();
                visual.Inlines.Add(run);

                // Использовать поля для получения рамки страницы
                visual.Margin = new Thickness(5);

                // Разрешить перенос для заполнения всей ширины страницы
                visual.TextWrapping = TextWrapping.Wrap;

                // Увеличить TextBlock по обоим измерениям в 5 раз.
                // (В этом случае увеличение шрифта дало бы тот же эффект,
                // потому что TextBlock — единственный элемент)
                visual.LayoutTransform = new ScaleTransform(5, 5);

                // Установить размер элемента
                System.Windows.Size pageSize = new System.Windows.Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
                visual.Measure(pageSize);
                visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));

                // Напечатать элемент
                printDialog.PrintVisual(visual, "Распечатываем текст");
            }
        }
Example #27
0
        public static void Print(FlowDocument printedPage)
        {
            PrintDialog dialog = new PrintDialog();

            dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
            dialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
            dialog.PrintTicket.OutputQuality = OutputQuality.High;
            dialog.PrintTicket.PageBorderless = PageBorderless.None;
            dialog.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);

            if (dialog.ShowDialog() == true)
            {
                double pageHeight = printedPage.PageHeight;
                double pageWidth = printedPage.PageWidth;
                Thickness pagePadding = printedPage.PagePadding;
                double columnGap = printedPage.ColumnGap;
                double columnWidth = printedPage.ColumnWidth;

                printedPage.PageHeight = dialog.PrintableAreaHeight;
                printedPage.PageWidth = dialog.PrintableAreaWidth;
                printedPage.PagePadding = new Thickness(50);

                dialog.PrintDocument(((IDocumentPaginatorSource)printedPage).DocumentPaginator, "");

                printedPage.PagePadding = pagePadding;
                printedPage.PageHeight = pageHeight;
                printedPage.PageWidth = pageWidth;
                printedPage.ColumnWidth = columnWidth;
                printedPage.ColumnGap = columnGap;

            }
        }
Example #28
0
        private void printButton_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                double zoom;

                double markerWidthInCm = markerBackground.ActualWidth * 0.026458333;

                zoom = markerWidthSlider.Value / markerWidthInCm;

                //markerCanvas.Background = Brushes.LightGray;

                markerCanvas.LayoutTransform = new ScaleTransform(zoom, zoom);

                Size pageSize = new Size(printDlg.PrintableAreaWidth - 20, printDlg.PrintableAreaHeight - 20);

                markerCanvas.Measure(pageSize);

                markerCanvas.Arrange(new Rect(10, 10, pageSize.Width, pageSize.Height));

                printDlg.PrintVisual(markerCanvas, "Marker");

                markerCanvas.Background      = null;
                markerCanvas.LayoutTransform = null;
            }
        }
Example #29
0
        private void InvokePrint(object sender, RoutedEventArgs e)
        {
            TitleGrid.Margin  = new Thickness(60, 40, 60, 0);
            FirstPage.Margin  = new Thickness(60, 0, 60, 0);
            SecondPage.Margin = new Thickness(60, 0, 60, 0);

            PrintDialog printDialog = new System.Windows.Controls.PrintDialog();

            if (printDialog.ShowDialog() == true)
            {
                PrintButton.Visibility    = Visibility.Collapsed;
                IntroPanel.Visibility     = Visibility.Collapsed;
                CopyrightPanel.Visibility = Visibility.Visible;

                PrintPanel(MainStackPanel, "3D Objects cheat sheet", printDialog, 0.75); // customScale = 0.75 - this should fit the document to 2 pages

                CopyrightPanel.Visibility = Visibility.Collapsed;
                IntroPanel.Visibility     = Visibility.Visible;
                PrintButton.Visibility    = Visibility.Visible;
            }

            TitleGrid.Margin  = new Thickness(20, 0, 20, 0);
            FirstPage.Margin  = new Thickness(20, 0, 20, 0);
            SecondPage.Margin = new Thickness(20, 0, 20, 0);
        }
Example #30
0
        /// <summary>
        /// Invokes a System.Windows.Controls.PrintDialog to print the TextEditor.Document with specified title.
        /// </summary>
        public static void PrintDialog(this TextEditor textEditor, string title)
        {
            Printing.mDocumentTitle = title;

            Printing.InitPageSettings();

            System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();

            printDialog.PrintQueue = mPrintQueue;

            if (mPageSettings.Landscape)
            {
                Printing.mPrintTicket.PageOrientation = PageOrientation.Landscape;
            }

            printDialog.PrintTicket = mPrintTicket;
            printDialog.PrintQueue.DefaultPrintTicket.PageOrientation = mPrintTicket.PageOrientation;

            if (printDialog.ShowDialog() == true)
            {
                Printing.mPrintQueue = printDialog.PrintQueue;

                Printing.mPrintTicket = printDialog.PrintTicket;

                printDialog.PrintDocument(CreateDocumentPaginatorToPrint(textEditor), "PrintJob");
            }
        }
        public PhieuRut_PrintPreview_ViewModel(string MaPR, string TenKH, string Ngay, string Tien)
        {
            MaPhieuRut         = MaPR;
            TenKhachhang       = TenKH;
            NgayRut            = Ngay;
            NguoiTaoPhieu      = LoginViewModel.TaiKhoanSuDung.HoTen;
            SoTienRut          = Tien;
            NgayTaoPhieu       = DateTime.Now.ToString("dd/MM/yyyy");
            CloseWindowCommand = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) => {
                var ex = p as Window;
                ex.Close();
            });

            Print_Command = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) =>
            {
                var ex = p as Window;
                try
                {
                    System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(ex, "Print report");
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Cannot print");
                }
            });
        }
Example #32
0
        public override void DoPrint(FlowDocument document)
        {
            var ph = document.PageHeight;
            var pw = document.PageWidth;
            var pp = document.PagePadding;
            var cg = document.ColumnGap;
            var cw = document.ColumnWidth;
            var fm = document.FontFamily;
            var bg = document.Background;

            var q = PrinterInfo.GetPrinter(Printer.ShareName);
            var pd = new PrintDialog { PrintQueue = q };
            if (q != null || pd.PrintQueue.FullName == Printer.ShareName || Printer.ShareName.ToLower() == "default" || Printer.ShareName.Contains("/") || pd.ShowDialog().GetValueOrDefault(false))
            {
                document.Background = Brushes.Transparent;
                document.FontFamily = new FontFamily(LocalSettings.PrintFontFamily);
                document.PageHeight = pd.PrintableAreaHeight;
                document.PageWidth = pd.PrintableAreaWidth;
                document.PagePadding = new Thickness(25);
                document.ColumnGap = 0;
                document.ColumnWidth = (document.PageWidth -
                                       document.ColumnGap -
                                       document.PagePadding.Left -
                                       document.PagePadding.Right);
                pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
            }

            document.Background = bg;
            document.FontFamily = fm;
            document.PageHeight = ph;
            document.PageWidth = pw;
            document.PagePadding = pp;
            document.ColumnGap = cg;
            document.ColumnWidth = cw;
        }
Example #33
0
        public static void Print(FrameworkElement obj)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                Transform transform = obj.LayoutTransform;

                // get selected printer capabilities
                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

                // get scale of the print wrt to screen of WPF visual
                double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / obj.ActualWidth, capabilities.PageImageableArea.ExtentHeight / obj.ActualHeight);

                // Transform the Visual to scale
                obj.LayoutTransform = new ScaleTransform(scale, scale);

                // get the size of the printer page
                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

                // update the layout of the visual to the printer page size.
                obj.Measure(sz);
                obj.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                // now print the visual to printer to fit on the one page.
                printDlg.PrintVisual(obj, "UnisensViewer");

                obj.LayoutTransform = transform;
            }
        }
        public BaoCaoMoDong_PrintPreview_ViewModel(string MaBC, string Thang, string Nam, string LTK, ObservableCollection <ListBaoCaoDongMo> list)
        {
            ListBaoCaoDMPP     = list;
            NamBaoCao          = Nam;
            MaBaoCao           = MaBC;
            ThangBaoCao        = Thang;
            LoaiTietKiem       = LTK;
            NgayLapBaoCao      = DateTime.Now.ToString("dd/MM/yyyy");
            NguoiTaoPhieu      = LoginViewModel.TaiKhoanSuDung.HoTen;
            CloseWindowCommand = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) => {
                var ex = p as Window;
                ex.Close();
            });

            Print_Command = new RelayCommand <object>((p) => { return(p == null ? false : true); }, (p) =>
            {
                var ex = p as Window;
                try
                {
                    System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(ex, "Print report");
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Cannot print");
                }
            });
        }
Example #35
0
        private void Print()
        {
            if (m_streams == null || m_streams.Count == 0)
            {
                return;
            }
            var ptdlg = new System.Windows.Controls.PrintDialog();

            if (ptdlg.ShowDialog() == true)
            {
                //const string printerName = "Microsoft Office Document Image Writer";
                string printerName = ptdlg.PrintQueue.FullName;

                PrintDocument printDoc = new PrintDocument();
                printDoc.PrinterSettings.PrinterName = printerName;
                if (!printDoc.PrinterSettings.IsValid)
                {
                    string msg = String.Format(
                        "Can't find printer \"{0}\".", printerName);
                    throw new InvalidOperationException(msg);
                }
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                printDoc.Print();
            }
        }
        private void cmdPrintCustom_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                FlowDocument doc = docReader.Document;
                
                // Save all the existing settings.                                
                double pageHeight = doc.PageHeight;
                double pageWidth = doc.PageWidth;
                Thickness pagePadding = doc.PagePadding;
                double columnGap = doc.ColumnGap;
                double columnWidth = doc.ColumnWidth;

                // Make the FlowDocument page match the printed page.
                doc.PageHeight = printDialog.PrintableAreaHeight;
                doc.PageWidth = printDialog.PrintableAreaWidth;
                doc.PagePadding = new Thickness(50);

                // Use two columns.
                doc.ColumnGap = 25;
                doc.ColumnWidth = (doc.PageWidth - doc.ColumnGap
                    - doc.PagePadding.Left - doc.PagePadding.Right) / 2;

                printDialog.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "A Flow Document");
                
                // Reapply the old settings.
                doc.PageHeight = pageHeight;
                doc.PageWidth = pageWidth;
                doc.PagePadding = pagePadding;
                doc.ColumnGap = columnGap;
                doc.ColumnWidth = columnWidth;
            }
        }
Example #37
0
 private void Print_Click(object sender, RoutedEventArgs e)
 {
     //If you reduce the size of the view area of the window, so the text does not all fit into one page, it will print separate pages
     PrintDialog printDialog = new PrintDialog();
     if (printDialog.ShowDialog() == true)
         printDialog.PrintDocument(((IDocumentPaginatorSource)flowDocument).DocumentPaginator, "This is a Flow Document");
 }
Example #38
0
        private void btnolustur_Click(object sender, RoutedEventArgs e)
        {
            cv         cvpage = new cv();
            raporlarBO bo     = new raporlarBO();
            raporlar   r      = new raporlar();

            r = bo.getir(Convert.ToInt32(txbsicilno.Text));
            cvpage.lblAd.Text = (r.adSoyad);

            cvpage.txtckimlk.Text  = (r.tcKimlikNo);
            cvpage.txdogumyer.Text = Convert.ToString(r.dogumYeri);
            cvpage.txdogumtar.Text = (r.dogumTarihi).ToShortDateString();
            cvpage.txasker.Text    = (r.askerlikDurumu);
            cvpage.txkan.Text      = Convert.ToString(r.kanGrubu);
            cvpage.txbolum.Text    = (r.Lokasyon);
            cvpage.txbirim.Text    = (r.Birim);
            cvpage.txisbasi.Text   = (r.kurumaBaslamaTarihi).ToShortDateString();
            //cvpage.txhizmetyil.Text
            cvpage.txegitim.Text  = (r.egitimDurumu);
            cvpage.txokul.Text    = (r.okulAdi);
            cvpage.txokbolum.Text = (r.Bolumu);
            cvpage.txbitirme.Text = (r.bitirdigiTarih).ToShortDateString();
            cvpage.istel.Text     = Convert.ToString(r.isTel);
            cvpage.adres.Text     = (r.adres);
            cvpage.ceptel.Text    = (r.cepTel);

            DateTime sontarih = DateTime.Now;
            DateTime ilktarih = r.kurumaBaslamaTarihi;

            ikitarihfark a = new ikitarihfark();

            int[] sonuc = (a.ikiTarihFarki(sontarih, ilktarih));
            cvpage.txhizmetyil.Text = sonuc[0] + " YIL " + sonuc[1] + " Ay " + sonuc[2] + " Gün";

            int uzunluk = (r.Unvan).Length;

            if (uzunluk > 10)
            {
                cvpage.lblUnvan.FontSize = 18;
            }


            cvpage.lblUnvan.Text = r.Unvan;


            try
            {
                cvpage.IsEnabled = false;
                System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
                if (pd.ShowDialog() == true)
                {
                    pd.PrintVisual(cvpage, "aaaa");
                }
            }
            finally
            {
                cvpage.IsEnabled = true;
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            if (pd.ShowDialog() == true) //Результат может быть равен true, false, или null
            {

            }
        }
 private void cmdPrint_Click(object sender, RoutedEventArgs e)
 {
     PrintDialog printDialog = new PrintDialog();
     if (printDialog.ShowDialog() == true)
     {                
         printDialog.PrintDocument(((IDocumentPaginatorSource)docReader.Document).DocumentPaginator, "A Flow Document");
     }
 }
Example #41
0
 private void menuPrint_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(canvas, "My First Print Job");
     }
 }
 private void PrintJ(object sender, RoutedEventArgs e)
 {
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(JournalDataGrid, "Распечатка журнала");
     }
 }
Example #43
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(canvas, "Распечатываем элемент Canvas");
     }
 }
Example #44
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                gateCanvas.Print(printDlg);
            }
        }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                printDlg.PrintVisual(this, "First WPF Print");
            }
        }
Example #46
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                printDlg.PrintVisual(gridPrintable, Event.Name + " Announcers Sheet");
            }
        }
Example #47
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() == true)
            {
                lb_DialogResult.Items.Add("打印已选择");
            }
        }
 public void Print()
 {
     PrintDialog printDialog = new PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         var document = CreateDocument(new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight));
         printDialog.PrintDocument(document.DocumentPaginator, "MyPrintJobName");
     }
 }
 private void printButton_Click(object sender, RoutedEventArgs e)
 {
     Logger("test");
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     if (printDialog.ShowDialog() == true)
     {
         printDialog.PrintVisual(dataGrid, "moi file");
     }
 }
Example #50
-1
        private void PrintPageDialog(Messages.PrintPage printMessage)
        {
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

                //get scale of the print wrt to screen of WPF visual
                double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /  this.ActualHeight);

                //Transform the Visual to scale
                this.LayoutTransform = new ScaleTransform(scale, scale);

                //get the size of the printer page
                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

                //update the layout of the visual to the printer page size.
                printMessage.Element.Measure(sz);
                printMessage.Element.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                //now print the visual to printer to fit on the one page.
                printDialog.PrintVisual(printMessage.Element, printMessage.Description);
            }
            
        }
        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
               //     Create DrawingVisual and open DrawingContext.
                DrawingVisual vis = new DrawingVisual();
                DrawingContext dc = vis.RenderOpen();

                // Draw ellipse.
                dc.DrawEllipse(Brushes.LightGray, new Pen(Brushes.Black, 3),
                               new Point(dlg.PrintableAreaWidth / 2,
                                         dlg.PrintableAreaHeight / 2),
                               dlg.PrintableAreaWidth / 2,
                               dlg.PrintableAreaHeight / 2);

                // Close DrawingContext.
                dc.Close();

                // Finally, print the page.
                dlg.PrintVisual(vis, "My first print job");

            }
        }
Example #52
-1
        public static void AskToPrint( FrameworkElement ctrl
                                     , string printJobDesc = "Scaled Visual")
        {
            PrintDialog print = new PrintDialog();
            if (print.ShowDialog() != true) return;

            PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket);

            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / ctrl.ActualWidth,
                                    capabilities.PageImageableArea.ExtentHeight / ctrl.ActualHeight);

            //Transform oldTransform = ctrl.LayoutTransform;

            ctrl.LayoutTransform = new ScaleTransform(scale, scale);

            //Size oldSize = new Size(ctrl.ActualWidth, ctrl.ActualHeight);

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            ctrl.Measure(sz);
            ((UIElement)ctrl).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight),
                sz));

            ctrl.Focus();

            print.PrintVisual(ctrl, printJobDesc);
            //ctrl.LayoutTransform = oldTransform;

            //ctrl.Measure(oldSize);

            //((UIElement)ctrl).Arrange(new Rect(new Point(0, 0),
            //    oldSize));
        }
Example #53
-1
 public static void AskToPrint( ContentPresenter content
                              , string printJobDesc = "Tab Content Visual")
 {
     var dlg = new PrintDialog();
     if (dlg.ShowDialog() != true) return;
     dlg.PrintVisual(content, printJobDesc);
 }
Example #54
-1
        public static void Print(Grid printedPage)
        {
            PrintDialog dialog = new PrintDialog();

            dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
            dialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
            dialog.PrintTicket.OutputQuality = OutputQuality.High;
            dialog.PrintTicket.PageBorderless = PageBorderless.None;
            dialog.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);

            if (dialog.ShowDialog() == true)
            {
                double pageHeight = printedPage.Height;
                double pageWidth = printedPage.Width;

                printedPage.Height = dialog.PrintableAreaHeight;
                printedPage.Width = dialog.PrintableAreaWidth;

                dialog.PrintVisual(printedPage, "");

                printedPage.Height = pageHeight;
                printedPage.Width = pageWidth;

            }
        }
Example #55
-1
        public static void PrintVisual(Grid g)
        {
            printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == false)
                return;
            FrameworkElement e = g as FrameworkElement;
            Transform originalScale = e.LayoutTransform;   
           
            //get selected printer capabilities
            PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
            //get scale of the print wrt to screen of WPF visual
            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / g.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
            g.ActualHeight);
            //Transform the Visual to scale
            g.LayoutTransform = new ScaleTransform(scale, scale);
            //get the size of the printer page

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            //update the layout of the visual to the printer page size.

            g.Measure(sz);
            g.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            //now print the visual to printer to fit on the one page.
           
            printDialog.PrintVisual(g, "Onion Smart Solutions");

            e.LayoutTransform = originalScale;
        }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     PrintDialog printDialog = new PrintDialog();
     if (printDialog.ShowDialog().GetValueOrDefault(false))
     {
         printDialog.PrintVisual(this, this.Title);
     }
 }
Example #57
-1
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     PrintDialog dialog = new PrintDialog();
     if (dialog.ShowDialog() == true)
     {
         dialog.PrintVisual(printArea, "Print Demo");
     }
 }
 private void Print_Click(object sender, RoutedEventArgs e)
 {
     var dlg = new PrintDialog();
     if (dlg.ShowDialog().GetValueOrDefault())
     {
         dlg.PrintVisual(view1.Viewport, this.Title);
     }
 }
 public void Print()
 {
     PrintDialog dialog = new PrintDialog();
     if (dialog.ShowDialog() == true)
     {
         dialog.PrintVisual(grdMain, "Social Network Analysis");
     }
 }
        private void btnPrintCommandList_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dlg = new PrintDialog();

            if (dlg.ShowDialog() == true)
            {
                dlg.PrintVisual(this.canvasCommands as Visual, "Command Lists");
            }
        }