public static int GetPDFPageCount(string _pdfFile)
        {
            int _count = 0;

            O2S.Components.PDF4NET.PDFDocument _pdfDocument
                = new O2S.Components.PDF4NET.PDFDocument(_pdfFile);

            _pdfDocument.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            _count = _pdfDocument.Pages.Count;
            return _count;
        }
        public static int GetPDFPageCountFromID(string _documentID)
        {
            string _documentPath = DatabaseCalls.ReturnSingleStringValue("select "
                + " ScanPath from ScanPatientDocuments"
                + " where ScanID = " + _documentID);
            
            int _count = 0;

            O2S.Components.PDF4NET.PDFDocument _pdfDocument
                = new O2S.Components.PDF4NET.PDFDocument(Common.StoreComputer
                + Common.StoreShare + _documentPath);

            _pdfDocument.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            _count = _pdfDocument.Pages.Count;
            return _count;
        }
        private MemoryStream CreatePreviewFax(StringCollection _listOfPdfs)
        {
            O2S.Components.PDF4NET.PDFDocument _ToBeCopiedPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _newPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFPage _pdfPage;
            Stream _fileStream = null;

            _ToBeCopiedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            for (int i = 0; i < _listOfPdfs.Count; i++)
            {
               // MakeDocumentReadable(_listOfPdfs[i]);
                _fileStream = new FileStream(Walden.CompleteFax.Library.Database.TemporaryFaxPath + GetUserName() + "\\" + _listOfPdfs[i], FileMode.Open);
                _ToBeCopiedPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                for (int j = 0; j < _ToBeCopiedPDF.Pages.Count; j++)
                {
                    _pdfPage = _ToBeCopiedPDF.Pages[j];
                    _newPDF.Pages.Add(_pdfPage);
                }
                _fileStream.Close();
            }

            MemoryStream _newPDFStream = new MemoryStream();
            _newPDF.Save(_newPDFStream);

            return _newPDFStream;
        }
        public static bool DeleteMultiplePDFPagesV2(string _reviewDoc, int iStartPageToDelete)
        {
            try
            {
                int _constant = 0;
                int _pageCount = 0;

                O2S.Components.PDF4NET.PDFDocument _newPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_reviewDoc);
                _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
                iStartPageToDelete = iStartPageToDelete - 1;
                _constant = iStartPageToDelete;
                _pageCount = _newPDF.Pages.Count - 1;
                for (int i = iStartPageToDelete; i <= _pageCount; i++)
                {
                    _newPDF.Pages.RemoveAt(_constant);
                }
                _newPDF.Save(_reviewDoc);
                _newPDF = null;
                return true;
            }
            catch (Exception ex)
            {
                Common.Log(ex.Message);
                return false;
            }
        }
        public static bool CreatePDFToReviewV2(string sAdobePath, string sAdobeNewFilePath)
        {
            try
            {
                O2S.Components.PDF4NET.PDFDocument _ToBeCopiedPDF
                    = new O2S.Components.PDF4NET.PDFDocument();
                O2S.Components.PDF4NET.PDFDocument _newPDF
                    = new O2S.Components.PDF4NET.PDFDocument();
                O2S.Components.PDF4NET.PDFPage _pdfPage;


                _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
                _ToBeCopiedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                Stream _fileStream = null;

                DataSet ds = new DataSet();
                DataTable MyTable = null;
                DataRow MyRow = null;
                DataView dv = null;

                ReviewPages = 0;

                int lFileCount = 0;

                DirectoryInfo di = new DirectoryInfo(sAdobePath);
                FileInfo[] rgFiles = di.GetFiles("*.pdf*");

                using (SqlConnection cn = new SqlConnection(Database.WaldenConnect))
                {
                    cn.Open();
                    using (SqlCommand cm = cn.CreateCommand())
                    {

                        cm.CommandText = "delete from ScanFiles";
                        cm.ExecuteNonQuery();

                        string sSQL = string.Empty;
                        System.Data.SqlClient.SqlDataAdapter sSQLAdp = null;
                        sSQL = "select FileName,FileDate from ScanFiles"
                            + " where AccountID = " + Common.AccountID
                            + " order by FileDate desc";
                        using (sSQLAdp = new System.Data.SqlClient.SqlDataAdapter(sSQL, cn))
                        {
                            sSQLAdp.Fill(ds, "ScanFiles");
                            MyTable = ds.Tables[0];
                            foreach (FileInfo fi in rgFiles)
                            {
                                MyRow = MyTable.NewRow();
                                MyRow["FileName"] = fi.FullName;
                                MyRow["FileDate"] = fi.CreationTime.ToString();
                                MyTable.Rows.Add(MyRow);
                                lFileCount++;
                            }
                            string[] srcFilesNames = new string[lFileCount];
                            dv = MyTable.DefaultView;

                            dv.Sort = "FileDate";

                            for (int b = 0; b < dv.Count; b++)
                            {
                                try
                                {
                                    _fileStream = new FileStream(dv[b].Row[0].ToString(), FileMode.Open);
                                    _ToBeCopiedPDF
                                        = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                                }
                                catch (Exception ex)
                                {
                                    Common.Log(ex.Message);
                                    return false;
                                }
                                //Write document file name and page number on each page
                                for (int i = 0; i < _ToBeCopiedPDF.Pages.Count; i++)
                                {
                                    _pdfPage = _ToBeCopiedPDF.Pages[i];
                                    _newPDF.Pages.Add(_pdfPage);

                                }
                                _fileStream.Close();
                            }
                        }
                        _newPDF.Save(sAdobeNewFilePath);
                        _newPDF.Dispose();
                    }
                }
                return true;
            }
            catch (Exception er)
            {
                Common.Log(er.Message);
                return false;
            }
        }
        public static bool DeletePDFPages(string _reviewDocument, int iPageToDelete)
        {
            try
            {
                O2S.Components.PDF4NET.PDFDocument _newPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_reviewDocument);

                _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                _newPDF.Pages.RemoveAt(iPageToDelete - 1);
                _newPDF.Save(_reviewDocument);
                return true;
            }
            catch (Exception ex)
            {
                Common.Log(ex.Message);
                return false;
            }
        }
        public static bool DeleteMultiplePDFPages(string _reviewDocument,
            int _startPage, int _deleteToPageTo)
        {
            try
            {
                O2S.Components.PDF4NET.PDFDocument _newPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_reviewDocument);

                _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                _startPage = _startPage - 1;

                for (int i = _startPage; i < _deleteToPageTo; i++)
                {
                    _newPDF.Pages.RemoveAt(_startPage);
                }
                _newPDF.Save(_reviewDocument);
                _newPDF = null;
                return true;
            }
            catch (Exception ex)
            {
                Common.Log(ex.Message);
                return false;
            }
        }
        public static MemoryStream CreatePreviewFax(StringCollection _listOfPdfs)
        {
            O2S.Components.PDF4NET.PDFDocument _ToBeCopiedPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _newPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFPage _pdfPage;
            Stream _fileStream = null;

            _ToBeCopiedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            for (int i = 0; i < _listOfPdfs.Count; i++)
            {
                MakeDocumentReadable(_listOfPdfs[i]);
                _fileStream = new FileStream(_listOfPdfs[i], FileMode.Open);
                _ToBeCopiedPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                for (int j = 0; j < _ToBeCopiedPDF.Pages.Count; j++)
                {
                    _pdfPage = _ToBeCopiedPDF.Pages[j];
                    _newPDF.Pages.Add(_pdfPage);
                }
                _fileStream.Close();
            }

            MemoryStream _newPDFStream = new MemoryStream();
            _newPDF.Save(_newPDFStream);
            
            return _newPDFStream;
        }
        public static bool MergeTwoDocumentsNoDelition(string _documentToMerge,
            string _MergedDocument)
        {

            O2S.Components.PDF4NET.PDFDocument _toBeCopied1PDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _toBeCopied2PDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _mergedPDF
                = new O2S.Components.PDF4NET.PDFDocument();

            _toBeCopied1PDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _toBeCopied2PDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _mergedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            O2S.Components.PDF4NET.PDFPage _pdfPage;
            Stream _fileStream = null;
            Stream _fileStream2 = null;

            //Merged document may be read only Need to change attributes so it can
            //be written to
            MakeDocumentReadable(_MergedDocument);

            //Create string name with a 1 added 
            string sTempName = _MergedDocument.Replace(".pdf", "temp.pdf");

            //Copy current document to name with 1 added
            File.Copy(_MergedDocument, sTempName, true);

            //Open the New document  By opening it first
            //these pages will be placed at the top of the
            //document
            _fileStream = new FileStream(_documentToMerge, FileMode.Open);
            _toBeCopied1PDF
                = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

            for (int i = 0; i < _toBeCopied1PDF.Pages.Count; i++)
            {
                _pdfPage = _toBeCopied1PDF.Pages[i];
                _mergedPDF.Pages.Add(_pdfPage);
            }

            //Adding pages to the document with the name that is in 
            //the database for that folder.  These are the pages that
            //are currently in the document

            _fileStream2 = new FileStream(sTempName, FileMode.Open);
            _toBeCopied2PDF
                = new O2S.Components.PDF4NET.PDFDocument(_fileStream2);

            //Write document file name and page number on each page
            for (int i = 0; i < _toBeCopied2PDF.Pages.Count; i++)
            {
                _pdfPage = _toBeCopied2PDF.Pages[i];
                _mergedPDF.Pages.Add(_pdfPage);
            }

            _fileStream.Close();
            _fileStream2.Close();
            //Save new document over the old document. 
            //It will be overwritten
            _mergedPDF.Save(_MergedDocument);

            //Delete temporary documents
            File.Delete(sTempName);
            //File.Delete(_documentToMerge);
            return true;
        }
