예제 #1
0
        //-----------------------------------------------------------
        #region ** PrintDocument event handlers

        void _doc_PrintPage(object sender, PrintPageEventArgs e)
        {
            var pages = _previewController.GetPreviewPageInfo();

            while (_pageCount < pages.Length - 1)
            {
                DrawPage(pages, _pageCount++);
            }
            if (e.Cancel)
            {
                _cancel = true;
            }
        }
예제 #2
0
        void SyncPageImages(bool lastPageReady)
        {
            PreviewPrintController pv = (PreviewPrintController)_doc.PrintController;

            if (pv != null)
            {
                PreviewPageInfo[] pageInfo = pv.GetPreviewPageInfo();
                int count = lastPageReady ? pageInfo.Length : pageInfo.Length - 1;
                for (int i = _img.Count; i < count; i++)
                {
                    Image img = pageInfo[i].Image;
                    _img.Add(img);

                    OnPageCountChanged(EventArgs.Empty);

                    if (StartPage < 0)
                    {
                        StartPage = 0;
                    }
                    if (i == StartPage || i == StartPage + 1)
                    {
                        Refresh();
                    }
                    Application.DoEvents();
                }
            }
        }
        private void ComputePreview()
        {
            int startPage = this.StartPage;

            if (this.document == null)
            {
                this.pageInfo = new PreviewPageInfo[0];
            }
            else
            {
                System.Windows.Forms.IntSecurity.SafePrinting.Demand();
                PrintController        printController      = this.document.PrintController;
                PreviewPrintController underlyingController = new PreviewPrintController {
                    UseAntiAlias = this.UseAntiAlias
                };
                this.document.PrintController = new PrintControllerWithStatusDialog(underlyingController, System.Windows.Forms.SR.GetString("PrintControllerWithStatusDialog_DialogTitlePreview"));
                this.document.Print();
                this.pageInfo = underlyingController.GetPreviewPageInfo();
                this.document.PrintController = printController;
            }
            if (startPage != this.StartPage)
            {
                this.OnStartPageChanged(EventArgs.Empty);
            }
        }
예제 #4
0
        private void drawPreviewPage()
        {
            if (rezimRada == RezimRada.MyPreviewDraw)
            {
                izvestaj.TimeOfPrint = DateTime.Now;
                bitmapGraphics.Clear(Color.White);
                drawPage(bitmapGraphics, previewPage);
                pictureBox1.Image = bitmap;
                return;
            }
            else if (rezimRada == RezimRada.PageSizeTooSmall)
            {
                bitmapGraphics.Clear(Color.White);
                pictureBox1.Image = bitmap;
                return;
            }

            PrintController        oldControler  = printDocument1.PrintController;
            PreviewPrintController prevControler = new PreviewPrintController();

            printDocument1.PrintController = prevControler;
            page            = previewPage;
            lastPageToPrint = previewPage;
            printDocument1.Print();
            printDocument1.PrintController = oldControler;

            PreviewPageInfo pageInfo = prevControler.GetPreviewPageInfo()[0];

            // PhysicalSize is in 0.01 inch
            pictureBox1.ClientSize = pageToScreen(new SizeF(
                                                      pageInfo.PhysicalSize.Width / 100f,
                                                      pageInfo.PhysicalSize.Height / 100f));
            pictureBox1.Image = pageInfo.Image; // Metafile
        }
        private void GeneratePreview()
        {
            m_currentPreviewPage = null;

            PrintDocument document = this.PrintDocument;

            if (document == null)
            {
                return;
            }

            PrintController oldController = document.PrintController;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                PreviewPrintController controller = new PreviewPrintController();

                document.PrintController = controller;
                document.PrintPage      += new PrintPageEventHandler(document_PrintPage);
                document.Print();
                document.PrintPage -= new PrintPageEventHandler(document_PrintPage);

                PreviewPageInfo[] pages = controller.GetPreviewPageInfo();

                m_currentPreviewPage = pages[0];
            }
            finally
            {
                document.PrintController = oldController;
                Cursor.Current           = Cursors.Default;
            }
        }
