2

我在尝试打印 FixedDocument 的多页时遇到问题,例如我的预览显示 3 个不同的页面,但是当我单击打印或使用 Printdialog(fixedDoc.DocumentPaginator,"namefile") 时,它总是打印 3 页内容为第 1 页。这是我的固定文档代码。lstBitMap 是 BitmapEncoder 的列表

FixedDocument fixedDoc = new FixedDocument();
fixedDoc.DocumentPaginator.PageSize = pageSize;

foreach (var bitmap in lstBitMapEncode)
{
    ImageSource imageSource;

    using (var stream = new MemoryStream())
    {
        bitmap.Save(stream);
        stream.Position = 0;
        imageSource = BitmapFrame.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
    }

    Canvas canvas = new Canvas();
    canvas.Width = pageSize.Width;
    canvas.Height = pageSize.Height;
    canvas.Background = new ImageBrush(imageSource);
    FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
    FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);

    //add canvas include image to page
    FixedPage page = new FixedPage();
    page.Width = fixedDoc.DocumentPaginator.PageSize.Width;
    page.Height = fixedDoc.DocumentPaginator.PageSize.Height;
    page.Children.Add(canvas);

    // add the page to the document
    PageContent pageContent = new PageContent();
    ((IAddChild)pageContent).AddChild(page);
    fixedDoc.Pages.Add(pageContent);
}
4

0 回答 0