Exemplo n.º 1
0
        /// <summary>
        /// A utility method to print preview and print an Aspose.Words document.
        /// </summary>
        internal static void Execute(Document document)
        {
            // This operation can take some time (for the first page) so we set the Cursor to WaitCursor.
            Cursor cursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            PrintPreviewDialog previewDlg = new PrintPreviewDialog();

            // Initialize the Print Dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog();
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings = new PrinterSettings();
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = document.PageCount;
            printDlg.PrinterSettings.FromPage = 1;
            printDlg.PrinterSettings.ToPage = document.PageCount;

            // Restore cursor.
            Cursor.Current = cursor;

            // Interesting, but PrintDialog will not show and will always return cancel
            // if you run this application in 64-bit mode.
            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
                return;

            // Create the Aspose.Words' implementation of the .NET print document
            // and pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(document);
            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;

            // Pass the Aspose.Words' print document to the .NET Print Preview dialog.
            previewDlg.Document = awPrintDoc;

            previewDlg.ShowDialog();
        }
Exemplo n.º 2
0
        public static void CachePrinterSettings(string dataDir)
        {
            // ExStart:CachePrinterSettings
            //Load the Word document
            Document doc = new Document(dataDir + "TestFile.doc");

            // Build layout.
            doc.UpdatePageLayout();

            // Create settings, setup printing.
            PrinterSettings settings = new PrinterSettings();

            settings.PrinterName = "Microsoft XPS Document Writer";

            // Create AsposeWordsPrintDocument  and cache settings.
            AsposeWordsPrintDocument printDocument = new AsposeWordsPrintDocument(doc);

            printDocument.PrinterSettings = settings;
            printDocument.CachePrinterSettings();

            printDocument.Print();

            // ExEnd:CachePrinterSettings
            Console.WriteLine("\nDocument is printed successfully.");
        }
Exemplo n.º 3
0
        public void CachePrinterSettings()
        {
            //ExStart:CachePrinterSettings
            Document doc = new Document(MyDir + "Rendering.docx");

            doc.UpdatePageLayout();

            PrinterSettings settings = new PrinterSettings {
                PrinterName = "Microsoft XPS Document Writer"
            };

            // The standard print controller comes with no UI.
            PrintController standardPrintController = new StandardPrintController();

            AsposeWordsPrintDocument printDocument = new AsposeWordsPrintDocument(doc)
            {
                PrinterSettings = settings,
                PrintController = standardPrintController
            };

            printDocument.CachePrinterSettings();

            printDocument.Print();
            //ExEnd:CachePrinterSettings
        }
Exemplo n.º 4
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Open the document.
            Document doc = new Document(dataDir + "TestFile.doc");

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Creation
            //ExSummary:Creates the print dialog.
            PrintDialog printDlg = new PrintDialog();

            // Initialize the print dialog with the number of pages in the document.
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage    = 1;
            printDlg.PrinterSettings.ToPage      = doc.PageCount;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Check_Result
            //ExSummary:Check if the user accepted the print settings and proceed to preview the document.
            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
            {
                return;
            }
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_AsposeWordsPrintDocument_Creation
            //ExSummary:Creates a special Aspose.Words implementation of the .NET PrintDocument class.
            // Pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);

            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_ActivePrintPreviewDialog_Creation
            //ExSummary:Creates an overridden version of the .NET Print Preview dialog to preview the document.
            ActivePrintPreviewDialog previewDlg = new ActivePrintPreviewDialog();

            // Pass the Aspose.Words print document to the Print Preview dialog.
            previewDlg.Document = awPrintDoc;
            // Specify additional parameters of the Print Preview dialog.
            previewDlg.ShowInTaskbar            = true;
            previewDlg.MinimizeBox              = true;
            previewDlg.PrintPreviewControl.Zoom = 1;
            previewDlg.Document.DocumentName    = "TestName.doc";
            previewDlg.WindowState              = FormWindowState.Maximized;
            // Show the appropriately configured Print Preview dialog.
            previewDlg.ShowDialog();
            //ExEnd
        }
