不知道你是否仍在與這個問題作鬥爭,但你可以嘗試使用FlowDocument。
如果你在DocumentPaginator上編寫一個包裝器,你將能夠在flowdoc中插入一個頭文件。另外,您可以將flowdoc.PagePadding設置爲自定義值,同時考慮到printablePageHeight和內容大小的高度。
這裏是圍繞DocumentPaginator的包裝,我從書中得到的一個例子:臨WPF在C#2008 - 馬修·麥克唐納
希望它能幫助。 (PS。我只是複製和粘貼默認所以沒有添加任何自定義Calcs(計算)等)
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;
}
}
}