Beispiel #1
0
        public void GetPageDetails_IfPdfDocHasPage_SetsObjectEditionPageProperties()
        {
            // Arrange
            const int page01Index     = 0;
            const int pdfPage01Number = 1;
            var       pdfDoc          = new PDFDoc();

            int pdfPage01Width, pdfPage01Height;

            try
            {
                var pdfPage01 = pdfDoc.PageCreate();
                pdfPage01Width  = (int)pdfPage01.GetPageWidth();
                pdfPage01Height = (int)pdfPage01.GetPageHeight();
                pdfDoc.PagePushBack(pdfPage01);
                AddTextDataToPdfPage(pdfDoc, pdfPage01, PdfPageText);

                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            var page01 = _objectEdition.PageCollection[page01Index];

            page01.PageNo.ShouldBe(pdfPage01Number);
            page01.DisplayNo.ShouldBe(pdfPage01Number.ToString());
            page01.TextContent.ShouldBe(PdfPageText);
            page01.Width.ShouldBe(pdfPage01Width);
            page01.Height.ShouldBe(pdfPage01Height);
        }
Beispiel #2
0
        public void GetPageDetails_IfPdfDocHasThreePages_ThreePagesAddedIntoObjectEdition()
        {
            // Arrange
            var pdfDoc = new PDFDoc();

            try
            {
                var pdfPage01 = pdfDoc.PageCreate();
                var pdfPage02 = pdfDoc.PageCreate();
                var pdfPage03 = pdfDoc.PageCreate();

                pdfDoc.PagePushBack(pdfPage01);
                pdfDoc.PagePushBack(pdfPage02);
                pdfDoc.PagePushBack(pdfPage03);

                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            _objectEdition.PageCollection.Count.ShouldBe(3);
        }
Beispiel #3
0
        public void Dispose()
        {
            if (pdfDoc != null)
            {
                pdfDoc.Close();
                pdfDoc.Dispose();
            }

            pdfDoc = null;
        }
Beispiel #4
0
        public void GetPageDetails_IfPdfDocHasNoPages_NoPagesAddedToObjectEdition()
        {
            // Arrange
            var pdfDoc = new PDFDoc();

            try
            {
                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            _objectEdition.PageCollection.Count.ShouldBe(0);
        }
Beispiel #5
0
        public void GetPageDetails_IfPdfPageHasUriLinkWithoutScheme_ObjectEditionHasPageUriLinkAddedUriScheme()
        {
            // Arrange
            const int page02Index = 1;
            var       pdfDoc      = new PDFDoc();

            try
            {
                var pdfPage01 = pdfDoc.PageCreate();
                var pdfPage02 = pdfDoc.PageCreate();

                pdfDoc.PagePushBack(pdfPage01);
                pdfDoc.PagePushBack(pdfPage02);

                // create annot of pdfPage02
                // uri type of annot to an uri with mailto scheme
                var uriAcion  = PDFAction.CreateURI(pdfDoc, WebUriWithoutScheme);
                var linkAnnot = Annot.CreateLink(pdfDoc, new Rect(X1, Y1, X2, Y2), uriAcion);
                pdfPage02.AnnotInsert(0, linkAnnot);

                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            var page02LinkCollection = _objectEdition.PageCollection[page02Index].LinkCollection;
            var page02Links          = ConvertToLinkArray(page02LinkCollection);

            page02Links.ShouldSatisfyAllConditions(
                () => page02Links.Length.ShouldBe(1),
                () => page02Links.ShouldContain(link => link.LinkType == UriLinkType),
                () => page02Links.First().LinkURL.ShouldStartWith(HttpScheme));
        }
Beispiel #6
0
        public void GetPageDetails_IfPdfPageHasGoToLink_ObjectEditionPageHasGoToLink()
        {
            // Arrange
            const int page01Index = 0;
            var       pdfDoc      = new PDFDoc();

            try
            {
                var pdfPage01 = pdfDoc.PageCreate();
                var pdfPage02 = pdfDoc.PageCreate();
                pdfDoc.PagePushBack(pdfPage01);
                pdfDoc.PagePushBack(pdfPage02);

                // create annot of pdfPage01
                // goto type of annot links to pdfPage02
                var destination = Destination.CreateFit(pdfPage02);
                var gotoAction  = PDFAction.CreateGoto(destination);
                var linkAnnot   = Annot.CreateLink(pdfDoc, new Rect(X1, Y1, X2, Y2), gotoAction);
                pdfPage01.AnnotInsert(0, linkAnnot);

                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            var page01LinkCollection = _objectEdition.PageCollection[page01Index].LinkCollection;
            var page01Links          = ConvertToLinkArray(page01LinkCollection);

            page01Links.ShouldSatisfyAllConditions(
                () => page01Links.Length.ShouldBe(1),
                () => page01Links.ShouldContain(link => link.LinkType == GoToLinkType));
        }
Beispiel #7
0
        public void GetPageDetails_IfPdfPageHasNoAnnots_ObjectEditionPageHasNoLinks()
        {
            // Arrange
            const int page01Index = 0;
            var       pdfDoc      = new PDFDoc();

            try
            {
                var pdfPage01 = pdfDoc.PageCreate();
                pdfDoc.PagePushBack(pdfPage01);

                // Act
                _testEntityPrivate.Invoke(GetPageDetailsMethodName, pdfDoc);
            }
            finally
            {
                pdfDoc.Dispose();
            }

            // Assert
            var page01LinkCollection = _objectEdition.PageCollection[page01Index].LinkCollection;

            page01LinkCollection.Count.ShouldBe(0);
        }
        // GET: api/InboundFax/5
        public HttpResponseMessage Get(string id)
        {

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, ConfigurationValues.PdfTronLicenseKey);

                PDFNet.Initialize(ConfigurationValues.PdfTronLicenseKey);
                PDFDoc documentToAdd = new PDFDoc();
                string xodFileName = Guid.NewGuid().ToString() + ".xod";
                string pdfFileName = xodFileName.Replace(".xod", ".pdf");

                string filePathXod = ConfigurationValues.PathToXodFile + xodFileName;
                string filePathPdf = ConfigurationValues.PathToXodFile + pdfFileName;
                PDFDoc newDocument = new PDFDoc();

                if (string.IsNullOrEmpty(id))
                {
                    try
                    {
                        File.Delete(filePathXod);
                    }
                    catch { }
                    File.Create(filePathXod).Dispose();
                    result = new HttpResponseMessage(HttpStatusCode.OK);
                    var stream = new FileStream(filePathXod, FileMode.Open);
                    result.Content = new StreamContent(stream);
                    result.Content.Headers.ContentType =
                        new MediaTypeHeaderValue("application/octet-stream");
                    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    {
                        FileName = ConfigurationValues.XodFileName
                    };
                    return result;
                }
                else
                {
                    string[] documents = id.Split('~');

                    for (int i = 0; i < documents.Length - 1; i++)
                    {
                        FaxRepository faxData = new FaxRepository();
                        //documentToAdd = new PDFDoc(faxData.GetFullPathInboundFax(documents[i]));
                        documentToAdd = new PDFDoc(documents[i]);
                        PageIterator itr = documentToAdd.GetPageIterator();
                        for (; itr.HasNext(); itr.Next())
                        {
                            try
                            {
                                pdftron.PDF.Page page = itr.Current();
                                newDocument.PageInsert(newDocument.GetPageIterator(itr.GetPageNumber()), page);
                            }
                            catch (Exception er)
                            {
                                string s1 = er.ToString();
                            }
                        }
                    }
                    try
                    {
                        File.Delete(filePathXod);
                    }
                    catch { }

                    documentToAdd.Close();
                    documentToAdd.Dispose();
                    DocumentRepository documentData = new DocumentRepository();
                    documentData.AddUpdateCurrentDocument(Utility.GetUserName(), filePathXod, filePathPdf, id, documentData.GetFullPathToDocument(Utility.GetUserName()));
                    File.Create(filePathXod).Dispose();
                    newDocument.Save(filePathPdf, 0);
                    pdftron.Filters.Filter objFilter = pdftron.PDF.Convert.ToXod(newDocument);
                    System.Threading.Thread.Sleep(ConfigurationValues.XodSaveDelay);
                    objFilter.WriteToFile(filePathXod, true);
                    var stream = new FileStream(filePathXod, FileMode.Open);
                    result.Content = new StreamContent(stream);
                    result.Content.Headers.ContentType =
                        new MediaTypeHeaderValue("application/octet-stream");
                    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    {
                        FileName = ConfigurationValues.XodFileName
                    };
                    newDocument.Close();
                    newDocument.Dispose();
                }
                return result;
            }
            catch (Exception er)
            {
                Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString());
                return result;
            }
        }
        // GET: api/SeparatePDF/5
        public IHttpActionResult Get(string id)
        {
            try
            {

                id = id + ",";

                PDFNet.Initialize(ConfigurationValues.PdfTronLicenseKey);
                string[] pagesSeparationGroups = id.Split('~');
                string[] newPdfNames = new string[pagesSeparationGroups.Length - 1];
                PDFDoc[] newPdfDocs = new PDFDoc[pagesSeparationGroups.Length - 1];

                for (int i = 0; i < newPdfNames.Length; i++)
                {
                    newPdfNames[i] = Guid.NewGuid().ToString() + ".pdf";
                    newPdfDocs[i] = new PDFDoc();
                }

                DocumentRepository documentData = new DocumentRepository();

                CurrentDocuments currentDocuments = documentData.GetCurrentDocumentPathPdf(Utility.GetUserName());
                string[] currentDocumentCount = currentDocuments.CurrentDocumentList.Split('~');
                string[] currentDocumentList = currentDocumentCount[0].Split('\\');

                string pathToCurrentPdfFile = currentDocuments.PathToCurrentPdfDocument;

                string currentPdfPath = currentDocumentCount[0].Replace(currentDocumentList[currentDocumentList.Length - 1], "");

                PDFDoc separatePagesFromDocument = new PDFDoc(pathToCurrentPdfFile);

                for (int i = 0; i < pagesSeparationGroups.Length - 1; i++)
                {
                    string[] beginEndPageValues = pagesSeparationGroups[i].Split(',');

                    string pagesSeparationBegin = beginEndPageValues[0];
                    string pagesSeparationEnd = beginEndPageValues[1];

                    if (pagesSeparationBegin.Length > 0)
                    {
                        newPdfDocs[i].InsertPages(0, separatePagesFromDocument, int.Parse(pagesSeparationBegin), int.Parse(pagesSeparationEnd), PDFDoc.InsertFlag.e_none);
                        //newPdfDocs[i].Save(ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\" + newPdfNames[i], 0);
                        newPdfDocs[i].Save(currentPdfPath + newPdfNames[i], 0);
                    }
                }

                separatePagesFromDocument.Close();
                separatePagesFromDocument.Dispose();
                File.Delete(currentDocumentCount[0]);


                for (int i = 0; i < newPdfNames.Length; i++)
                {
                    newPdfDocs[i].Close();
                    newPdfDocs[i].Dispose();
                }

                string[] deleteTheDocumentList = currentDocuments.CurrentDocumentList.Split('~');
                for (int i = 0; i < deleteTheDocumentList.Length - 1; i++)
                {
                    try
                    {
                        File.Delete(ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\" + deleteTheDocumentList[i]);
                    }
                    catch { }
                }
                // ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\"
                return Ok();
            }
            catch
            {
                return BadRequest("Error in splitting document.  Please try again");
            }
        }
        // GET: api/FileFromFolder/5
        public HttpResponseMessage Get(string id)
        {
            string fullPath = System.Configuration.ConfigurationManager.AppSettings["holdFolder"] + id;

            PDFNet.Initialize("CT Orthopaedic Specialists(ct-ortho.com):ENTCPU:1::W:AMS(20160714):DF4FD2223CBF58B9128E100F400DD2BC2BFD701DC22C3C2E6D83F6B6F5C7");
            PDFDoc documentToAdd = new PDFDoc();
            string xodFileName = Guid.NewGuid().ToString() + ".xod";
            string pdfFileName = xodFileName.Replace(".xod", ".pdf");

            string filePathXod = ConfigurationValues.PathToXodFile + xodFileName;
            string filePathPdf = ConfigurationValues.PathToXodFile + pdfFileName;
            PDFDoc newDocument = new PDFDoc();

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    File.Delete(filePathXod);
                }
                catch { }
                File.Create(filePathXod).Dispose();
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(filePathXod, FileMode.Open);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = ConfigurationValues.XodFileName
                };
                return result;
            }
            else
            {
                string[] documents = id.Split('~');

                documentToAdd = new PDFDoc(fullPath);
                PageIterator itr = documentToAdd.GetPageIterator();
                for (; itr.HasNext(); itr.Next())
                {
                    try
                    {
                        pdftron.PDF.Page page = itr.Current();
                        newDocument.PageInsert(newDocument.GetPageIterator(itr.GetPageNumber()), page);
                    }
                    catch (Exception er)
                    {
                        string s1 = er.ToString();
                    }
                }
                try
                {
                    File.Delete(filePathXod);
                }
                catch { }

                documentToAdd.Close();
                documentToAdd.Dispose();
                DocumentRepository documentData = new DocumentRepository();
                documentData.AddUpdateCurrentDocument(Utility.GetUserName(), filePathXod, filePathPdf, id, documentData.GetFullPathToDocument(Utility.GetUserName()));
                File.Create(filePathXod).Dispose();
                newDocument.Save(filePathPdf, 0);
                pdftron.Filters.Filter objFilter = pdftron.PDF.Convert.ToXod(newDocument);
                System.Threading.Thread.Sleep(ConfigurationValues.XodSaveDelay);
                objFilter.WriteToFile(filePathXod, true);
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(filePathXod, FileMode.Open);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = ConfigurationValues.XodFileName
                };
                newDocument.Close();
                newDocument.Dispose();
                return result;
            }
        }
        // GET: api/SeparatePDF/5
        public HttpResponseMessage Get(string id)
        //public string Get(string id)
        {
            id = id + ",";
            PDFNet.Initialize("CT Orthopaedic Specialists(ct-ortho.com):ENTCPU:1::W:AMS(20160714):DF4FD2223CBF58B9128E100F400DD2BC2BFD701DC22C3C2E6D83F6B6F5C7");
            PDFDoc newDocument = new PDFDoc();
            string[] pagesSeparationGroups = id.Split(',');
            string[] newPDFNames = new string[pagesSeparationGroups.Length - 1];
            PDFDoc[] NewPDFDocs = new PDFDoc[pagesSeparationGroups.Length - 1];
            //string pathToCurrentPdfFile = documentData.GetCurrentDocumentPathPDF(Utility.GetUserName());

            for (int i = 0; i < newPDFNames.Length; i++)
            {
                newPDFNames[i] = Guid.NewGuid().ToString() + ".pdf";
                NewPDFDocs[i] = new PDFDoc();
            }

            DocumentRepository documentData = new DocumentRepository();
            //int pageCount = 0;

            CurrentDocuments currentDocuments = documentData.GetCurrentDocumentPathPDF(Utility.GetUserName());
            string pathToCurrentPdfFile = currentDocuments.PathToCurrentPDFDocument;

            //string[] fileName = pathToCurrentPdfFile.Split('\\');

            //File.Move(pathToCurrentPdfFile, ConfigurationValues.TemporaryFaxPath + "\\" + pathToCurrentPdfFile[pathToCurrentPdfFile.Length - 1]);
            PDFDoc separatePagesFromDocument = new PDFDoc(pathToCurrentPdfFile);

            for (int i = 0; i < pagesSeparationGroups.Length - 1; i++)
            {
                string[] pagesSeparation = pagesSeparationGroups[i].Split('-');

                //PageIterator itr = separatePagesFromDocument.GetPageIterator(i);
                NewPDFDocs[i].InsertPages(0, separatePagesFromDocument, int.Parse(pagesSeparation[0]), int.Parse(pagesSeparation[1]), PDFDoc.InsertFlag.e_none);
                NewPDFDocs[i].Save(ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\" + newPDFNames[i], 0);
            }

            //            string pathToCurrentPdfFileTemp = pathToCurrentPdfFile.Replace(".pdf", "temp.pdf");
            //string pathToCurrentXodFile = documentData.GetCurrentDocumentPathXOD(Utility.GetUserName());
            separatePagesFromDocument.Close();
            separatePagesFromDocument.Dispose();
            File.Delete(pathToCurrentPdfFile);


            for (int i = 0; i < newPDFNames.Length; i++)
            {
                NewPDFDocs[i].Close();
                NewPDFDocs[i].Dispose();
            }

            string[] deleteTheDocumentList = currentDocuments.CurrentDocumentList.Split('~');
            for (int i = 0; i < deleteTheDocumentList.Length - 1; i++)
            {
                File.Delete(ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\" + deleteTheDocumentList[i]);
            }
           // ConfigurationValues.OutboundFaxDirectory + "\\" + Utility.GetUserName() + "\\"


            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            return result;
        }