예제 #6
0
        ///<summary>"Prints" the document to memory</summary>
        private void ComputePreview()
        {
            int oldStart = StartPage;

            if (Document == null)
            {
                _arrayPageInfo = new PreviewPageInfo[0];
            }
            else
            {
                _permSafePrinting.Demand();                //Mimics original line of: IntSecurity.SafePrinting.Demand();
                PrintController        oldController     = Document.PrintController;
                PreviewPrintController previewController = new PreviewPrintController();
                previewController.UseAntiAlias = UseAntiAlias;
                if (ODBuild.IsWeb())
                {
                    Document.PrintController = previewController;
                }
                else
                {
                    //.Net uses PrintControllerWithStatusDialog which breaks the web.
                    //Document.PrintController=new PrintControllerWithStatusDialog(previewController,"DIALOG TEXT");
                    throw new ODException("You can not use the ODWebPrintPreviewControl when not using WEB");
                }
                // Want to make sure we've reverted any security asserts before we call Print -- that calls into user code
                Document.Print();
                _arrayPageInfo = previewController.GetPreviewPageInfo();
                //Debug.Assert(pageInfo != null,"ReviewPrintController did not give us preview info");
                Document.PrintController = oldController;
            }
            if (oldStart != StartPage)
            {
                OnStartPageChanged(EventArgs.Empty);
            }
        }
예제 #7
0
        // "Prints" the document to memory
        private void ComputePreview()
        {
            int oldStart = StartPage;

            if (document == null)
            {
                pageInfo = new PreviewPageInfo[0];
            }
            else
            {
                PrintController        oldController     = document.PrintController;
                PreviewPrintController previewController = new PreviewPrintController();
                previewController.UseAntiAlias = UseAntiAlias;
                document.PrintController       = new PrintControllerWithStatusDialog(previewController,
                                                                                     string.Format(SR.PrintControllerWithStatusDialog_DialogTitlePreview));

                document.Print();
                pageInfo = previewController.GetPreviewPageInfo();
                Debug.Assert(pageInfo != null, "ReviewPrintController did not give us preview info");

                document.PrintController = oldController;
            }

            if (oldStart != StartPage)
            {
                OnStartPageChanged(EventArgs.Empty);
            }
        }
예제 #8
0
        // "Prints" the document to memory
        private void ComputePreview()
        {
            int oldStart = StartPage;

            if (document == null)
            {
                pageInfo = new PreviewPageInfo[0];
            }
            else
            {
                PrintController        oldController     = document.PrintController;
                PreviewPrintController previewController = new PreviewPrintController();
                previewController.UseAntiAlias = UseAntiAlias;
                document.PrintController       = new PrintControllerWithStatusDialog(previewController,
                                                                                     string.Format(SR.PrintControllerWithStatusDialog_DialogTitlePreview));

                // Want to make sure we've reverted any security asserts before we call Print -- that calls into user code
                document.Print();
                pageInfo = previewController.GetPreviewPageInfo();
                Debug.Assert(pageInfo != null, "ReviewPrintController did not give us preview info");

                document.PrintController = oldController;
            }

            if (oldStart != StartPage)
            {
                OnStartPageChanged(EventArgs.Empty);
            }
        }
예제 #9
0
    private void method_7(bool bool_2)
    {
        PreviewPrintController printController = (PreviewPrintController)this.printDocument_0.PrintController;

        if (printController != null)
        {
            PreviewPageInfo[] previewPageInfo = printController.GetPreviewPageInfo();
            int num = bool_2 ? previewPageInfo.Length : (previewPageInfo.Length - 1);
            for (int i = this.class15_0.Count; i < num; i++)
            {
                Image item = previewPageInfo[i].Image;
                this.class15_0.Add(item);
                this.method_5(EventArgs.Empty);
                if (this.Int32_0 < 0)
                {
                    this.Int32_0 = 0;
                }
                if ((i == this.Int32_0) || (i == (this.Int32_0 + 1)))
                {
                    this.Refresh();
                }
                Application.DoEvents();
            }
        }
    }
예제 #10
0
        bool ExportDocument()
        {
            // get pdf file name
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter = "Portable Document File (*.pdf)|*.pdf";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    // create preview document
                    PrintDocument          doc  = Editor.PrintDocument;
                    PrintController        pc   = doc.PrintController;
                    PreviewPrintController pcpv = new PreviewPrintController();
                    doc.PrintController = pcpv;
                    doc.Print();
                    doc.PrintController = pc;

                    // create pdf document
                    using (C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument())
                    {
                        // add pages to pdf document
                        bool firstPage = true;
                        foreach (PreviewPageInfo page in pcpv.GetPreviewPageInfo())
                        {
                            pdf.PageSize = new SizeF(
                                page.PhysicalSize.Width * 0.72f,
                                page.PhysicalSize.Height * 0.72f);
                            if (!firstPage)
                            {
                                pdf.NewPage();
                            }
                            pdf.DrawImage(page.Image, pdf.PageRectangle);
                            firstPage = false;
                        }

                        // save pdf file
                        try
                        {
                            pdf.Save(dlg.FileName);
                            string       msg = string.Format(Resources.ExportPdf_msg, Path.GetFileName(dlg.FileName));
                            DialogResult dr  = MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.Yes)
                            {
                                Process.Start(dlg.FileName);
                            }
                            return(true);
                        }
                        catch (Exception x)
                        {
                            string msg = x.Message;
                            MessageBox.Show(this, msg, Application.ProductName);
                            return(false);
                        }
                    }
                }
            }

            // failed
            return(false);
        }
