Ejemplo n.º 1
0
        /// <summary>
        /// Occurs when the Print button is clicked
        /// </summary>
        /// <param name="item">The item that has been clicked</param>
        protected virtual void OnPrintClick(ToolStripButton item)
        {
            if (PdfViewer.Document.FormFill != null)
            {
                PdfViewer.Document.FormFill.ForceToKillFocus();
            }

            //Show standard print dialog
            var printDoc = new PdfPrintDocument(PdfViewer.Document);
            var dlg      = new PrintDialog();

            dlg.AllowCurrentPage = true;
            dlg.AllowSomePages   = true;
            dlg.UseEXDialog      = true;
            dlg.Document         = printDoc;
            OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc));
            ShowPrintDialogDelegate showprintdialog = ShowPrintDialog;

            this.BeginInvoke(showprintdialog, dlg);
            //this.BeginInvoke(new Action(() =>
            //{
            //	if (dlg.ShowDialog() == DialogResult.OK)
            //	{
            //		PrintController printController = new StandardPrintController();
            //		printDoc.PrintController = printController;
            //		printDoc.Print();
            //	}
            //}));
        }
Ejemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////
        // Create print example
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // create default font for printing
            DefaultFont = new Font("Arial", 10.0F, FontStyle.Regular);

            // start page number
            PageNo = 1;

            // create PrintPdfDocument
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution = 300.0;
            ImageControl.SaveAs     = SaveImageAs.BWImage;
            PdfPrintDocument Print = new PdfPrintDocument(Document, ImageControl);

            // the method that will print one page at a time to PrintDocument
            Print.PrintPage += PrintPage;

            // set margins
            Print.SetMargins(1.0, 1.0, 1.0, 1.0);

            // crop the page image result to reduce PDF file size
            Print.PageCropRect = new RectangleF(0.95F, 0.95F, 6.6F, 9.1F);

            // initiate the printing process (calling the PrintPage method)
            // after the document is printed, add each page an an image to PDF file.
            Print.AddPagesToPdfDocument();

            // dispose of the PrintDocument object
            Print.Dispose();

            // create the PDF file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Occurs when the Print button is clicked
        /// </summary>
        /// <param name="item">The item that has been clicked</param>
        public virtual void OnPrintClick(ToolStripButton item)
        {
            if (PdfViewer.Document.FormFill != null)
            {
                PdfViewer.Document.FormFill.ForceToKillFocus();
            }

            //Show standard print dialog
            var printDoc = new PdfPrintDocument(PdfViewer.Document);
            var dlg      = new PrintDialog();

            dlg.AllowCurrentPage = true;
            dlg.AllowSomePages   = true;
            dlg.UseEXDialog      = true;
            dlg.Document         = printDoc;

            OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc));
            ShowPrintDialogDelegate showprintdialog = ShowPrintDialog;

            //Initialize a new thread for print dialog
            Thread thread3 = new Thread(() => {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.Focus();
                        this.BringToFront();
                        Application.Exit();
                        dlg.Document.Print();
                        this.DestroyHandle();
                    }
                    catch (Win32Exception)
                    {
                        //Printing was canceled
                    }
                }
            });

            thread3.SetApartmentState(ApartmentState.STA);
            thread3.Start();
            thread3.Join();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Occurs when the Print button is clicked
        /// </summary>
        /// <param name="item">The item that has been clicked</param>
        protected virtual void OnPrintClick(Button item)
        {
            if (PdfViewer.Document.FormFill != null)
            {
                PdfViewer.Document.FormFill.ForceToKillFocus();
            }

            //Show standard print dialog
            var printDoc = new PdfPrintDocument(PdfViewer.Document);
            var dlg      = new System.Windows.Forms.PrintDialog();

            dlg.AllowCurrentPage = true;
            dlg.AllowSomePages   = true;
            dlg.UseEXDialog      = true;
            dlg.Document         = printDoc;
            OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc));
            ShowPrintDialogDelegate showprintdialog = ShowPrintDialog;

            Dispatcher.BeginInvoke(showprintdialog, dlg);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Occurs when the Print button is clicked
		/// </summary>
		/// <param name="item">The item that has been clicked</param>
		protected virtual void OnPrintClick(Button item)
		{
			if (PdfViewer.Document.FormFill != null)
				PdfViewer.Document.FormFill.ForceToKillFocus();

			//Show standard print dialog
			var printDoc = new PdfPrintDocument(PdfViewer.Document);
			var dlg = new System.Windows.Forms.PrintDialog();
			dlg.AllowCurrentPage = true;
			dlg.AllowSomePages = true;
			dlg.UseEXDialog = true;
			dlg.Document = printDoc;
			OnPdfPrinDocumentCreaded(new EventArgs<PdfPrintDocument>(printDoc));
			ShowPrintDialogDelegate showprintdialog = ShowPrintDialog;
			Dispatcher.BeginInvoke(showprintdialog, dlg);
		}