【发布时间】:2011-05-14 20:59:08
【问题描述】:
我想从我拥有的一些带有小标题的文本中打印一个页面。 我希望所有文本都集中在页面上,但我不知道该怎么做..
这是我的代码.. t 是 track 类型,它只是一个包含艺术家姓名、专辑名称、歌曲标题和歌词等信息的对象。
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() != true)
{ return; }
FlowDocument doc = new FlowDocument();
Section sec = new Section();
Paragraph header = new Paragraph();
Paragraph body = new Paragraph();
Bold boldSong = new Bold();
boldSong.Inlines.Add(new Run(t.Song));
header.Inlines.Add(boldSong);
header.Inlines.Add(new LineBreak());
Bold boldArtist = new Bold();
if (!string.IsNullOrWhiteSpace(t.Artist))
{
boldArtist.Inlines.Add(new Run(t.Artist));
header.Inlines.Add(boldArtist);
header.Inlines.Add(new LineBreak());
}
Bold boldAlbum = new Bold();
if (!string.IsNullOrWhiteSpace(t.Album))
{
boldAlbum.Inlines.Add(new Run(t.Album));
header.Inlines.Add(boldAlbum);
header.Inlines.Add(new LineBreak());
}
header.TextAlignment = TextAlignment.Center;
body.Inlines.Add(t.iTunesFileTrack.Lyrics);
body.TextAlignment = TextAlignment.Center;
doc.Blocks.Add(header);
doc.Blocks.Add(body);
doc.Name = "FlowDoc";
IDocumentPaginatorSource idpSource = doc;
DocumentPaginator holder = idpSource.DocumentPaginator;
holder.PageSize = new Size(dialog.PrintableAreaWidth,
dialog.PrintableAreaHeight);
dialog.PrintDocument(holder, "Lyrics");
页面打印得很好,除了打印时整个东西都紧贴在文档的左侧......我知道有一些属性我没有正确设置或根本没有设置..
【问题讨论】:
标签: wpf printing alignment center flowdocument