Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF print document constructor
        /// </summary>
        /// <param name="Document">Current PDF document</param>
        /// <param name="Resolution">Image resolution</param>
        ////////////////////////////////////////////////////////////////////
        public PdfPrintDocument
        (
            PdfDocument Document,
            Double Resolution                                           // printer resolution in pixels per inch
        )
        {
            // save document
            this.Document = Document;

            // save resolution
            this.Resolution = Resolution;

            // create print document and preview controller objects
            PrintController = new PreviewPrintController();

            // copy document's page size to default settings
            // convert page size from points to 100th of inch
            // do not set lanscape flag
            PaperSize PSize = new PaperSize();

            PSize.Width  = (Int32)(Document.PageSize.Width / 0.72 + 0.5);
            PSize.Height = (Int32)(Document.PageSize.Height / 0.72 + 0.5);
            DefaultPageSettings.PaperSize = PSize;

            // assume document is in color
            DefaultPageSettings.Color = true;
            return;
        }
Exemplo n.º 2
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();
            }
        }
    }
Exemplo n.º 3
0
        public void OnStartPage_InvokeNullDocument_ThrowsNullReferenceException()
        {
            var controller = new PreviewPrintController();
            var e          = new PrintPageEventArgs(null, Rectangle.Empty, Rectangle.Empty, null);

            Assert.Throws <NullReferenceException>(() => controller.OnStartPage(null, e));
        }
Exemplo n.º 4
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 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;
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF print document constructor
        /// </summary>
        /// <param name="Document">Current PDF document</param>
        ////////////////////////////////////////////////////////////////////
        public PdfPrintDocument
        (
            PdfDocument Document
        )
        {
            // save document
            this.Document = Document;

            // set default resolution to 96 pixels per inch
            Resolution = 96.0;

            // save as jpeg
            SaveAs = SaveImageAs.Jpeg;

            // create print document and preview controller objects
            PrintController = new PreviewPrintController();

            // copy document's page size to default settings
            // convert page size from points to 100th of inch
            // do not set lanscape flag
            PaperSize PSize = new PaperSize();

            PSize.Width  = (int)(Document.PageSize.Width / 0.72 + 0.5);
            PSize.Height = (int)(Document.PageSize.Height / 0.72 + 0.5);
            DefaultPageSettings.PaperSize = PSize;

            // assume document is in color
            DefaultPageSettings.Color = true;
            return;
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
        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);
            }
        }
Exemplo n.º 11
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
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
 public void OnStartPage_InvokeNullEventArgs_ThrowsNullReferenceException()
 {
     using (var document = new PrintDocument())
     {
         var controller = new PreviewPrintController();
         Assert.Throws <NullReferenceException>(() => controller.OnStartPage(document, null));
     }
 }
Exemplo n.º 14
0
 public void OnEndPrint_InvokeWithoutStarting_Nop(PrintEventArgs e)
 {
     using (var document = new PrintDocument())
     {
         var controller = new PreviewPrintController();
         controller.OnEndPrint(document, e);
         controller.OnEndPrint(null, e);
     }
 }
Exemplo n.º 15
0
 public void OnEndPage_InvokeWithoutStarting_Nop()
 {
     using (var document = new PrintDocument())
     {
         var controller = new PreviewPrintController();
         controller.OnEndPage(document, new PrintPageEventArgs(null, Rectangle.Empty, Rectangle.Empty, null));
         controller.OnEndPage(null, null);
     }
 }
Exemplo n.º 16
0
 public void OnStartPage_PrintNotStarted_ThrowsNullReferenceException()
 {
     using (var document = new PrintDocument())
     {
         var controller = new PreviewPrintController();
         var e          = new PrintPageEventArgs(null, Rectangle.Empty, Rectangle.Empty, null);
         Assert.Throws <NullReferenceException>(() => controller.OnStartPage(document, e));
     }
 }
Exemplo n.º 17
0
        public void OnStartPrint_InvokeWithDocument_Success(PrintEventArgs e)
        {
            using (var document = new PrintDocument())
            {
                var controller = new PreviewPrintController();
                controller.OnStartPrint(document, e);

                // Call OnEndPrint
                controller.OnEndPrint(document, e);
            }
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        public void OnStartPage_InvokeNullEventArgsPageSettings_ReturnsNull()
        {
            using (var document = new PrintDocument())
            {
                var controller = new PreviewPrintController();
                controller.OnStartPrint(document, new PrintEventArgs());

                var printEventArgs = new PrintPageEventArgs(null, Rectangle.Empty, Rectangle.Empty, null);
                Assert.Throws <NullReferenceException>(() => controller.OnStartPage(document, printEventArgs));
            }
        }
Exemplo n.º 20
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();
        }
Exemplo n.º 21
0
        public void OnStartPrint_InvokeMultipleTimes_Success()
        {
            using (var document = new PrintDocument())
            {
                var controller = new PreviewPrintController();
                controller.OnStartPrint(document, new PrintEventArgs());
                controller.OnStartPrint(document, new PrintEventArgs());

                // Call OnEndPrint
                controller.OnEndPrint(document, new PrintEventArgs());
            }
        }
