private void Print_Click(object sender, RoutedEventArgs e) { PrintDialog prnt = new PrintDialog(); prnt.UserPageRangeEnabled = true; prnt.MaxPage = (uint)data.pages.Count; prnt.MinPage = 1; if (prnt.ShowDialog() == true) { if (CB_OutPutColor.SelectedIndex > 0) { prnt.PrintTicket.OutputColor = (OutputColor)(CB_OutPutColor.SelectedIndex); } if (CB_Orientation.SelectedIndex > 0) { prnt.PrintTicket.PageOrientation = (PageOrientation)(CB_Orientation.SelectedIndex); } FixedDocument document = new FixedDocument(); PrintCapabilities capabilities = prnt.PrintQueue.GetPrintCapabilities(prnt.PrintTicket); Size visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); Size Margins = new Size(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight); if (SB_Fit.IsChecked()) { document.DocumentPaginator.PageSize = new Size(prnt.PrintableAreaWidth, prnt.PrintableAreaHeight); } else { document.DocumentPaginator.PageSize = new Size(data.CanvasW, data.CanvasH); } Debug.WriteLine("Page Range: From: " + prnt.PageRange.PageFrom + " To: " + prnt.PageRange.PageTo); if (prnt.PageRange.PageTo < 1) { for (int i = 0; i < data.pages.Count; i++) { PrintAddPage(i, document, visibleSize, Margins); } } else { for (int i = (prnt.PageRange.PageFrom - 1); i < prnt.PageRange.PageTo; i++) { PrintAddPage(i, document, visibleSize, Margins); } } prnt.PrintDocument(document.DocumentPaginator, "Good Teacher"); } }
private void PrintAddPage(int i, FixedDocument document, Size sizeContent, Size margins) { Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i); CanvasSaveLoad.ToPresentationMode(can); CanvasSaveLoad.SimulateCanvas(can); can.UpdateLayout(); Size size = new Size(); can.Measure(size); can.Arrange(new Rect(size)); ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can)); Image image = new Image(); if (SB_Fit.IsChecked()) { image.Width = sizeContent.Width; image.Height = sizeContent.Height; } else { image.Width = data.CanvasW; image.Height = data.CanvasH; } image.Stretch = Stretch.Uniform; image.Source = bs; FixedPage page = new FixedPage(); page.Width = document.DocumentPaginator.PageSize.Width; page.Height = document.DocumentPaginator.PageSize.Width; if (SB_Fit.IsChecked()) { page.Margin = new Thickness(margins.Width, margins.Height, 0, 0); } page.Children.Clear(); page.Children.Add(image); PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(page); document.Pages.Add(pageContent); }