Exemplo n.º 1
0
        public bool LoadStream(System.IO.Stream fileStream)
        {
            if (_pdfDoc != null)
            {
                _pdfDoc.Dispose();
                _pdfDoc = null;
            }
            //if (_pdfDoc == null)
            //{
            _pdfDoc = new PDFWrapper();
            _pdfDoc.RenderNotifyFinished += new RenderNotifyFinishedHandler(_pdfDoc_RenderNotifyFinished);
            _pdfDoc.PDFLoadCompeted      += new PDFLoadCompletedHandler(_pdfDoc_PDFLoadCompeted);
            _pdfDoc.PDFLoadBegin         += new PDFLoadBeginHandler(_pdfDoc_PDFLoadBegin);

            try
            {
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }
                //fs = new System.IO.FileStream(filename, System.IO.FileMode.Open);
                //return pdfDoc.LoadPDF(fs);
                bool bRet = _pdfDoc.LoadPDF(fileStream);
                return(bRet);
            }
            catch (System.Security.SecurityException ex)
            {
                frmPassword frm = new frmPassword();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (!frm.UserPassword.Equals(String.Empty))
                    {
                        _pdfDoc.UserPassword = frm.UserPassword;
                    }
                    if (!frm.OwnerPassword.Equals(String.Empty))
                    {
                        _pdfDoc.OwnerPassword = frm.OwnerPassword;
                    }
                    bool bRet = _pdfDoc.LoadPDF(fileStream);
                    return(bRet);
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
 private bool LoadFile(string filename, PDFLibNet.PDFWrapper pdfDoc)
 {
     try
     {
         if (fs != null)
         {
             fs.Close();
             fs = null;
         }
         //fs = new System.IO.FileStream(filename, System.IO.FileMode.Open);
         //return pdfDoc.LoadPDF(fs);
         bool bRet = pdfDoc.LoadPDF(filename);
         return(bRet);
     }
     catch (System.Security.SecurityException)
     {
         frmPassword frm = new frmPassword();
         if (frm.ShowDialog() == DialogResult.OK)
         {
             if (!frm.UserPassword.Equals(String.Empty))
             {
                 pdfDoc.UserPassword = frm.UserPassword;
             }
             if (!frm.OwnerPassword.Equals(String.Empty))
             {
                 pdfDoc.OwnerPassword = frm.OwnerPassword;
             }
             return(LoadFile(filename, pdfDoc));
         }
         else
         {
             MessageBox.Show(Resources.UIStrings.ErrorFileEncrypted, Text);
             return(false);
         }
     }
 }
Exemplo n.º 3
0
 private bool LoadFile(string filename, PDFLibNet.PDFWrapper pdfDoc)
 {
     try
     {
         if (fs != null)
         {
             fs.Close();
             fs = null;
         }
         //Does not supported by MuPDF.                
         //fs = new System.IO.FileStream(filename, System.IO.FileMode.Open);                
         //return pdfDoc.LoadPDF(fs);                
         bool bRet =  pdfDoc.LoadPDF(filename);               
         tsbUseMuPDF.Checked = pdfDoc.UseMuPDF;
         return bRet;                
     }
     catch (System.Security.SecurityException)
     {
          frmPassword frm = new frmPassword();
          if (frm.ShowDialog() == DialogResult.OK)
          {
              if (!frm.UserPassword.Equals(String.Empty))
                  pdfDoc.UserPassword = frm.UserPassword;
              if (!frm.OwnerPassword.Equals(String.Empty))
                  pdfDoc.OwnerPassword = frm.OwnerPassword;
              return LoadFile(filename, pdfDoc);
          }
          else
          {
              MessageBox.Show(Resources.UIStrings.ErrorFileEncrypted ,Text);
              return false;
          }
     }
 }
Exemplo n.º 4
0
        public bool LoadStream(System.IO.Stream fileStream)
        {
            if (_pdfDoc != null)
            {
                _pdfDoc.Dispose();
                _pdfDoc = null;
            }
            //if (_pdfDoc == null)
            //{
            _pdfDoc = new PDFWrapper();
            _pdfDoc.RenderNotifyFinished += new RenderNotifyFinishedHandler(_pdfDoc_RenderNotifyFinished);
            _pdfDoc.PDFLoadCompeted += new PDFLoadCompletedHandler(_pdfDoc_PDFLoadCompeted);
            _pdfDoc.PDFLoadBegin += new PDFLoadBeginHandler(_pdfDoc_PDFLoadBegin);
            _pdfDoc.UseMuPDF = tsbUseMuPDF.Checked;

            try
            {
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }
                //Does not supported by MuPDF.                
                //fs = new System.IO.FileStream(filename, System.IO.FileMode.Open);                
                //return pdfDoc.LoadPDF(fs);                
                bool bRet = _pdfDoc.LoadPDF(fileStream);
                tsbUseMuPDF.Checked = _pdfDoc.UseMuPDF;
                return bRet;
            }
            catch (System.Security.SecurityException ex)
            {
                frmPassword frm = new frmPassword();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (!frm.UserPassword.Equals(String.Empty))
                        _pdfDoc.UserPassword = frm.UserPassword;
                    if (!frm.OwnerPassword.Equals(String.Empty))
                        _pdfDoc.OwnerPassword = frm.OwnerPassword;
                    bool bRet = _pdfDoc.LoadPDF(fileStream);
                    tsbUseMuPDF.Checked = _pdfDoc.UseMuPDF;
                    return bRet;
                }
                else
                {
                    throw ex;
                }
            }
                            
        }