Пример #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();
            }

            PictureBox pic = new PictureBox();

            pic.Width  = 800;
            pic.Height = 1024;
            _pdfDoc.FitToWidth(pic.Handle);
            pic.Height = _pdfDoc.PageHeight;
            _pdfDoc.RenderPage(pic.Handle);
            /*Added since 1.0.6.2*/
            _pdfDoc.CurrentX     = 0;
            _pdfDoc.CurrentY     = 0;
            _pdfDoc.ClientBounds = new Rectangle(0, 0, _pdfDoc.PageWidth, _pdfDoc.PageHeight);

            _backbuffer = new Bitmap(_pdfDoc.PageWidth, _pdfDoc.PageHeight);

            using (Graphics g = Graphics.FromImage(_backbuffer))
            {
                /*New thread safe method*/
                _pdfDoc.DrawPageHDC(g.GetHdc());
                g.ReleaseHdc();
            }
            pic.Dispose();

            pictureBox1.Image = _backbuffer;
        }
Пример #2
0
 private void ApplyZoomToPDF(PictureBox pictureBox, object mode)
 {
     pictureBox.Width += SystemInformation.VerticalScrollBarWidth;
     if (mode.GetType() == typeof(ViewMode))
     {
         if ((ViewMode)mode == ViewMode.FIT_WIDTH)
         {
             pdfDoc.FitToWidth(pictureBox.Handle);
         }
         else if ((ViewMode)mode == ViewMode.FIT_TO_SCREEN)
         {
             pdfDoc.FitToHeight(pictureBox.Handle);
             if (pdfDoc.PageWidth > pdfDoc.PageHeight)
             {
                 pdfDoc.FitToWidth(pictureBox.Handle);
             }
         }
     }
     else if (mode.GetType() == typeof(double))
     {
         pdfDoc.Zoom = Math.Abs((double)mode);
     }
     pictureBox.Width -= SystemInformation.VerticalScrollBarWidth;
 }
Пример #3
0
        /* ----------------------------------------------------------------- */
        ///
        /// Open
        ///
        /// <summary>
        /// 指定された PDF ファイルを開いて,最初のページを描画する.
        /// MEMO: パスの記憶場所を検討中.現在は,Parent.Tag を利用
        /// している.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public static void Open(Canvas canvas, string path, string password, FitCondition which)
        {
            if (canvas == null)
            {
                return;
            }
            var engine = canvas.Tag as CanvasEngine;

            if (engine != null)
            {
                CanvasPolicy.Close(canvas);
            }

            var core = new PDF();

            engine             = new CanvasEngine(core);
            canvas.Tag         = engine;
            core.UseMuPDF      = true;
            core.UserPassword  = password;
            core.OwnerPassword = password;

            if (core.LoadPDF(path))
            {
                core.CurrentPage = 1;
                if (which == FitCondition.Height)
                {
                    core.FitToHeight(canvas.Parent.Handle);
                    core.Zoom = core.Zoom - 1; // 暫定
                }
                else if (which == FitCondition.Width)
                {
                    core.FitToWidth(canvas.Parent.Handle);
                    core.Zoom = core.Zoom - 1; // 暫定
                }
                else
                {
                    core.Zoom = 100;
                }
                canvas.Parent.Text = System.IO.Path.GetFileNameWithoutExtension(path);
                canvas.Parent.Tag  = path;
                CanvasPolicy.AsyncRender(canvas, true);
            }
        }
Пример #4
0
        /* ----------------------------------------------------------------- */
        ///
        /// Open
        /// 
        /// <summary>
        /// 指定された PDF ファイルを開いて,最初のページを描画する.
        /// MEMO: パスの記憶場所を検討中.現在は,Parent.Tag を利用
        /// している.
        /// </summary>
        /// 
        /* ----------------------------------------------------------------- */
        public static void Open(Canvas canvas, string path, string password, FitCondition which)
        {
            if (canvas == null) return;
            var engine = canvas.Tag as CanvasEngine;
            if (engine != null) CanvasPolicy.Close(canvas);

            var core = new PDF();
            engine = new CanvasEngine(core);
            canvas.Tag = engine;
            core.UseMuPDF = true;
            core.UserPassword = password;
            core.OwnerPassword = password;

            if (core.LoadPDF(path)) {
                core.CurrentPage = 1;
                if (which == FitCondition.Height) {
                    core.FitToHeight(canvas.Parent.Handle);
                    core.Zoom = core.Zoom - 1; // 暫定
                }
                else if (which == FitCondition.Width) {
                    core.FitToWidth(canvas.Parent.Handle);
                    core.Zoom = core.Zoom - 1; // 暫定
                }
                else core.Zoom = 100;
                canvas.Parent.Text = System.IO.Path.GetFileNameWithoutExtension(path);
                canvas.Parent.Tag = path;
                CanvasPolicy.AsyncRender(canvas, true);
            }
        }