FixedDocument always print first page

☆樱花仙子☆ 提交于 2021-01-28 02:50:39

问题


I have a problem when trying to printing multipage of FixedDocument, for example my preview show 3 different page, but when I click print or using Printdialog(fixedDoc.DocumentPaginator,"namefile"), it always prints 3 pages with content of page 1. Here my code for fixed document. lstBitMap is a list of 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);
}

来源:https://stackoverflow.com/questions/45137665/fixeddocument-always-print-first-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!