Пример #10
0
        public static string CombineMultiplePDFsDelete(StringCollection _listOfPdfs, string _pathNewPDF)
        {
            O2S.Components.PDF4NET.PDFDocument _ToBeCopiedPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _newPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFPage _pdfPage;
            Stream _fileStream = null;

            string _newName = "\\" + Common.GetFileNameFromDateTimeString() + ".pdf";

            _ToBeCopiedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            for (int i = 0; i < _listOfPdfs.Count; i++)
            {
                MakeDocumentReadable(_listOfPdfs[i]);
                _fileStream = new FileStream(_listOfPdfs[i], FileMode.Open);
                _ToBeCopiedPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                for (int j = 0; j < _ToBeCopiedPDF.Pages.Count; j++)
                {
                    _pdfPage = _ToBeCopiedPDF.Pages[j];
                    _newPDF.Pages.Add(_pdfPage);
                }
                _fileStream.Close();
            }

            //Save new document over the old document. 
            //It will be overwritten
            _newPDF.Save(_pathNewPDF + _newName);

            for (int i = 0; i < _listOfPdfs.Count; i++)
            {
                File.Delete(_listOfPdfs[i]);
            }

            return _pathNewPDF + _newName;
        }
Пример #11
0
        public static string CombineMultiplePDFs(StringCollection _listOfPdfs, string _pathNewPDF)
        {
            O2S.Components.PDF4NET.PDFDocument _ToBeCopiedPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFDocument _newPDF
                = new O2S.Components.PDF4NET.PDFDocument();
            O2S.Components.PDF4NET.PDFPage _pdfPage;
            Stream _fileStream = null;

            _ToBeCopiedPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";
            _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

            for (int i = 0; i < _listOfPdfs.Count; i++)
            {
                MakeDocumentReadable(_listOfPdfs[i]);
                _fileStream = new FileStream(_listOfPdfs[i], FileMode.Open);
                _ToBeCopiedPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                for (int j = 0; j < _ToBeCopiedPDF.Pages.Count; j++)
                {
                    _pdfPage = _ToBeCopiedPDF.Pages[j];
                    _newPDF.Pages.Add(_pdfPage);
                }
                _fileStream.Close();
            }

            //Save new document over the old document. 
            //It will be overwritten
            int rr = _newPDF.Pages.Count;
            _newPDF.Save(_pathNewPDF);

            return "OK";
        }
