FixedDocument始终打印第一页

时间:2017-07-17 06:49:30

标签: c# wpf fixeddocument

我在尝试打印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);
}

0 个答案:

没有答案