コード例 #1
0
        /// <summary>
        /// Creates a DocumentPaginatorWrapper from TextEditor text to print.
        /// </summary>
        public static DocumentPaginatorWrapper CreateDocumentPaginatorToPrint(TextEditor textEditor)
        {
            PrintSettings settings = textEditor.Tag as PrintSettings;

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

            // this baby adds headers and footers
            IDocumentPaginatorSource dps = CreateFlowDocumentToPrint(textEditor);
            DocumentPaginatorWrapper dpw = new DocumentPaginatorWrapper(dps.DocumentPaginator, settings.PageSettings, settings.PrintTicket, textEditor.FontFamily);

            dpw.Title = settings.DocumentTitle;
            return(dpw);
        }
コード例 #2
0
        /// <summary>
        /// Creates a FlowDocument from TextEditor text to print.
        /// </summary>
        public static FlowDocument CreateFlowDocumentToPrint(TextEditor textEditor)
        {
            PrintSettings settings = textEditor.Tag as PrintSettings;

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

            // this baby has all settings to be printed or previewed in the PrintEngine.PrintPreviewDialog
            FlowDocument doc = CreateFlowDocumentForEditor(textEditor);

            doc.ColumnWidth = settings.PageSettings.PrintableArea.Width;
            doc.PageHeight  = (settings.PageSettings.Landscape ? (int)settings.PrintTicket.PageMediaSize.Width : (int)settings.PrintTicket.PageMediaSize.Height);
            doc.PageWidth   = (settings.PageSettings.Landscape ? (int)settings.PrintTicket.PageMediaSize.Height : (int)settings.PrintTicket.PageMediaSize.Width);
            doc.PagePadding = ConvertPageMarginsToThickness(settings.PageSettings.Margins);
            doc.FontFamily  = textEditor.FontFamily;
            doc.FontSize    = textEditor.FontSize;

            return(doc);
        }
コード例 #3
0
        /// <summary>
        /// Prints the the TextEditor.Document to the current printer (no dialogs) with specified title.
        /// </summary>
        public static void PrintDirect(this TextEditor textEditor, string title)
        {
            PrintSettings settings = textEditor.Tag as PrintSettings;

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

            settings.DocumentTitle = (title != null) ? title : String.Empty;
            PrintDialog printDialog = new 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;
            printDialog.PrintDocument(CreateDocumentPaginatorToPrint(textEditor), "PrintDirectJob");
        }