2011-08-01 3 views
1

richTextBox 각 단어 위에 이미지 adorner 개의 레이어가 포함 된 편집기가 있습니다.
문서를 좋은 형식으로 인쇄하고 adorner 그림 레이어도 인쇄하고 싶습니다.
이것을 수행 할 수있는 방법이 있습니까?
나는 PrintDialog을 시도했으나 adorner 레이어를 인쇄하지 못했습니다.RichTextBox의 Adorner 레이어 인쇄

+0

아니 직접 답변을 할 수 있지만,이 링크가 도움이 HTTP : //social.msdn.microsoft.com/Forums/en-US/wpf/thread/ae8312df-9ed9-4c4c-951b-42cee5427afa/ 전체 콘텐츠 컨트롤을 XPS로 인쇄 할 수 있으며이를 사용하여 꾸미기를 가져야합니다. 희망이 도움이됩니다. – NetSquirrel

답변

0

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ae8312df-9ed9-4c4c-951b-42cee5427afa/을 사용하여 항목과 연결된 Adorner 레이어를 인쇄 할 수있었습니다. RichTextBox에서 작동하는지 모릅니다. RichTextBox 안에 Adorner를 추가 할 수 없었습니다.

Adorner가 OnRender에 추가 되었기 때문에 인쇄하기 전에 모두 화면에 렌더링 될 때까지 기다려야했기 때문에 (인쇄 버튼) Window_Loaded 함수로 인쇄하면 Adorner 레이어가 표시되지 않습니다.

AdornerLayer에서 인쇄하려면 StyleContent to ContentControl이 필요합니다.

코드는 다음과 같습니다

<Window x:Class="WpfApplication1.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"> 
<Window.Resources> 
    <Style TargetType="{x:Type ContentControl}"> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type ContentControl}"> 
     <AdornerDecorator> 
      <ContentPresenter 
        Content="{TemplateBinding Content}" 
        ContentTemplate="{TemplateBinding ContentTemplate}" /> 
     </AdornerDecorator> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 
</Window.Resources> 
<ContentControl Name="MyContent"> 
    <StackPanel> 
<Grid Name="MyGrid" Margin="10"> 
    <RichTextBox Name="MyDoc" Margin="2"> 
     <FlowDocument Name="MyFlow"> 
      <Paragraph Name="MyParagraph"> 
       I am a flow document. Would you like to edit me? 
        <Bold>Go ahead.</Bold> 
      </Paragraph> 

      <Paragraph Foreground="Blue"> 
       I am blue I am blue I am blue. 
      </Paragraph> 
     </FlowDocument> 
    </RichTextBox> 
</Grid> 
     <Button Click="Button_Click">Print</Button> 
     </StackPanel> 
</ContentControl> 

창 코드

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 
    } 

    private void Window_Loaded(object sender, RoutedEventArgs e) 
    { 
     var myAdornerLayer = AdornerLayer.GetAdornerLayer(MyDoc); 
     myAdornerLayer.Add(new SimpleCircleAdorner(MyDoc)); 


    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     LocalPrintServer ps = new LocalPrintServer(); 
     PrintQueue pq = ps.DefaultPrintQueue; 
     XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq); 
     PrintTicket pt = pq.UserPrintTicket; 
     if (xpsdw != null) 
     { 
      pt.PageOrientation = PageOrientation.Portrait; 
      PageMediaSize pageMediaSize = new PageMediaSize(this.ActualWidth, this.ActualHeight); 
      pt.PageMediaSize = pageMediaSize; 

      xpsdw.Write(MyContent); 
     } 
    } 
} 

Adorner 마이크로 소프트 SimpleCircleAdorner에서.

희망이 도움이됩니다.

+0

