public void ReloadPreview(double scale, Thickness margin, PageOrientation pageOrientation, PaperSize paperSize) { try { FitToPage_Scale(); scale = Scale; PrintControlView.ScalePreviewPaneVisibility(false); ReloadingPreview = true; ShowWaitScreen(); var printSize = GetPrintSize(paperSize, pageOrientation); var visual = GetScaledVisual(scale); CreatePaginator(visual, printSize); var visualPaginator = ((VisualPaginator)Paginator); visualPaginator.Initialize(IsMarkPageNumbers); PagesAcross = visualPaginator.HorizontalPageCount; ApproaxNumberOfPages = MaxCopies = Paginator.PageCount; if (Scale == 1) { NumberOfPages = ApproaxNumberOfPages; } DisplayPagePreviewsAll(visualPaginator); ReloadingPreview = false; } catch (Exception ex) { } finally { WaitScreen.Hide(); } }
public void ReloadPreview(PageOrientation pageOrientation, PaperSize currentPaper) { ReloadingPreview = true; if (FullScreenPrintWindow != null) { WaitScreen.Show("Loading Preview"); } if (PageOrientation == PageOrientation.Portrait) { FlowDocument.PageHeight = currentPaper.Height; FlowDocument.PageWidth = currentPaper.Width; } else { FlowDocument.PageHeight = currentPaper.Width; FlowDocument.PageWidth = currentPaper.Height; } _ms = new MemoryStream(); _pkg = Package.Open(_ms, FileMode.Create, FileAccess.ReadWrite); const string pack = "pack://temp.xps"; var oldPackage = PackageStore.GetPackage(new Uri(pack)); if (oldPackage == null) { PackageStore.AddPackage(new Uri(pack), _pkg); } else { PackageStore.RemovePackage(new Uri(pack)); PackageStore.AddPackage(new Uri(pack), _pkg); } _xpsDocument = new XpsDocument(_pkg, CompressionOption.SuperFast, pack); var xpsWriter = XpsDocument.CreateXpsDocumentWriter(_xpsDocument); var documentPaginator = ((IDocumentPaginatorSource)FlowDocument).DocumentPaginator; xpsWriter.Write(documentPaginator); Paginator = documentPaginator; MaxCopies = NumberOfPages = ApproaxNumberOfPages = Paginator.PageCount; PagesAcross = 2; DisplayPagePreviewsAll(documentPaginator); WaitScreen.Hide(); ReloadingPreview = false; }