private Block ConvertTextDocumentToBlock()
        {
            TextDocument document    = textEditor.Document;
            IHighlighter highlighter =
                textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            return(DocumentPrinter.ConvertTextDocumentToBlock(document, highlighter));

            //Paragraph p = new Paragraph();
            //foreach (DocumentLine line in document.Lines)
            //{
            //    int lineNumber = line.LineNumber;
            //    HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
            //    if (highlighter != null)
            //    {
            //        HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
            //        int lineStartOffset = line.Offset;
            //        foreach (HighlightedSection section in highlightedLine.Sections)
            //            inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
            //    }
            //    p.Inlines.AddRange(inlineBuilder.CreateRuns());
            //    p.Inlines.Add(new LineBreak());
            //}

            //return p;
        }
        protected void PrintCurrentPage(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = (args.Document != null &&
                                args.EditorControl != null &&
                                args.Document.Options.BehaviorOptions.Printable);
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                args.Result = false;
                if (args.Document.Options.BehaviorOptions.Printable == false)
                {
                    // 文档禁止打印
                    return;
                }
                DocumentPrinter printer = new DocumentPrinter(args.Document);
                if (args.EditorControl != null)
                {
                    printer.JumpPrint   = args.EditorControl._JumpPrint;
                    printer.CurrentPage = args.EditorControl.CurrentPage;
                }
                if (args.Parameter is JumpPrintInfo)
                {
                    JumpPrintInfo info = (JumpPrintInfo)args.Parameter;
                    printer.JumpPrint = args.Document.GetJumpPrintInfo(info.Position);
                }
                printer.PrintRange = System.Drawing.Printing.PrintRange.CurrentPage;

                InnerPrint(args, printer, false);
            }
        }
        protected void OnButtonViewDocumentClicked(object sender, EventArgs e)
        {
            ITdiTab mytab = DialogHelper.FindParentTab(this);

            if (mytab == null)
            {
                return;
            }

            CounterpartyDocumentNode selectedPrintableDocuments = (ytreeDocuments.GetSelectedObject() as CounterpartyDocumentNode);

            if (selectedPrintableDocuments.Document is CounterpartyContract)
            {
                int        contractID = (selectedPrintableDocuments.Document as CounterpartyContract).Id;
                ITdiDialog dlg        = new CounterpartyContractDlg(contractID);
                mytab.TabParent.AddTab(dlg, mytab);
            }

            if (selectedPrintableDocuments.Document is OrderDocument)
            {
                var rdlDoc = (selectedPrintableDocuments.Document as IPrintableRDLDocument);
                if (rdlDoc != null)
                {
                    mytab.TabParent.AddTab(DocumentPrinter.GetPreviewTab(rdlDoc), mytab);
                }
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            const string PrinterName = "Microsoft Print to PDF";

            // Create an instance of Bytescout.PDFRenderer.DocumentPrinter object and register it.
            DocumentPrinter documentPrinter = new DocumentPrinter();

            documentPrinter.RegistrationName = "demo";
            documentPrinter.RegistrationKey  = "demo";

            // Load PDF document.
            documentPrinter.LoadDocumentFromFile("multipage.pdf");

            // Change some printing options for demo purposes
            // (note, some options might be not supported by the printer):

            // Change paper orientation
            documentPrinter.Landscape = true;
            // Set number of copies
            documentPrinter.Copies = 2;
            // Set collation
            documentPrinter.Collate = true;
            // Force black and white printing
            documentPrinter.Color = false;

            // Print all document pages to the specified printer
            documentPrinter.PrintDocument(PrinterName);

            // To print specific pages use overridden methods allowing to define pages to print:
            //documentPrinter.PrintDocument(PrinterName, 2, 4); // printer pages from 3 to 5
            //documentPrinter.PrintDocument(PrinterName, new int[] {0, 2, 3, 4, 6}); // print specific pages
            //documentPrinter.PrintDocument(PrinterName, "1,3-5,7-");

            documentPrinter.Dispose();
        }
Exemple #5
0
        private Block ConvertTextDocumentToBlock()
        {
            TextDocument document    = textEditor.Document;
            IHighlighter highlighter =
                textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            return(DocumentPrinter.ConvertTextDocumentToBlock(document, highlighter));
        }
        void Orderselectedview1_OrderActivated(object sender, int e)
        {
            var doc = UoW.GetById <OrderDocument>(e) as IPrintableRDLDocument;

            if (doc == null)
            {
                return;
            }
            TabParent.AddTab(DocumentPrinter.GetPreviewTab(doc), this, false);
        }
Exemple #7
0
        /// <summary>
        /// Creates a <see cref="FlowDocument"/> containing the text.
        /// </summary>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="pagePadding">The page padding.</param>
        /// <returns>A <see cref="FlowDocument"/>.</returns>
        /// <remarks>
        /// </remarks>
        public FlowDocument CreateFlowDocument(Size pageSize, Thickness pagePadding)
        {
            var doc = DocumentPrinter.CreateFlowDocumentForEditor(this);

            doc.ColumnWidth = pageSize.Width;
            doc.FontStretch = FontStretch;
            doc.FontStyle   = FontStyle;
            doc.FontWeight  = FontWeight;
            doc.PageWidth   = pageSize.Width;
            doc.PageHeight  = pageSize.Height;
            doc.PagePadding = pagePadding;
            return(doc);
        }
        public void AddCodeBlock(string textContent, bool keepLargeMargin = false)
        {
            var document = new ReadOnlyDocument(textContent);
            var highlightingDefinition = HighlightingManager.Instance.GetDefinition(SyntaxHighlighting);

            var block = DocumentPrinter.ConvertTextDocumentToBlock(document, highlightingDefinition);

            block.FontFamily = GetCodeFont();
            if (!keepLargeMargin)
            {
                block.Margin = new Thickness(0, 6, 0, 6);
            }
            AddBlock(block);
        }
Exemple #9
0
 private void PrintReportCompleted(Task <string[]> task)
 {
     IsBusy = false;
     if (TaskIsFauledOrCancelled(task, "Print"))
     {
         return;
     }
     dialogService.AsyncRequestPrintingConfirmation(continuePrinting => {
         if (continuePrinting)
         {
             DocumentPrinter documentPrinter = new DocumentPrinter();
             documentPrinter.Print(new XamlDocumentPaginator(task.Result), "Print Document Name");
         }
     });
 }
        private void InnerPrint(
            WriterCommandEventArgs args,
            DocumentPrinter printer,
            bool refreshDocument)
        {
            System.Windows.Forms.Cursor cur = null;
            JumpPrintInfo infoBack          = null;
            int           piBack            = -1;

            if (args.EditorControl != null)
            {
                infoBack = args.EditorControl._JumpPrint.Clone();
                if (infoBack.Enabled && infoBack.Page != null)
                {
                    piBack = args.EditorControl.Pages.IndexOf(infoBack.Page);
                }

                printer.WriterControl = args.EditorControl;
                cur = args.EditorControl.Cursor;
                args.EditorControl.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                if (refreshDocument)
                {
                    // 冻结用户界面
                    args.EditorControl.FreezeUI();
                }
            }
            try
            {
                args.Result = printer.PrintDocument(args.ShowUI);
            }
            finally
            {
                if (args.EditorControl != null)
                {
                    if (refreshDocument)
                    {
                        args.EditorControl.RefreshDocument();
                        if (piBack >= 0)
                        {
                            infoBack.Page = args.EditorControl.Pages[piBack];
                            args.EditorControl._JumpPrint = infoBack;
                        }
                        args.EditorControl.ReleaseFreezeUI();
                    }
                    args.EditorControl.Cursor = cur;
                }
            }
        }
Exemple #11
0
        private void PrintLabels()
        {
            string rtvShipper = mesTbxRtvShipper.Text.Trim();

            if (rtvShipper == "")
            {
                panel2.Dock    = DockStyle.None;
                Cursor.Current = Cursors.Default;

                _messages.Message = "RTV shipper is required.";
                _messages.ShowDialog();
                return;
            }
            int iShipper = Convert.ToInt32(rtvShipper);

            // Get a list of serial numbers tied to this shipper
            string        error;
            List <string> serials = new List <string>();

            serials = _controller.GetShipperSerials(iShipper, out error);
            if (error != "")
            {
                panel2.Dock    = DockStyle.None;
                Cursor.Current = Cursors.Default;

                _messages.Message = error;
                _messages.ShowDialog();
                return;
            }

            foreach (var item in serials)
            {
                // Get label code with label data
                int    serial    = Convert.ToInt32(item);
                string labelCode = _controller.GetLabelCode(serial, out error);

                // Print the label
                bool result = DocumentPrinter.Print(labelCode);
                if (result == false)
                {
                    panel2.Dock    = DockStyle.None;
                    Cursor.Current = Cursors.Default;

                    _messages.Message = string.Format("Failed to print a label for serial {0}.", serial.ToString());
                    _messages.ShowDialog();
                }
            }
        }
Exemple #12
0
        public void AddCodeBlock(string textContent, bool keepLargeMargin = false)
        {
            var document    = new TextDocument(textContent);
            var highlighter = new DocumentHighlighter(document, highlightingDefinition);
            var richText    = DocumentPrinter.ConvertTextDocumentToRichText(document, highlighter).ToRichTextModel();

            var block = new Paragraph();

            block.Inlines.AddRange(richText.CreateRuns(document));
            block.FontFamily = GetCodeFont();
            if (!keepLargeMargin)
            {
                block.Margin = new Thickness(0, 6, 0, 6);
            }
            AddBlock(block);
        }
        public void AddSignatureBlock(string signature, int currentParameterOffset, int currentParameterLength, string currentParameterName)
        {
            ParameterName = currentParameterName;
            var document = new ReadOnlyDocument(signature);
            var highlightingDefinition = HighlightingManager.Instance.GetDefinition(SyntaxHighlighting);

            var richText = DocumentPrinter.ConvertTextDocumentToRichText(document, highlightingDefinition).ToRichTextModel();

            richText.SetFontWeight(currentParameterOffset, currentParameterLength, FontWeights.Bold);
            var block = new Paragraph();

            block.Inlines.AddRange(richText.CreateRuns(document));
            block.FontFamily    = GetCodeFont();
            block.TextAlignment = TextAlignment.Left;
            AddBlock(block);
        }
Exemple #14
0
        public BitmapSource PrintToBitmap(string script, Size size)
        {
            var editor = GetOrCreateTextEditor(script, FontFamily, FontSize, IndentationSize);

            var document = DocumentPrinter.CreateFlowDocumentForEditor(editor);

            document.PagePadding = Padding;

            if (loadedHighlightingDefinition != null)
            {
                var defaultNamedColor = loadedHighlightingDefinition.GetNamedColor("Default");
                if (defaultNamedColor != null)
                {
                    document.Foreground = defaultNamedColor.Foreground.GetBrush(null);
                }
            }

            return(FlowDocumentToBitmap(document, size));
        }
Exemple #15
0
        public void AddSignatureBlock(string signature, RichTextModel highlighting = null)
        {
            var document = new TextDocument(signature);
            var richText = highlighting ?? DocumentPrinter.ConvertTextDocumentToRichText(document, new DocumentHighlighter(document, highlightingDefinition)).ToRichTextModel();
            var block    = new Paragraph();
            // HACK: measure width of signature using a TextBlock
            // Paragraph sadly does not support TextWrapping.NoWrap
            var text = new TextBlock {
                FontFamily    = GetCodeFont(),
                FontSize      = DisplaySettingsPanel.CurrentDisplaySettings.SelectedFontSize,
                TextAlignment = TextAlignment.Left
            };

            text.Inlines.AddRange(richText.CreateRuns(document));
            text.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            this.document.MinPageWidth = Math.Min(text.DesiredSize.Width, MainWindow.Instance.ActualWidth);
            block.Inlines.AddRange(richText.CreateRuns(document));
            block.FontFamily    = GetCodeFont();
            block.TextAlignment = TextAlignment.Left;
            AddBlock(block);
        }
        /// <summary>
        /// Prints the current document honoring the selected page range.
        /// </summary>
        public void Print()
        {
            try
            {
                // select pages to print
                var ps    = _doc.PrinterSettings;
                int first = ps.MinimumPage - 1;
                int last  = ps.MaximumPage - 1;
                switch (ps.PrintRange)
                {
                case PrintRange.AllPages:
                    Document.Print();
                    return;

                case PrintRange.CurrentPage:
                    first = last = StartPage;
                    break;

                case PrintRange.Selection:
                    first = last = StartPage;
                    if (ZoomMode == ZoomMode.TwoPages)
                    {
                        last = Math.Min(first + 1, PageCount - 1);
                    }
                    break;

                case PrintRange.SomePages:
                    first = ps.FromPage - 1;
                    last  = ps.ToPage - 1;
                    break;
                }

                // print using helper class
                var dp = new DocumentPrinter(this, first, last);
                dp.Print();
            }
            catch
            {
            }
        }
 private void PrintWarnings()
 {
     DocumentPrinter documentPrinter = new DocumentPrinter();
     documentPrinter.PrintDocument.PrinterSettings = this.printDialog1.PrinterSettings;
     documentPrinter.PrintDocument.DefaultPageSettings.Margins.Top = 0;
     documentPrinter.PrintDocument.DefaultPageSettings.Margins.Right = 0;
     documentPrinter.PrintDocument.DefaultPageSettings.Margins.Bottom = 0;
     documentPrinter.PrintDocument.DefaultPageSettings.Margins.Left = 0;
     documentPrinter.PagePositioning.Horizontal = HPagePosition.Left;
     documentPrinter.PagePositioning.Vertical = VPagePosition.Top;
     documentPrinter.PageScaling = PageScalingOptions.Fit;
     documentPrinter.PrintDocument.DocumentName = this.newFileErr;
     System.IO.Stream file = new System.IO.FileStream(this.newFileErr, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
     documentPrinter.Print(file, "");
     Application.ExitThread();
 }
        /// <summary>
        /// Prints the current document honoring the selected page range.
        /// </summary>
        public void Print()
        {
            // select pages to print
            var ps = _doc.PrinterSettings;
            int first = ps.MinimumPage - 1;
            int last = ps.MaximumPage - 1;
            switch (ps.PrintRange)
            {
                case PrintRange.AllPages:
                    Document.Print();
                    return;
                case PrintRange.CurrentPage:
                    first = last = StartPage;
                    break;
                case PrintRange.Selection:
                    first = last = StartPage;
                    if (ZoomMode == ZoomMode.TwoPages)
                    {
                        last = Math.Min(first + 1, PageCount - 1);
                    }
                    break;
                case PrintRange.SomePages:
                    first = ps.FromPage - 1;
                    last = ps.ToPage - 1;
                    break;
            }

            // print using helper class
            var dp = new DocumentPrinter(this, first, last);
            dp.Print();
        }