Exemplo n.º 5
0
 public void PrintWordDocument(byte[] fileContents, string documentName)
 {
     using (MemoryStream ms = new MemoryStream(fileContents))
     {
         var doc = new Document(ms);
         var printDocument = new AsposeWordsPrintDocument(doc);
         printDocument.DocumentName = documentName;
         printDocument.Print();
     }
 }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); ;

            // Open the document.
            Document doc = new Document(dataDir + "TestFile.doc");

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Creation
            //ExSummary:Creates the print dialog.
            PrintDialog printDlg = new PrintDialog();
            // Initialize the print dialog with the number of pages in the document.
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage = 1;
            printDlg.PrinterSettings.ToPage = doc.PageCount;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Check_Result
            //ExSummary:Check if the user accepted the print settings and proceed to preview the document.
            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
                return;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_AsposeWordsPrintDocument_Creation
            //ExSummary:Creates a special Aspose.Words implementation of the .NET PrintDocument class.
            // Pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_ActivePrintPreviewDialog_Creation
            //ExSummary:Creates an overridden version of the .NET Print Preview dialog to preview the document.
            ActivePrintPreviewDialog previewDlg = new ActivePrintPreviewDialog();

            // Pass the Aspose.Words print document to the Print Preview dialog.
            previewDlg.Document = awPrintDoc;
            // Specify additional parameters of the Print Preview dialog.
            previewDlg.ShowInTaskbar = true;
            previewDlg.MinimizeBox = true;
            previewDlg.PrintPreviewControl.Zoom = 1;
            previewDlg.Document.DocumentName = "TestName.doc";
            previewDlg.WindowState = FormWindowState.Maximized;
            // Show the appropriately configured Print Preview dialog.
            previewDlg.ShowDialog();
            //ExEnd
        }
        public static void Run()
        {
            // ExStart:PrintPreviewSettingsDialog
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_RenderingAndPrinting();
            Document doc     = new Document(dataDir + "TestFile.doc");

            PrintDialog printDlg = new PrintDialog();

            // Initialize the print dialog with the number of pages in the document.
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage    = 1;
            printDlg.PrinterSettings.ToPage      = doc.PageCount;

            // Сheck if the user accepted the print settings and whether to proceed to document preview.
            if (printDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Create a special Aspose.Words implementation of the .NET PrintDocument class.
            // Pass the printer settings from the print dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);

            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;

            // Initialize the print preview dialog.
            PrintPreviewDialog previewDlg = new PrintPreviewDialog();

            // Pass the Aspose.Words print document to the print preview dialog.
            previewDlg.Document = awPrintDoc;

            // Specify additional parameters of the print preview dialog.
            previewDlg.ShowInTaskbar            = true;
            previewDlg.MinimizeBox              = true;
            previewDlg.PrintPreviewControl.Zoom = 1;
            previewDlg.Document.DocumentName    = doc.OriginalFileName;
            previewDlg.WindowState              = FormWindowState.Maximized;

            // Occur whenever the print preview dialog is first displayed.
            previewDlg.Shown += PreviewDlg_Shown;

            // Show the appropriately configured print preview dialog.
            previewDlg.ShowDialog();
            // ExEnd:PrintPreviewSettingsDialog
        }
Exemplo n.º 8
0
        public void Print()
        {
            Document doc = new Document(MyDir + "Rendering.docx");

            //ExStart:PrintDialog
            // Initialize the print dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog
            {
                AllowSomePages  = true,
                PrinterSettings =
                {
                    MinimumPage = 1, MaximumPage = doc.PageCount, FromPage = 1, ToPage = doc.PageCount
                }
            };

            //ExEnd:PrintDialog

            //ExStart:ShowDialog
            if (printDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            //ExEnd:ShowDialog

            //ExStart:AsposeWordsPrintDocument
            // Pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc)
            {
                PrinterSettings = printDlg.PrinterSettings
            };
            //ExEnd:AsposeWordsPrintDocument

            //ExStart:ActivePrintPreviewDialog
            // Pass the Aspose.Words print document to the Print Preview dialog.
            ActivePrintPreviewDialog previewDlg = new ActivePrintPreviewDialog
            {
                Document = awPrintDoc, ShowInTaskbar = true, MinimizeBox = true
            };

            // Specify additional parameters of the Print Preview dialog.
            previewDlg.PrintPreviewControl.Zoom = 1;
            previewDlg.Document.DocumentName    = "PrintDocuments.Print.docx";
            previewDlg.WindowState = FormWindowState.Maximized;
            previewDlg.ShowDialog(); // Show the appropriately configured Print Preview dialog.
            //ExEnd:ActivePrintPreviewDialog
        }
Exemplo n.º 9
0
        public void PreviewAndPrint()
        {
            //ExStart
            //ExFor:AsposeWordsPrintDocument.#ctor(Document)
            //ExFor:AsposeWordsPrintDocument.CachePrinterSettings
            //ExSummary:Shows how to select a page range and a printer to print the document with, and then bring up a print preview.
            Document doc = new Document(MyDir + "Rendering.docx");

            PrintPreviewDialog previewDlg = new PrintPreviewDialog();

            // Call the "Show" method to get the print preview form to show on top.
            previewDlg.Show();

            // Initialize the Print Dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog();

            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage    = 1;
            printDlg.PrinterSettings.ToPage      = doc.PageCount;

            if (printDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Create the "Aspose.Words" implementation of the .NET print document,
            // and then pass the printer settings from the dialog.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);

            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;

            // Use the "CachePrinterSettings" method to reduce time of the first call of the "Print" method.
            awPrintDoc.CachePrinterSettings();

            // Call the "Hide", and then the "InvalidatePreview" methods to get the print preview to show on top.
            previewDlg.Hide();
            previewDlg.PrintPreviewControl.InvalidatePreview();

            // Pass the "Aspose.Words" print document to the .NET Print Preview dialog.
            previewDlg.Document = awPrintDoc;

            previewDlg.ShowDialog();
            //ExEnd
        }
Exemplo n.º 10
0
        public void PreviewAndPrint()
        {
            //ExStart
            //ExFor:AsposeWordsPrintDocument
            //ExSummary:Shows the Print dialog that allows selecting the printer and page range to print with. Then brings up the print preview from which you can preview the document and choose to print or close.
            Document doc = new Document(MyDir + "Rendering.doc");

            PrintPreviewDialog previewDlg = new PrintPreviewDialog();

            // Show non-modal first is a hack for the print preview form to show on top.
            previewDlg.Show();

            // Initialize the Print Dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog();

            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage    = 1;
            printDlg.PrinterSettings.ToPage      = doc.PageCount;

            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
            {
                return;
            }

            // Create the Aspose.Words' implementation of the .NET print document
            // and pass the printer settings from the dialog to the print document.
            // Use 'CachePrinterSettings' to reduce time of first call of Print() method.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);

            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
            awPrintDoc.CachePrinterSettings();

            // Hide and invalidate preview is a hack for print preview to show on top.
            previewDlg.Hide();
            previewDlg.PrintPreviewControl.InvalidatePreview();

            // Pass the Aspose.Words' print document to the .NET Print Preview dialog.
            previewDlg.Document = awPrintDoc;

            previewDlg.ShowDialog();
            //ExEnd
        }
        public static void Run()
        {
            // ExStart:PrintProgressDialog
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 
            // Load the documents which store the shapes we want to render.
            Document doc = new Document(dataDir + "TestFile RenderShape.doc");
            // Obtain the settings of the default printer
            System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();

            // The standard print controller comes with no UI
            System.Drawing.Printing.PrintController standardPrintController = new System.Drawing.Printing.StandardPrintController();

            // Print the document using the custom print controller
            AsposeWordsPrintDocument prntDoc = new AsposeWordsPrintDocument(doc);
            prntDoc.PrinterSettings = settings;
            prntDoc.PrintController = standardPrintController;
            prntDoc.Print();            
            // ExEnd:PrintProgressDialog
        }
Exemplo n.º 12
0
        /// <summary>
        /// A utility method to print preview and print an Aspose.Words document.
        /// </summary>
        internal static void Execute(Document document)
        {
            // This operation can take some time (for the first page) so we set the Cursor to WaitCursor.
            Cursor cursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            PrintPreviewDialog previewDlg = new PrintPreviewDialog();

            // Initialize the Print Dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog
            {
                AllowSomePages  = true,
                PrinterSettings = new PrinterSettings
                {
                    MinimumPage = 1, MaximumPage = document.PageCount, FromPage = 1, ToPage = document.PageCount
                }
            };

            // Restore cursor.
            Cursor.Current = cursor;

            // Interesting, but PrintDialog will not show and will always return cancel
            // If you run this application in 64-bit mode.
            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
            {
                return;
            }

            // Create the Aspose.Words' implementation of the .NET print document
            // And pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(document)
            {
                PrinterSettings = printDlg.PrinterSettings
            };

            // Pass the Aspose.Words' print document to the .NET Print Preview dialog.
            previewDlg.Document = awPrintDoc;

            previewDlg.ShowDialog();
        }
Exemplo n.º 13
0
        public static void Run()
        {
            // ExStart:PrintProgressDialog
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();
            // Load the documents which store the shapes we want to render.
            Document doc = new Document(dataDir + "TestFile RenderShape.doc");

            // Obtain the settings of the default printer
            System.Drawing.Printing.PrinterSettings settings = new System.Drawing.Printing.PrinterSettings();

            // The standard print controller comes with no UI
            System.Drawing.Printing.PrintController standardPrintController = new System.Drawing.Printing.StandardPrintController();

            // Print the document using the custom print controller
            AsposeWordsPrintDocument prntDoc = new AsposeWordsPrintDocument(doc);

            prntDoc.PrinterSettings = settings;
            prntDoc.PrintController = standardPrintController;
            prntDoc.Print();
            // ExEnd:PrintProgressDialog
        }
        public void PreviewAndPrint()
        {
            //ExStart
            //ExFor:AsposeWordsPrintDocument
            //ExSummary:Shows the Print dialog that allows selecting the printer and page range to print with. Then brings up the print preview from which you can preview the document and choose to print or close.
            Document doc = new Document(MyDir + "Rendering.doc");

            PrintPreviewDialog previewDlg = new PrintPreviewDialog();
            // Show non-modal first is a hack for the print preview form to show on top.
            previewDlg.Show();

            // Initialize the Print Dialog with the number of pages in the document.
            PrintDialog printDlg = new PrintDialog();
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage = 1;
            printDlg.PrinterSettings.ToPage = doc.PageCount;

            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
                return;

            // Create the Aspose.Words' implementation of the .NET print document
            // and pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;

            // Hide and invalidate preview is a hack for print preview to show on top.
            previewDlg.Hide();
            previewDlg.PrintPreviewControl.InvalidatePreview();

            // Pass the Aspose.Words' print document to the .NET Print Preview dialog.
            previewDlg.Document = awPrintDoc;

            previewDlg.ShowDialog();
            //ExEnd
        }
Exemplo n.º 15
0
        public static void Main(string[] args)
        {
            // Sample infrastructure.
            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
            string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;

            // Open the document.
            Document doc = new Document(dataDir + "TestFile.doc");

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Creation
            //ExSummary:Creates the print dialog.
            PrintDialog printDlg = new PrintDialog();
            // Initialize the print dialog with the number of pages in the document.
            printDlg.AllowSomePages = true;
            printDlg.PrinterSettings.MinimumPage = 1;
            printDlg.PrinterSettings.MaximumPage = doc.PageCount;
            printDlg.PrinterSettings.FromPage = 1;
            printDlg.PrinterSettings.ToPage = doc.PageCount;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_PrintDialog_Check_Result
            //ExSummary:Check if the user accepted the print settings and proceed to preview the document.
            if (!printDlg.ShowDialog().Equals(DialogResult.OK))
                return;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_AsposeWordsPrintDocument_Creation
            //ExSummary:Creates a special Aspose.Words implementation of the .NET PrintDocument class.
            // Pass the printer settings from the dialog to the print document.
            AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
            awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
            //ExEnd

            //ExStart
            //ExId:DocumentPreviewAndPrint_ActivePrintPreviewDialog_Creation
            //ExSummary:Creates an overridden version of the .NET Print Preview dialog to preview the document.
            ActivePrintPreviewDialog previewDlg = new ActivePrintPreviewDialog();

            // Pass the Aspose.Words print document to the Print Preview dialog.
            previewDlg.Document = awPrintDoc;
            // Specify additional parameters of the Print Preview dialog.
            previewDlg.ShowInTaskbar = true;
            previewDlg.MinimizeBox = true;
            previewDlg.PrintPreviewControl.Zoom = 1;
            previewDlg.Document.DocumentName = "TestName.doc";
            previewDlg.WindowState = FormWindowState.Maximized;
            // Show the appropriately configured Print Preview dialog.
            previewDlg.ShowDialog();
            //ExEnd
        }