不确定您是否仍在与此问题作斗争,但您可以尝试使用 FlowDocument。
如果您在 DocumentPaginator 周围编写一个包装器,您将能够在 flowdoc 中插入一个标题。此外,您可以将 flowdoc.PagePadding 设置为自定义值,同时考虑 printablePageHeight 和内容大小的高度。
这是我从书中获得的 DocumentPaginator 包装器的示例:Pro WPF in C# 2008 - Mathew MacDonald
希望能帮助到你。(PS。我只是复制并粘贴了默认值,所以没有添加任何自定义计算等)
using System.Globalization;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
namespace NPS.ClinicalEAudit.Controls
{
public class FlowDocPaginator : DocumentPaginator
{
private DocumentPaginator _paginator;
public FlowDocPaginator(FlowDocument flowDoc)
{
_paginator = ((IDocumentPaginatorSource) flowDoc).DocumentPaginator;
}
public override bool IsPageCountValid
{
get { return _paginator.IsPageCountValid; }
}
public override int PageCount
{
get { return _paginator.PageCount; }
}
public override Size PageSize
{
get { return _paginator.PageSize; }
set { _paginator.PageSize = value; }
}
public override IDocumentPaginatorSource Source
{
get { return _paginator.Source; }
}
public override DocumentPage GetPage(int pageNumber)
{
// Get the requested page.
DocumentPage page = _paginator.GetPage(pageNumber);
// Wrap the page in a Visual object. You can then apply transformations
// and add other elements.
ContainerVisual newVisual = new ContainerVisual();
newVisual.Children.Add(page.Visual);
// Create a header.
DrawingVisual header = new DrawingVisual();
using (DrawingContext dc = header.RenderOpen())
{
Typeface typeface = new Typeface("Times New Roman");
FormattedText text = new FormattedText("Page " +
(pageNumber + 1).ToString(), CultureInfo.CurrentCulture,
FlowDirection.LeftToRight, typeface, 14, Brushes.Black);
// Leave a quarter inch of space between the page edge and this text.
dc.DrawText(text, new Point(96 * 0.25, 96 * 0.25));
}
// Add the title to the visual.
newVisual.Children.Add(header);
// Wrap the visual in a new page.
DocumentPage newPage = new DocumentPage(newVisual);
return newPage;
}
}
}