Beispiel #1
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.");
        }
Beispiel #2
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
        }
Beispiel #3
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
        }
Beispiel #4
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
        }