예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (Library lib = new Library())
                {
                    using (Document doc = new Document(textBox1.Text))
                    {
                        using (PrintUserParams userParams = new PrintUserParams())
                        {
                            userParams.NCopies = 1;

                            if (userParams.PosePrintDialog(doc))
                            {
                                userParams.PrintParams.ShrinkToFit = true;
                                userParams.ShrinkToFit             = userParams.PrintParams.ShrinkToFit;
                                userParams.PaperHeight             = PrintUserParams.UseMediaBox;
                                userParams.PaperWidth = PrintUserParams.UseMediaBox;

                                // If you un-comment the file path (binding) below, PDFL will print via the platform print driver to disk.
                                // The type of file produced when doing so (e.g., PS, PCL, PCLXL) depends upon the type of printer/driver.
                                //userParams.OutFileName = String.Format("{0}\\{1}.prn", finfo.Directory.FullName, System.IO.Path.GetFileNameWithoutExtension(finfo.FullName));

                                doc.Print(userParams, null, null);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception when printing...{0}{1}", Environment.NewLine, ex.Message);
            }
        }
예제 #2
0
        public static void PrintOnePDF(FileInfo finfo, SamplePrintCancel cancel, SamplePrintProgress progress)
        {
            try
            {
                progress.PrintingStarted = false;   // Used to keep the Print Progress form hidden until printing begins

                //
                // This implements the core prep/actions related to printing (from DLE)
                // In order to support GUI refresh they MUST occur on a background thread.
                // Notifications related to Cancel and Print Progress all occur via callback, elsewhere.
                //

                using (Library lib = new Library())
                    using (Document doc = new Document(finfo.FullName))
                    {
                        using (PrintUserParams userParams = new PrintUserParams())
                        {
                            userParams.NCopies = 1;

                            if (userParams.PosePrintDialog(doc))
                            {
                                userParams.PrintParams.ShrinkToFit = true;
                                userParams.ShrinkToFit             = userParams.PrintParams.ShrinkToFit;
                                userParams.PaperHeight             = PrintUserParams.UseMediaBox;
                                userParams.PaperWidth = PrintUserParams.UseMediaBox;

                                // If you un-comment the file path (binding) below, DLE will print via the platform print driver to disk.
                                // The type of file produced when doing so (e.g., PS, PCL, PCLXL) depends upon the type of printer/driver.
                                //userParams.OutFileName = String.Format("{0}\\{1}.prn", finfo.Directory.FullName, System.IO.Path.GetFileNameWithoutExtension(finfo.FullName));

                                progress.NumPages        = userParams.EndPage + 1; // important! (establishes the range of the page progress bar)
                                progress.PrintingStarted = true;                   // Just before print start, set this (so that the Print Progress form will show)

                                doc.Print(userParams, cancel, progress);           // Long running activity (cancel and progress will update via callback, elsewhere)
                            }
                        }
                    }
            }
            catch (Exception ex)
            {   // Some PDFs won't print (for various reasons). All code should be written to expect failure (never assume success by default).
                Console.WriteLine("Exception when printing...{0}{1}", Environment.NewLine, ex.Message);
            }
            finally
            {   // Tell the Print Progress form we're done...
                progress.ReportProgressDone();
            }
        }
        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (PDFDoc == null)
            {
                MessageBox.Show("Please open a PDF document first before printing");
                return;
            }

            // Get some parameters
            PrintUserParams userParams = new PrintUserParams();
            // These are the "other" print parameters that hang off the user parameters.
            PrintParams printParams = userParams.PrintParams;

            // Print to a printer
            // For a list of the current print drivers available under WinNT, look at:
            // HKEY_CURRENT_USER\Software\Microsoft\WindowsNT\CurrentVersion\Devices
            // Or use the default printer

            if (userParams.PosePrintDialog(PDFDoc) == true)
            {
                PDFDoc.Print(userParams);
            }
        }