Пример #12
0
        public static void EncryptPDF(string _pathToPDF, string _password)
        {
            O2S.Components.PDF4NET.PDFDocument _pdfDocument
                = new O2S.Components.PDF4NET.PDFDocument(_pathToPDF); 

            //_pdfDocument.s

			// Create the pdf document
			O2S.Components.PDF4NET.PDFDocument pdfDoc = new PDFDocument( );
			
			// set the security options
			pdfDoc.SecurityManager = new PDFSecurityManager( );
			// use 128 bit encryption
			pdfDoc.SecurityManager.KeySize = EncryptionKeySize.Use128BitKey;
			// set user password to "userpass"
			pdfDoc.SecurityManager.UserPassword = Encoding.ASCII.GetBytes( "userpass" );
			// set owner password to "ownerpass"
			pdfDoc.SecurityManager.OwnerPassword = Encoding.ASCII.GetBytes( "ownerpass" );
			// allow to print the pdf document
			pdfDoc.SecurityManager.AllowPrint = true;
			// do not allow high quality print
			pdfDoc.SecurityManager.FullQualityPrint = false;
			// do not alow to modify the document
			pdfDoc.SecurityManager.AllowModifyDocument = false;
			// do not allow to extract content (text and images) from the document
			pdfDoc.SecurityManager.AllowExtractContent = false;
			// do not allow to fill forms or to create annotations
			pdfDoc.SecurityManager.AllowInteractiveEdit = false;
			// do not allow forms fill
			pdfDoc.SecurityManager.AllowFormsFill = false;
			// allow to extract content in support for accessibility
			pdfDoc.SecurityManager.AllowAccessibilityExtractContent = true;
			// do not allow to assemble document
			pdfDoc.SecurityManager.AllowAssembleDocument = false;

			// Create one page
			PDFPage pdfPage = pdfDoc.AddPage( );

			// Draw "Encrypted Hello world" in the center of the page
			//pdfPage.Canvas.DrawText( "Encrypted", 
			//	new PDFFont( FontFace.Helvetica, 100 ), new PDFPen( new PDFColor( 255, 0, 0 ), 1 ), 
			//	new PDFBrush( new PDFColor( 0, 0, 255 ) ), pdfPage.Width/2, pdfPage.Height/2 - 3, 
			//	0, TextAlign.BottomCenter );
			//pdfPage.Canvas.DrawText( "Hello world !", 
			//	new PDFFont( FontFace.Helvetica, 100 ), new PDFPen( new PDFColor( 255, 0, 0 ), 1 ), 
			//	new PDFBrush( new PDFColor( 0, 0, 255 ) ), pdfPage.Width/2, pdfPage.Height/2 + 3, 
			//	0, TextAlign.TopCenter );

			// Save the document to disk
            pdfDoc.Save(_pathToPDF);
        }