위대한 작품이지만, 전체 문서의 내용이 아닌 화면에 보이는 문서의 내용 만 인쇄합니다. ( – raym0nd

+0

"렌더시"가 추가되었으므로 아마도 가능하지 않습니다. "off-sceen"인쇄하기 인쇄용으로 모든 것을 준비하고 문서에 임베드 된 실제 이미지로 Adorners를 추가하는 실제 XPS 문서를 만드는 것이 가장 좋은 방법 일 수 있습니다. 지금은 더 좋은 제안이 없습니다. , 행운을 빌어 요. – NetSquirrel

+0

어떻게 할 수 있습니까? 이미 많은 것을 시도해 봤지만 아무 것도 좋은 결과를주지 못했습니다. – raym0nd

0

보고서를 작성해야 할 때 사용한 대체 방법은 FlowDocument을 사용하여 필요한 모든 것을 포함 시켰습니다. 그 모습을 here과 같이 볼 수 있습니다.

다음은이 보고서를 생성하는 데 사용되는 추악한 코드입니다.이 방법이 도움이 될 수 있으면 도움이 되었으면합니다. 너무 오래 걸리면 사과 할 시간이 없으므로 "// Start of FlowDocument"에서 읽기 시작하십시오.

UI 요소를 보고서에 포함 시키려면 FlowDocument 링크에 설명 된대로 UIContainers를 사용할 수 있습니다. 그리고 아마 플로우 문서에 Adorners를 추가하기 위해 here on stackoverflow을 생성 한 솔루션과 섞어봤을까요?

private FlowDocument HydroPowerReportI(string PlantPath, string PlantName, bool filled) 
    { 
     //Ignore these first 20 lines, they are there to populate my data 
     List<HydroMarket.LocalData.BinaryIO.HydroFileIO.Report1> data = new List<HydroMarket.LocalData.BinaryIO.HydroFileIO.Report1>(); 
     int nTime = 0; 
     List<int> iReportingPoints = new List<int>(); 
     SimulationsTreeViewModel S = (this.DataContext as SimulationsTreeViewModel); 
     List<DateTime> dates = new List<DateTime>(); 
     if (filled) 
     { 
      if (HydroFileIO.ObtainReportI(data, out nTime, PlantPath)) 
      { 
       MarketParameters m = MarketParameters.ReadScenarioParameters(new FileInfo(System.IO.Path.Combine(PlantPath, "MarketParam.bin"))); 
       iReportingPoints.Add(0); 
       iReportingPoints.Add(1); 
       iReportingPoints.Add(2); 
       iReportingPoints.Add(3); 
       iReportingPoints.Add(4); 

       dates.Add(m.ValueDate); 
       foreach (DateTime x in m.ReportingDates) 
       { 
        DateTime dt = SetBetween(m.ValueDate, x, m.Maturity); 
        dates.Add(dt); 
       } 
       dates.Add(m.Maturity); 
      } 
      else 
      { 
       filled = false; 
      } 
     } 
     //START of FlowDocument 
     Brush HeaderColor = Brushes.RoyalBlue; 
     FlowDocument flowDoc = new FlowDocument(); 

     //Original table holder with columns 
     Table table2 = new Table(); 
     flowDoc.Blocks.Add(table2); 

     table2.Columns.Add(new TableColumn()); 
     table2.Columns.Add(new TableColumn()); 
     table2.Columns.Add(new TableColumn()); 
     table2.Columns.Add(new TableColumn()); 
     table2.Columns.Add(new TableColumn()); 
     table2.Columns.Add(new TableColumn()); 

     table2.Columns[0].Width = new GridLength(280); 

     // Create and add an empty TableRowGroup to hold the table's Rows. 
     table2.RowGroups.Add(new TableRowGroup()); 
     // Add the first (title) row. 
     table2.RowGroups[0].Rows.Add(new TableRow()); 
     // Alias the current working row for easy reference. 
     TableRow currentRow2 = new TableRow(); 
     currentRow2 = table2.RowGroups[0].Rows[0]; 

     // Add cells with content to the second row. 
     currentRow2.Cells.Add(new TableCell(new Paragraph(new Run("Valuation Report")))); 
     currentRow2.Cells[0].ColumnSpan = 6; //1 less than center for offsetting it 
     currentRow2.FontSize = 32; 
     currentRow2.Foreground = HeaderColor; 
     currentRow2.Cells[0].TextAlignment = TextAlignment.Left; 

     table2.RowGroups[0].Rows.Add(new TableRow()); 
     currentRow2 = table2.RowGroups[0].Rows[1]; 
     if (filled) 
      if (S.SimSetup.LastSimulation.HasValue) 
       currentRow2.Cells.Add(new TableCell(new Paragraph(new Run("Valuation: " + S.Name + "\nMarket: " + S.SimSetup.Market.Name + "\nPlant: " + PlantName + "\nLast simulated at: " + S.SimSetup.LastSimulation.Value.ToLongDateString() + " " + S.SimSetup.LastSimulation.Value.ToShortTimeString())))); 
      else 
       currentRow2.Cells.Add(new TableCell(new Paragraph(new Run("Valuation: " + S.Name + "\nMarket: " + S.SimSetup.Market.Name + "\nPlant: " + PlantName)))); 
     else 
     { 
      //BUGFIX: 091113 
      //When no data is loaded, it is unclear that it has not loaded data 
      currentRow2.Cells.Add(new TableCell(new Paragraph(new Run("No simulation data available for valuation " + S.Name)))); 
     } 
     currentRow2.Cells[0].TextAlignment = TextAlignment.Left; 
     currentRow2.Cells[0].ColumnSpan = 6; //all for the center 
     currentRow2.Cells[0].Padding = new Thickness(10); 

     //Table Headers 
     // Create and add an empty TableRowGroup to hold the table//s Rows. 
     table2.RowGroups.Add(new TableRowGroup()); 
     // Add the first (title) row. 
     table2.RowGroups[1].Rows.Add(new TableRow()); 
     // Alias the current working row for easy reference. 
     int iRow = 0; 
     TableRow currentRow = new TableRow(); 
     currentRow = table2.RowGroups[1].Rows[iRow]; 
     // Add the header row with content, 
     if (filled) 
     { 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Value date")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Maturity")))); 

      table2.RowGroups[1].Rows.Add(new TableRow()); 
      iRow = 1; 
      currentRow = table2.RowGroups[1].Rows[iRow]; 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dates[0].ToShortDateString())))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dates[1].ToShortDateString())))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dates[2].ToShortDateString())))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dates[3].ToShortDateString())))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(dates[4].ToShortDateString())))); 
     } 
     else 
     { 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Value date")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Maturity")))); 
      table2.RowGroups[1].Rows.Add(new TableRow()); 
      iRow = 1; 
      currentRow = table2.RowGroups[1].Rows[iRow]; 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
      currentRow.Cells.Add(new TableCell(new Paragraph(new Run(" ")))); 
     } 
     for (int i = 0; i < 6; i++) 
     { 
      currentRow.Cells[i].Foreground = HeaderColor; 
      currentRow.Cells[i].TextAlignment = TextAlignment.Right; 
     } 
     iRow++; 
     table2.RowGroups[1].Rows.Add(new TableRow()); 
     currentRow = table2.RowGroups[1].Rows[iRow]; 
     currentRow.Cells.Add(new TableCell()); 
     currentRow.Cells[0].ColumnSpan = 6; 
     currentRow.Cells[0].BorderThickness = new Thickness(0, 5, 0, 0); 
     currentRow.Cells[0].BorderBrush = HeaderColor; 

     for (int i = 3; i < 23; i++) 
     { 
      table2.RowGroups[1].Rows.Add(new TableRow()); 
      currentRow = table2.RowGroups[1].Rows[i]; 
     } 
     table2.RowGroups[1].Rows[3].Cells.Add(new TableCell(new Paragraph(new Run("Expected value")))); 
     table2.RowGroups[1].Rows[4].Cells.Add(new TableCell(new Paragraph(new Run("Expected price")))); 
     table2.RowGroups[1].Rows[5].Cells.Add(new TableCell(new Paragraph(new Run("Expected income (cumulated)")))); 
     table2.RowGroups[1].Rows[6].Cells.Add(new TableCell(new Paragraph(new Run("Expected income")))); 
     table2.RowGroups[1].Rows[7].Cells.Add(new TableCell(new Paragraph(new Run("Expected income by generation")))); 
     table2.RowGroups[1].Rows[8].Cells.Add(new TableCell(new Paragraph(new Run("Expected costs of pumping")))); 
     table2.RowGroups[1].Rows[9].Cells.Add(new TableCell(new Paragraph(new Run("Expected penalties")))); 
     table2.RowGroups[1].Rows[10].Cells.Add(new TableCell(new Paragraph(new Run("Expected costs of switching on/off")))); 
     table2.RowGroups[1].Rows[11].Cells.Add(new TableCell(new Paragraph(new Run("Standard deviation of value")))); 
     table2.RowGroups[1].Rows[12].Cells.Add(new TableCell(new Paragraph(new Run("Value at Risk (95%)")))); 
     table2.RowGroups[1].Rows[13].Cells.Add(new TableCell(new Paragraph(new Run("Generated electricity (MWh)")))); 
     table2.RowGroups[1].Rows[14].Cells.Add(new TableCell(new Paragraph(new Run("Consumed electricity (MWh)")))); 
     table2.RowGroups[1].Rows[15].Cells.Add(new TableCell(new Paragraph(new Run("Days generated")))); 
     table2.RowGroups[1].Rows[16].Cells.Add(new TableCell(new Paragraph(new Run("Days pumped")))); 
     table2.RowGroups[1].Rows[17].Cells.Add(new TableCell(new Paragraph(new Run("Expected volume (m³)")))); 
     table2.RowGroups[1].Rows[18].Cells.Add(new TableCell(new Paragraph(new Run("Expected volume used for generation (m³)")))); 
     table2.RowGroups[1].Rows[19].Cells.Add(new TableCell(new Paragraph(new Run("Expected volume used for pumping (m³)")))); 
     table2.RowGroups[1].Rows[20].Cells.Add(new TableCell(new Paragraph(new Run("Expected volume natural inflow (m³)")))); 
     table2.RowGroups[1].Rows[21].Cells.Add(new TableCell(new Paragraph(new Run("Standard deviation of volume")))); 
     table2.RowGroups[1].Rows[22].Cells.Add(new TableCell(new Paragraph(new Run("Volume at risk")))); 

     if (filled) 
     { 
      //Writing 
      for (int j = 0; j < 5; j++) 
      { 
       table2.RowGroups[1].Rows[3].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].Value.ToString("N0"))))); 
       table2.RowGroups[1].Rows[4].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].Price.ToString("N0"))))); 
       table2.RowGroups[1].Rows[5].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].IncomeCum.ToString("N0"))))); 
       table2.RowGroups[1].Rows[6].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].Income.ToString("N0"))))); 
       //table2.RowGroups[1].Rows[6].Cells.Add(new TableCell(new Paragraph(new Run(income[j].ToString("N0"))))); 
       table2.RowGroups[1].Rows[7].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].IncomeGen.ToString("N0"))))); 
       table2.RowGroups[1].Rows[8].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].CostsPmp.ToString("N0"))))); 
       table2.RowGroups[1].Rows[9].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].Penalties.ToString("N0"))))); 
       table2.RowGroups[1].Rows[10].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].CostSwitch.ToString("N0"))))); 
       table2.RowGroups[1].Rows[11].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].StdValue.ToString("N0"))))); 
       table2.RowGroups[1].Rows[12].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].VaRValue.ToString("N0"))))); 
       table2.RowGroups[1].Rows[13].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].PowGen.ToString("N0"))))); 
       table2.RowGroups[1].Rows[14].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].PowPump.ToString("N0"))))); 
       table2.RowGroups[1].Rows[15].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].DaysGen.ToString("N0"))))); 
       table2.RowGroups[1].Rows[16].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].DaysPmp.ToString("N0"))))); 
       table2.RowGroups[1].Rows[17].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].Volume.ToString("N0"))))); 
       table2.RowGroups[1].Rows[18].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].VolGen.ToString("N0"))))); 
       table2.RowGroups[1].Rows[19].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].VolPmp.ToString("N0"))))); 
       table2.RowGroups[1].Rows[20].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].VolNat.ToString("N0"))))); 
       table2.RowGroups[1].Rows[21].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].StdVolume.ToString("N0"))))); 
       table2.RowGroups[1].Rows[22].Cells.Add(new TableCell(new Paragraph(new Run(data[iReportingPoints[j]].VaRVolume.ToString("N0"))))); 
      } 
     } 
     else 
     { 
      double d = 0.00; 
      for (int j = 0; j < 5; j++) 
      { 
       for (int k = 3; k < 23; k++) 
        table2.RowGroups[1].Rows[k].Cells.Add((new TableCell(new Paragraph(new Run(d.ToString("N0")))))); 
      } 
     } 
     for (int r = 3; r < 23; r++) 
      for (int j = 1; j < 6; j++) 
       table2.RowGroups[1].Rows[r].Cells[j].TextAlignment = TextAlignment.Right; 

     for (int j = 0; j < 6; j++) 
     { 
      table2.RowGroups[1].Rows[10].Cells[j].BorderThickness = new Thickness(0, 1, 0, 0); 
      table2.RowGroups[1].Rows[10].Cells[j].BorderBrush = Brushes.Black; 
      table2.RowGroups[1].Rows[12].Cells[j].BorderThickness = new Thickness(0, 1, 0, 0); 
      table2.RowGroups[1].Rows[12].Cells[j].BorderBrush = Brushes.Black; 
      table2.RowGroups[1].Rows[14].Cells[j].BorderThickness = new Thickness(0, 1, 0, 0); 
      table2.RowGroups[1].Rows[14].Cells[j].BorderBrush = Brushes.Black; 
      table2.RowGroups[1].Rows[20].Cells[j].BorderThickness = new Thickness(0, 1, 0, 0); 
      table2.RowGroups[1].Rows[20].Cells[j].BorderBrush = Brushes.Black; 
      table2.RowGroups[1].Rows[22].Cells[j].BorderThickness = new Thickness(0, 1, 0, 0); 
      table2.RowGroups[1].Rows[22].Cells[j].BorderBrush = Brushes.Black; 
     } 

     return flowDoc; 
    } 
정말