Ejemplo n.º 1
0
        public void Open(IPdfSource source, string password = null)
        {
            var pw = password;

            if (this.PasswordRequired != null && MuPdfWrapper.NeedsPassword(source) && pw == null)
            {
                var e = new PasswordRequiredEventArgs();
                this.PasswordRequired(this, e);

                if (e.Cancel)
                {
                    return;
                }

                pw = e.Password;
            }

            this.LoadPdf(source, pw);
            this.CurrentSource   = source;
            this.CurrentPassword = pw;
            if (TotalPages > 0)
            {
                this.CurrentPage = 1;
            }

            if (this.PdfLoaded != null)
            {
                this.PdfLoaded(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Will only be triggered if the AllowDrop-Property is set to true
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }

            var filenames = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (filenames == null)
            {
                return;
            }

            var filename = filenames.FirstOrDefault();

            if (filename != null && File.Exists(filename))
            {
                string pw = null;

                if (MuPdfWrapper.NeedsPassword(new FileSource(filename)))
                {
                    if (this.PasswordRequired == null)
                    {
                        return;
                    }

                    var args = new PasswordRequiredEventArgs();
                    this.PasswordRequired(this, args);

                    if (args.Cancel)
                    {
                        return;
                    }

                    pw = args.Password;
                }

                try
                {
                    this.OpenFile(filename, pw);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("An error occured: " + ex.Message));
                }
            }
        }