예제 #11
0
        public override void OnEndPrint(PrintDocument document, PrintEventArgs e)
        {
            System.Diagnostics.Trace.WriteLine("ExtPrintcontroller OnEndprint");
            PreviewPrintController c = this.controller as PreviewPrintController;

            if (c != null)
            {
                PreviewPageInfo[] ppia = c.GetPreviewPageInfo();
            }
            this.controller.OnEndPrint(document, e);
        }
예제 #12
0
        public void Print(out PreviewPageInfo[] previewPageInfo_0)
        {
            PreviewPrintController controller = new PreviewPrintController
            {
                UseAntiAlias = true
            };

            this.printDocument.PrintController = controller;
            this.printDocument.Print();
            previewPageInfo_0 = controller.GetPreviewPageInfo();
        }
예제 #13
0
        //This is an example of how to use the Printcontroller to "hack" the printdocument
        //to print images. On current FlexCel versions is better to use FlexCelImageExport as shown on the DoExportUsingFlexCelImgExport or DoExportMultiPageTiff methods.
        private void DoExportUsingPrintController()
        {
            if (!HasFileOpen())
            {
                return;
            }
            if (!LoadPreferences())
            {
                return;
            }
            if (!DoSetup())
            {
                return;
            }

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

            PrintController RealController = flexCelPrintDocument1.PrintController;

            try
            {
                PreviewPrintController Controller = new PreviewPrintController();
                flexCelPrintDocument1.PrintController = Controller;

                flexCelPrintDocument1.Print();

                PreviewPageInfo[] Pages = Controller.GetPreviewPageInfo();
                System.Drawing.Imaging.ImageFormat ImgFormat = System.Drawing.Imaging.ImageFormat.Png;
                if (String.Compare(Path.GetExtension(exportImageDialog.FileName), ".jpg", true) == 0)
                {
                    ImgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                }

                for (int i = 0; i < Pages.Length; i++)
                {
                    using (Image Bmp = Pages[i].Image)
                    {
                        Bmp.Save(Path.GetDirectoryName(exportImageDialog.FileName)
                                 + Path.DirectorySeparatorChar
                                 + Path.GetFileNameWithoutExtension(exportImageDialog.FileName)
                                 + String.Format("_{0:0000}", i) +
                                 Path.GetExtension(exportImageDialog.FileName), ImgFormat);
                    }
                }
            }
            finally
            {
                flexCelPrintDocument1.PrintController = RealController;
            }
        }