Пример #13
0
        public static int GetPDFPageCountFromFolder(string _pdfFolder)
        {
            try
            {
                int _count = 0;
                DirectoryInfo di = new DirectoryInfo(_pdfFolder);
                FileInfo[] rgFiles = di.GetFiles("*.*");

                foreach (FileInfo fi in rgFiles)
                {
                    O2S.Components.PDF4NET.PDFDocument _pdfDocument 
                        = new O2S.Components.PDF4NET.PDFDocument(fi.FullName);

                    _pdfDocument.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                    _count = _count + _pdfDocument.Pages.Count;
                }

                return _count;
            }
            catch
            {
                return 0;
            }
        }
Пример #14
0
        public static bool SplitTwoPDFDocumentsV2(string _document1, string _document2,
            int _startPage, int _numberOfPages)
        {
            try
            {
                string _fileToProcess = string.Empty;
                Stream _fileStream = null;

                _fileToProcess = _document2.Replace(".pdf", "temp.pdf");

                File.Copy(_document1, _fileToProcess, true);

                _fileStream = new FileStream(_fileToProcess, FileMode.Open);

                O2S.Components.PDF4NET.PDFDocument _newPDF
                    = new O2S.Components.PDF4NET.PDFDocument(_fileStream);

                _newPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                O2S.Components.PDF4NET.PDFDocument _firstSplitPDF
                    = new O2S.Components.PDF4NET.PDFDocument();

                _firstSplitPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                O2S.Components.PDF4NET.PDFDocument _secondSplitPDF
                    = new O2S.Components.PDF4NET.PDFDocument();

                _secondSplitPDF.SerialNumber = "PDF4NET-AYBAM-8ARRR-B4EX2-OXGCC-KN2Q5";

                O2S.Components.PDF4NET.PDFPage _pdfPage;

                for (int i = 0; i < _startPage; i++)
                {
                    _pdfPage = _newPDF.Pages[i];
                    _firstSplitPDF.Pages.Add(_pdfPage);
                }

                for (int i = _startPage; i < _numberOfPages; i++)
                {
                    _pdfPage = _newPDF.Pages[i];
                    _secondSplitPDF.Pages.Add(_pdfPage);
                }

                _firstSplitPDF.Save(_document1);
                _secondSplitPDF.Save(_document2);

                _fileStream.Close();

                return true;
            }
            catch (Exception ex)
            {
                Common.Log(ex.Message);
                return false;
            }
        }