Exemplo n.º 22
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;
            }
        }
Exemplo n.º 23
0
        public void OnStartPage_InvokeWithPrint_ReturnsNull()
        {
            using (var document = new PrintDocument())
            {
                var controller = new PreviewPrintController();
                controller.OnStartPrint(document, new PrintEventArgs());

                var printEventArgs = new PrintPageEventArgs(null, Rectangle.Empty, Rectangle.Empty, new PageSettings());
                Assert.NotNull(controller.OnStartPage(document, printEventArgs));

                // Call OnEndPage.
                controller.OnEndPage(document, printEventArgs);

                // Call EndPrint.
                controller.OnEndPrint(document, new PrintEventArgs());
            }
        }
Exemplo n.º 24
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     PDF print document constructor
        /// </summary>
        /// <param name="Document">Current PDF document</param>
        /// <param name="ImageControl">Image control</param>
        ////////////////////////////////////////////////////////////////////
        public PdfPrintDocument
        (
            PdfDocument Document,
            PdfImageControl ImageControl
        )
        {
            // save document
            this.Document = Document;

            // save image control
            if (ImageControl == null)
            {
                ImageControl = new PdfImageControl();
            }

            this.ImageControl = ImageControl;

            // set default resolution to 96 pixels per inch
            if (ImageControl.Resolution == 0)
            {
                ImageControl.Resolution = 96.0;
            }

            // make sure image control crop rectangles are empty
            this.ImageControl.CropRect    = Rectangle.Empty;
            this.ImageControl.CropPercent = RectangleF.Empty;

            // create print document and preview controller objects
            PrintController = new PreviewPrintController();

            // copy document's page size to default settings
            // convert page size from points to 100th of inch
            // do not set lanscape flag
            var PSize = new PaperSize
            {
                Width  = (int)(Document.PageSize.Width / 0.72 + 0.5),
                Height = (int)(Document.PageSize.Height / 0.72 + 0.5)
            };

            DefaultPageSettings.PaperSize = PSize;

            // assume document is in color
            DefaultPageSettings.Color = true;
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 27
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;
        }
Exemplo n.º 28
0
Arquivo: test.cs Projeto: mono/gert
	static int Main ()
	{
		PreviewPrintController printController = new PreviewPrintController ();
		MyPrintDocument doc = new MyPrintDocument ();
		doc.PrintController = printController;
		doc.Print ();

		if (doc.Matrix.Elements.Length != 6)
			return 1;
		if (doc.Matrix.Elements [0] != 1)
			return 2;
		if (doc.Matrix.Elements [1] != 0)
			return 3;
		if (doc.Matrix.Elements [2] != 0)
			return 4;
		if (doc.Matrix.Elements [3] != 1)
			return 5;
		if (doc.Matrix.Elements [4] != 0)
			return 6;
		if (doc.Matrix.Elements [5] != 0)
			return 7;
		return 0;
	}
        public PrintPreviewControl()
        {
            autozoom  = true;
            columns   = 1;
            rows      = 0;
            startPage = 0;

            this.BackColor = SystemColors.AppWorkspace;

            controller = new PreviewPrintController();

            vbar = new ImplicitVScrollBar();
            hbar = new ImplicitHScrollBar();

            vbar.Visible       = false;
            hbar.Visible       = false;
            vbar.ValueChanged += new EventHandler(VScrollBarValueChanged);
            hbar.ValueChanged += new EventHandler(HScrollBarValueChanged);

            SuspendLayout();
            Controls.AddImplicit(vbar);
            Controls.AddImplicit(hbar);
            ResumeLayout();
        }
Exemplo n.º 30
0
        //-----------------------------------------------------------
        #region ** object model

        public bool RenderDocument(PrintDocument doc, bool showProgressDialog)
        {
            // save reference to document
            _doc = doc;

            // initialize pdf document
            _pdf.Clear();
            _pdf.Landscape = false;

            // prepare to render
            var savePC = _doc.PrintController;

            _previewController   = new PreviewPrintController();
            _doc.PrintController = showProgressDialog
                ? new PrintControllerWithStatusDialog(_previewController)
                : (PrintController)_previewController;
            _pageCount = 0;
            _cancel    = false;

            // render
            try
            {
                _doc.PrintPage += _doc_PrintPage;
                _doc.EndPrint  += _doc_EndPrint;
                _doc.Print();
            }
            finally
            {
                _doc.PrintPage      -= _doc_PrintPage;
                _doc.EndPrint       -= _doc_EndPrint;
                _doc.PrintController = savePC;
            }

            // done
            return(!_cancel);
        }
Exemplo n.º 31
0
        public void OnStartPrint_InvokeNullDocument_ThrowsNullReferenceException()
        {
            var controller = new PreviewPrintController();

            Assert.Throws <NullReferenceException>(() => controller.OnStartPrint(null, new PrintEventArgs()));
        }