예제 #14
0
        internal void GeneratePreview()
        {
            if (document == null)
            {
                return;
            }

            try {
                if (page_infos == null)
                {
                    var prevPrintController = document.PrintController;

                    if (document.PrintController == null || !(document.PrintController is PrintControllerWithStatusDialog))
                    {
                        document.PrintController = new PrintControllerWithStatusDialog(controller);
                    }
                    document.Print();
                    document.PrintController = prevPrintController;
                    page_infos = controller.GetPreviewPageInfo();
                }

                if (image_cache == null)
                {
                    image_cache = new Image[page_infos.Length];

                    if (page_infos.Length > 0)
                    {
                        image_size = ThemeEngine.Current.PrintPreviewControlGetPageSize(this);
                        // Only resize the pages if they are stored as bitmaps. The print controller
                        // could internally use scalable metafiles and they should be preserved to
                        // allow loss-less resizing.
                        for (int i = 0; i < page_infos.Length; i++)
                        {
                            if (page_infos[i].Image is Bitmap &&
                                image_size.Width >= 0 && image_size.Width < page_infos[i].Image.Width &&
                                image_size.Height >= 0 && image_size.Height < page_infos[i].Image.Height)
                            {
                                image_cache[i] = new Bitmap(image_size.Width, image_size.Height);
                                using (Graphics g = Graphics.FromImage(image_cache[i]))
                                    g.DrawImage(page_infos[i].Image, new Rectangle(new Point(0, 0), image_size), 0, 0, page_infos[i].Image.Width, page_infos[i].Image.Height, GraphicsUnit.Pixel);
                            }
                        }
                    }
                }
                UpdateScrollBars();
            }
            catch (Exception e) {
                page_infos  = new PreviewPageInfo[0];
                image_cache = new Image[0];
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        internal void GeneratePreview()
        {
            if (document == null)
            {
                return;
            }

            try {
                if (page_infos == null)
                {
                    PrintController oldController = document.PrintController;
                    if (document.PrintController == null || !(document.PrintController is PrintControllerWithStatusDialog))
                    {
                        document.PrintController = new PrintControllerWithStatusDialog(controller);
                    }
                    document.Print();
                    page_infos = controller.GetPreviewPageInfo();
                    document.PrintController = oldController;
                }

                if (image_cache == null)
                {
                    image_cache = new Image[page_infos.Length];

                    if (page_infos.Length > 0)
                    {
                        image_size = ThemeEngine.Current.PrintPreviewControlGetPageSize(this);
                        // Keep the original preview data since they could be Metafile and not a Bitmap

                        /*if (image_size.Width >= 0 && image_size.Width < page_infos[0].Image.Width
                         *  && image_size.Height >= 0 && image_size.Height < page_infos[0].Image.Height) {
                         *
                         *      for (int i = 0; i < page_infos.Length; i ++) {
                         *              image_cache[i] = new Bitmap (image_size.Width, image_size.Height);
                         *              Graphics g = Graphics.FromImage (image_cache[i]);
                         *              g.DrawImage (page_infos[i].Image, new Rectangle (new Point (0, 0), image_size), 0, 0, page_infos[i].Image.Width, page_infos[i].Image.Height, GraphicsUnit.Pixel);
                         *              g.Dispose ();
                         *      }
                         * }*/
                    }
                }
                UpdateScrollBars();
            }
            catch (Exception e) {
                page_infos  = new PreviewPageInfo[0];
                image_cache = new Image[0];
                //MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #16
0
        void ComputePreview()
        {
            if (Document == null)
            {
                Pages = new PreviewPageInfo[0];
            }
            else
            {
                //IntSecurity.SafePrinting.Demand();
                var printController      = Document.PrintController;
                var underlyingController = new PreviewPrintController();
                underlyingController.UseAntiAlias = UseAntiAlias;
                Document.PrintController          = new PrintControllerWithStatusDialog(underlyingController, "PrintControllerWithStatusDialog_DialogTitlePreview");
                Document.Print();
                Pages = underlyingController.GetPreviewPageInfo();
                Document.PrintController = printController;
            }

            StartPage = Math.Min(Pages.Length - 1, StartPage);
        }
예제 #17
0
        /// <summary>
        /// 计算预览页
        /// </summary>
        private void ComputePreview()
        {
            if (document == null)
            {
                ppiPreviewPageArr = new PreviewPageInfo[0];
            }
            else
            {
                System.Drawing.Printing.PrintController printControl = document.PrintController;
                PreviewPrintController previewControl = new PreviewPrintController();
                previewControl.UseAntiAlias = UseAntiAlias;

                document.PrintController = previewControl;

                SetPageSize();
                document.Print();
                ppiPreviewPageArr        = previewControl.GetPreviewPageInfo();
                document.PrintController = printControl;
            }
        }
예제 #18
0
        private void 取打印图_Click(object sender, EventArgs e)
        {
            PreviewPrintController previewController = new PreviewPrintController();

            // previewController.UseAntiAlias = true;
            printDocument.PrintController = previewController;//赋值后,为打印预览模式,printDocument.Print() 不执行打印操作,执行预览操作
            printDocument.Print();
            PreviewPageInfo[] pageInfo = previewController.GetPreviewPageInfo();
            if (pageInfo != null && pageInfo.Length > 0)
            {
                Image  image  = pageInfo[0].Image;
                Size   s      = pageInfo[0].PhysicalSize;
                Bitmap bitmap = new Bitmap(image, 620, s.Height);

                this.pictureBox1.BackColor = Color.White;
                this.pictureBox1.Image     = (Image)bitmap;
            }
            StandardPrintController printController = new StandardPrintController();

            printDocument.PrintController = printController;
        }