コード例 #1
0
 private void GeneratePreview(FrameworkElement printElement, PrinterOrientation orientation)
 {
     if (printDoc != null)
     {
         printDoc.Close();
     }
     printDoc           = VisualToXpsDocument(printElement, orientation);
     docViewer.Document = printDoc.GetFixedDocumentSequence();
 }
コード例 #2
0
 public PrintPreviewWindow(Image image = null, PrinterOrientation orientation = PrinterOrientation.Portrait)
 {
     InitializeComponent();
     printElement             = image;
     printerOrientation       = orientation;
     targetPrinterOrientation = orientation;
     if (image == null)
     {
         int width  = (int)Math.Max(printDialog.PrintableAreaHeight, printDialog.PrintableAreaWidth);
         int height = (int)Math.Min(printDialog.PrintableAreaHeight, printDialog.PrintableAreaWidth);
         image = GisEditor.ActiveMap.GetPrintingImage(width, height);
     }
     GeneratePreview(image, orientation);
     docViewer.FitToMaxPagesAcross();
 }
コード例 #3
0
        private XpsDocument VisualToXpsDocument(FrameworkElement printContent, PrinterOrientation orientation)
        {
            if (File.Exists(printPreviewTempPathFileName))
            {
                File.Delete(printPreviewTempPathFileName);
            }
            XpsDocument xpsDocument = new XpsDocument(printPreviewTempPathFileName, FileAccess.ReadWrite);

            FixedPage page = new FixedPage();

            if (printContent.Parent != null && printContent.Parent is FixedPage)
            {
                ((FixedPage)printContent.Parent).Children.Remove(printContent);
            }
            page.Children.Add(printContent);

            if (this.printerOrientation == orientation)
            {
                page.Width  = printContent.Width;
                page.Height = printContent.Height;
            }
            else
            {
                page.Width  = printContent.Height;
                page.Height = printContent.Width;
            }

            PageContent pageContent = new PageContent();

            ((IAddChild)pageContent).AddChild(page);
            FixedDocument doc = new FixedDocument();

            doc.Pages.Add(pageContent);
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

            writer.Write(doc);
            return(xpsDocument);
        }
コード例 #4
0
 private void Portrait_Click(object sender, RoutedEventArgs e)
 {
     targetPrinterOrientation = PrinterOrientation.Portrait;
     GeneratePreview(printElement, PrinterOrientation.Portrait);
 }
コード例 #5
0
 private void Landscape_Click(object sender, RoutedEventArgs e)
 {
     targetPrinterOrientation = PrinterOrientation.Landscape;
     GeneratePreview(printElement, PrinterOrientation.Landscape);
 }