运行时流程文档中的分页
我能够在流文档上获取文本文件,但现在我必须在运行时将内容划分为适当的分页符,即如果内容很大,它们在运行时也会获得同样的页数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TextOnFlowDoc
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(System.IO.File.ReadAllText(@"C:\Lis.txt"));
paragraph.FontFamily = new FontFamily("CourierNew");
FlowDocument document = new FlowDocument(paragraph);
// FlowDocumentReader rdr = new FlowDocumentReader();
FlowDocScl.Document = document;
}
}
}
现在这个“FlowDocScl”现在是一个流文档,需要在运行时分成页面。
I AM able to get a text file on a flow document but now I have to divide the contents in proper pagebreaks at runtime i.e if contents are huge they shud get itself in number of pages that too at runtime.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TextOnFlowDoc
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(System.IO.File.ReadAllText(@"C:\Lis.txt"));
paragraph.FontFamily = new FontFamily("CourierNew");
FlowDocument document = new FlowDocument(paragraph);
// FlowDocumentReader rdr = new FlowDocumentReader();
FlowDocScl.Document = document;
}
}
}
Now this "FlowDocScl" is now a flow document and needs to be breaked into pages AT RUNTIME.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么你想要自定义分页符,如果你在
FlowDocumentPageViewer
例如,如果内容对于查看者来说太大,您会自动中断。如果必须按需插入分隔符,则需要在
块
,它们具有名为BreakPageBefore
当设置为 true 时,显然会在该块之前插入分页符。像这样的东西(未经测试):
I am not sure why you want custom page-breaks, if you display it in a
FlowDocumentPageViewer
for example you get automatic breaks if the content is too large for the viewer.If you must insert breaks on demand you need to split the document in
Blocks
, those have a property calledBreakPageBefore
which when set to true inserts a page break before that block obviously.Something like this (untested):