问题
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