WPF 打印 FlowDocument 未居中
我想打印带有小标题的一些文本的页面。 我希望所有文本都在页面上居中,但我不知道该怎么做。
这是我的代码。它是轨道类型,它只是一个包含艺术家姓名、专辑名称、歌曲等信息的对象标题和歌词。
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");
页面打印得很好,除了打印时整个内容紧贴在文档的左侧...我知道有一些属性我没有正确设置或根本没有设置..
I want to print a page from some text I have with a small header.
I wanted all the text to be centered on the page but I'm not sure how to do it..
Here is my code.. t is of type track which is just an object that holds information like artist name, album name, song title, and lyrics.
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");
The page prints just fine except for the fact that the whole thing clings to the left of the document when printed... I know there is some property I'm not setting correctly or not setting at all..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
增加 ColumnWidth 属性的大小或将其设置为“999999”
increase the size of the ColumnWidth property or just make it '999999'