Динамически писать и печатать в RunTime FlowDocument в WPF - PullRequest
0 голосов
/ 16 февраля 2012

привет, друзья! Сегодня я пытаюсь сделать небольшое wpf-приложение для моей жены.Я хочу, чтобы она могла писать во время выполнения и печатать то, что она пишет, в потоковом документе.я могу делать все что угодно во время разработки, но я хочу написать во время выполнения здесь мое решение, вероятно, я должен использовать я уведомить измененный объект или привязать текст flowdocument к printDlg Что я должен сделать, вы можете помочь мне, пожалуйста

Ответы [ 2 ]

1 голос
/ 17 февраля 2012

Я совершенно забыл, как вы сказали, что FlowDocument в RichTextBox можно редактировать здесь. Находите лучшее решение, которое вы можете распечатать и сохранить pdf, xps.format

/ ************* ***************** ***************** ***** /

// Handle "Save RichTextBox Content" button click.
private void SaveRTBContent(Object sender, RoutedEventArgs args)
        {

        // 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 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. 
        PrintDocumentImageableArea ia = null; 
        System.Windows.Xps.XpsDocumentWriter docWriter = 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); 
        } 

    } 
1 голос
/ 17 февраля 2012

Для редактирования WYSIWYG WPF предоставляет готовый элемент управления. Элемент управления WPF RichTextBox может редактировать потоковые документы XAML.

http://msdn.microsoft.com/en-us/magazine/cc163371.aspx

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...