2012-02-16 28 views
0

hello Friends Today私は妻のために小さなwpfアプリケーションを作成しようとしています。私は彼女が実行時にwrıteし、彼女がflowdocumentで書くものを印刷することができます。私は、設計時にeverthingsを行うことができますが、私はおそらく私がınotifyPropertyは、私はあなたが私をHELLPすることができます何をすべきかPRINTDLGにWYSIWYG編集のためにWPFのRunTime FlowDocumentでダイナミックに書き込みと印刷

/// <summary> 
/// This method creates a dynamic FlowDocument. You can add anything to this 
/// FlowDocument that you would like to send to the printer 
/// </summary> 
/// <returns></returns> 
private FlowDocument CreateFlowDocument() 
{ 
// Create a FlowDocument 
FlowDocument doc = new FlowDocument(); 
// Create a Section 
Section sec = new Section(); 
// Create first Paragraph 
Paragraph p1 = new Paragraph(); 
// Create and add a new Bold, Italic and Underline 
Bold bld = new Bold(); 
bld.Inlines.Add(new Run("First Paragraph")); 
Italic italicBld = new Italic(); 
italicBld.Inlines.Add(bld); 
Underline underlineItalicBld = new Underline(); 
underlineItalicBld.Inlines.Add(italicBld); 
// Add Bold, Italic, Underline to Paragraph 
p1.Inlines.Add(underlineItalicBld); 
// Add Paragraph to Section 
sec.Blocks.Add(p1); 
// Add Section to FlowDocument 
doc.Blocks.Add(sec); 
return doc; 
} 









private void print(object sender, RoutedEventArgs e) 
{ 
// Create a PrintDialog 
PrintDialog printDlg = new PrintDialog(); 
// Create a FlowDocument dynamically. 
FlowDocument doc = CreateFlowDocument(); 
doc.Name = "FlowDoc"; 
// Create IDocumentPaginatorSource from FlowDocument 
IDocumentPaginatorSource idpSource = doc; 
// Call PrintDocument method to send document to printer 
printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing."); 
} 

答えて

1

をしてください変更またはflowdocumentの結合テキストıを使用する必要があります。ここに私の解決策をAR実行時間を書きたいです、WPFは既製のコントロールを提供します。 WPF RichTextBoxコントロールは、XAMLフロードキュメントをネイティブに編集できます。

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

1

あなたがリッチテキストボックス内FlowDocumentはxps.format

/* ** 、見つける私ここにあなたがPDFを印刷して保存することができます最善の解決策編集可能です言ったように私はば完全に忘れてしまっています*** ** * ** * ** * ** * * * ** * ** * ** * ** * ** * ** * ** * ** * ** ** * ***/

// 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); 
     } 

    } 
関連する問題