如何打印带有各种格式文本的堆栈面板的精确副本到a4页面以进行打印 [英] How to print exact copy of stack panel with various formatted text on to a4 page for printing purpose

查看:75
本文介绍了如何打印带有各种格式文本的堆栈面板的精确副本到a4页面以进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


我正在研究一种所见即所得的应用程序。我正在使用wpf进行开发。在我的应用程序中,我有十个堆栈面板,每个堆栈面板包含文本。文本格式化并以某种方式对齐。我的要求是将每个堆栈面板打印到每个a4尺寸页面
。每个堆栈面板都应该正好打印在纸上。 


使用我的代码,我可以打印,但是我打印整个窗口,而不是一个文件,我收到十个档案。我想得到一个包含10页的pdf文件,每页应该有每个堆栈面板的精确副本。 


每个堆栈面板高度为800,宽度为500,所需的打印纸尺寸为a4


请查看以下代码。 

 private void PrintDocument(){            
PrintDialog printDialog = new PrintDialog(); 
foreach(rootStackPanel.Children中的StackPanel spnl){
                printDialog.PrintVisual(spnl,""); 
          }                  
}


有没有解决方案。请指导我。 

解决方案

嗨  ;   Kumar Sree,



根据您的描述,您希望将StackPanel打印到多页。根据我的经验,您可以首先捕获UI元素并将其保存为XPS格式,然后打印XPS文件。  
$


这是一个示例显示如何将UI元素保存到XPS文件并打印出来:

打印WPF ListView的内容
$


此外,您可以创建
FlowDocument
相对容易打印。

< FlowDocumentReader Name =" flowReader" ;> 
< FlowDocument Name =" flowDoc">
<段落>
< StackPanel>
< / StackPanel>

< / Paragraph>
< / FlowDocument>
< / FlowDocumentReader>



以下文章介绍如何使用页面将WPF流文档转换为多页XPS大小,保证金和标题。



转换XAML流文档带样式的XPS(多页,
页面大小,标题,边距)

$




最好的问候,

$
Yong Lu




Hi

I am working on a wysiwyg kind of application. I am developing using wpf. In my application, I have ten stack panels and each stack panel contains text. The texts are formatted and aligned in certain way. My requirement is to print each stack panel on to each a4 size page. Each stack panel should be printed exactly it looks on to the paper. 

With my code, I could able to print, but I am getting entire window printed, instead of one file, I am getting ten files. I want to get one pdf file with ten pages and each page should have exact copy of each stackpanel. 

Each stack panel height is 800 and width is 500 and desired print paper size is a4

Please look into the following code. 

private void PrintDocument() {            
PrintDialog printDialog = new PrintDialog(); 
foreach (StackPanel spnl in rootStackPanel.Children) {
                printDialog.PrintVisual(spnl,"");  
          }                   
}

Is there any solution. Please guide me. 

解决方案

Hi   Kumar Sree,

From your description, You want to Print StackPanel into Multipage. Based on my experience, you can firstly capture the UI elements and save it as XPS format and then print the XPS file.  

Here is an example shows how to save the UI element to XPS file and print it:
Printing the contents of a WPF ListView

Besides, you can create a FlowDocument which are relatively easy to print.

       <FlowDocumentReader Name="flowReader">
                <FlowDocument Name="flowDoc">
                    <Paragraph>
                        <StackPanel>
                        </StackPanel>
                     </Paragraph>
                 </FlowDocument>
        </FlowDocumentReader>


This follow article shows how to convert WPF flow document to multiple page XPS with page size, margin, and header.

Convert XAML Flow Document to XPS with Style (multiple page, page size, header, margin)


Best Regards,

Yong Lu


这篇关于如何打印带有各种格式文本的堆栈面板的精确副本到a4页面以进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