Exemple #1
0
        public List <DocStatusModel> GetAllDocStatus()
        {
            List <DocStatusModel> listDocument = new List <DocStatusModel>();

            using (MySqlConnection con = new MySqlConnection(connectionString))
            {
                MySqlCommand cmd = new MySqlCommand("select * from doc_status;", con);
                //cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                MySqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    DocStatusModel document = new DocStatusModel();
                    document.DocStatusID          = Convert.ToInt32(rdr["doc_status_ID"]);
                    document.DocStatusName        = String.IsNullOrEmpty(rdr["doc_status_name"].ToString()) ? "" : rdr["doc_status_name"].ToString();
                    document.DocStatusDescription = String.IsNullOrEmpty(rdr["doc_status_description"].ToString()) ? "" : rdr["doc_status_description"].ToString();
                    document.CreatedBy            = Convert.ToInt32(String.IsNullOrEmpty(rdr["created_by"].ToString()) ? "0" : rdr["created_by"].ToString());
                    document.UpdatedBy            = Convert.ToInt32(String.IsNullOrEmpty(rdr["updated_by"].ToString()) ? "0" : rdr["updated_by"].ToString());
                    document.CreatedAt            = String.IsNullOrEmpty(rdr["created_at"].ToString()) ? "" : rdr["created_at"].ToString();
                    document.UpdatedAt            = String.IsNullOrEmpty(rdr["updated_at"].ToString()) ? "" : rdr["updated_at"].ToString();

                    listDocument.Add(document);
                }
                con.Close();
            }
            return(listDocument);
        }
Exemple #2
0
        public IHttpActionResult ReplaceText(ReplaceTextModel replaceTextModel)
        {
            var documentFileName = System.IO.Path.Combine(Config.Configuration.WorkingDirectory, "Editor", replaceTextModel.documentId, "document.pdf");

            try
            {
                Document doc = new Document(documentFileName);

                // TODO: Imporve alghorithm
                //create TextAbsorber object to find all instances of the input search phrase
                //TextFragmentAbsorber textFragmentAbsorber =
                //    new TextFragmentAbsorber("(?i)" + replaceTextModel.txtFind, new TextSearchOptions(true))
                //    {
                //        TextReplaceOptions =
                //        {
                //            ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation
                //        }
                //    };

                TextFragmentAbsorber textFragmentAbsorber =
                    new TextFragmentAbsorber(replaceTextModel.txtFind);

                doc.Pages.Accept(textFragmentAbsorber);

                //get the extracted text fragments
                TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

                //loop through the fragments
                foreach (TextFragment textFragment in textFragmentCollection)
                {
                    //update text and other properties
                    textFragment.Text = replaceTextModel.txtReplace;
                }

                doc.Save(documentFileName);

                //doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf"));

                var downloadedMessageInfo = new DirectoryInfo(Path.GetDirectoryName(documentFileName));
                foreach (FileInfo file in downloadedMessageInfo.GetFiles("*.png"))
                {
                    file.Delete();
                }

                var model = new DocStatusModel
                {
                    d    = ImageConverter(documentFileName),
                    Path = replaceTextModel.documentId
                };

                return(Ok(replaceTextModel));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #3
0
        public IHttpActionResult CreateNewFile()
        {
            var guid       = Guid.NewGuid().ToString();
            var tempFolder = string.Format("{0}Editor\\{1}", Config.Configuration.WorkingDirectory.Replace("/", "\\"), guid);

            System.IO.Directory.CreateDirectory(tempFolder);
            var      fullPath = System.IO.Path.Combine(tempFolder, "document.pdf");
            Document doc      = new Document();

#if DEBUG
            var debugDocument = new Document(@"C:\Tmp\FormTest1.pdf");
            doc.Pages.Add(debugDocument.Pages);
#else
            doc.Pages.Add();
#endif
            doc.Save(fullPath);
            var model = new DocStatusModel
            {
                d    = ImageConverter(fullPath),
                Path = guid
            };
            return(Ok(model));
        }
Exemple #4
0
        public IHttpActionResult SearchClear(SearchDataModel searchDataModel)
        {
            //'searchText': moveTo, 'pageList': Npages, 'documentId': documentId
            var fullPath         = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", searchDataModel.documentId);
            var documentFileName = Path.Combine(fullPath, "document.pdf");
            //string name = DateTime.Now.Millisecond.ToString();
            var documentFolderInfo = new DirectoryInfo(fullPath);

            foreach (FileInfo file in documentFolderInfo.GetFiles("image*.png"))
            {
                file.Delete();
            }

            Document document = new Document(documentFileName);

            foreach (var page in document.Pages)
            {
                var annotations = page.Annotations.Where(a => a.AnnotationType == Pdf.Annotations.AnnotationType.Highlight).Cast <Pdf.Annotations.HighlightAnnotation>();
                foreach (var highlightAnnotation in annotations)
                {
                    if (highlightAnnotation.Title.Equals(searchMarker))
                    {
                        page.Annotations.Delete(highlightAnnotation);
                    }
                }
            }
            document.Save(documentFileName);
            var model = new DocStatusModel
            {
                d                = ImageConverter(documentFileName),
                Path             = searchDataModel.documentId,
                OriginalFileName = ""
            };

            return(Ok(model));
        }
Exemple #5
0
        public IHttpActionResult SearchData(SearchDataModel searchDataModel)
        {
            //'searchText': moveTo, 'pageList': Npages, 'documentId': documentId
            var fullPath         = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", searchDataModel.documentId);
            var documentFileName = Path.Combine(fullPath, "document.pdf");
            //string name = DateTime.Now.Millisecond.ToString();
            var documentFolderInfo = new DirectoryInfo(fullPath);

            foreach (FileInfo file in documentFolderInfo.GetFiles("image*.png"))
            {
                file.Delete();
            }

            Document             document             = new Document(documentFileName);
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchDataModel.searchText);

            textFragmentAbsorber.Visit(document);
            foreach (var textFragment in textFragmentAbsorber.TextFragments)
            {
                textFragment.Page.Annotations.Add(
                    new Pdf.Annotations.HighlightAnnotation(textFragment.Page, textFragment.Rectangle)
                {
                    Title = searchMarker
                }
                    );
            }
            document.Save(documentFileName);
            var model = new DocStatusModel
            {
                d                = ImageConverter(documentFileName),
                Path             = searchDataModel.documentId,
                OriginalFileName = ""
            };

            return(Ok(model));
        }
Exemple #6
0
        public IHttpActionResult Upload()
        {
            var httpRequest = HttpContext.Current.Request;
            var fullPath    = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", httpRequest.Form["documentId"]);

            var postedFile = httpRequest.Files[0];

            if (postedFile == null)
            {
                return(InternalServerError(new Exception("")));
            }

            if (httpRequest.Form["Opp"].StartsWith("uploading"))
            {
                var guid       = Guid.NewGuid().ToString();
                var tempFolder = string.Format("{0}Editor\\{1}", Config.Configuration.WorkingDirectory.Replace("/", "\\"), guid);
                Directory.CreateDirectory(tempFolder);
                var filePath = Path.Combine(tempFolder, "document.pdf");
                postedFile.SaveAs(filePath);
                var model = new DocStatusModel
                {
                    d                = ImageConverter(filePath),
                    Path             = guid,
                    OriginalFileName = postedFile.FileName
                };
                return(Ok(model));
            }
            else if (httpRequest.Form["Opp"].StartsWith("appending"))
            {
                string appPages   = httpRequest.Form["pages"];
                string appRatios  = httpRequest.Form["ratios"];
                string appHeights = httpRequest.Form["heights"];
                var    filePath   = Path.Combine(fullPath, "append.pdf");
                postedFile.SaveAs(filePath);
                var model = new DocStatusModel
                {
                    d    = AppendConverter(fullPath, appPages, appRatios, appHeights),
                    Path = httpRequest.Form["documentId"]
                };
                return(Ok(model));
            }
            else if (httpRequest.Form["Opp"].StartsWith("addAttachment"))
            {
                var documentFileName = Path.Combine(fullPath, "document.pdf");

                PdfContentEditor contentEditor = new PdfContentEditor();
                contentEditor.BindPdf(documentFileName);
                contentEditor.AddDocumentAttachment(postedFile.InputStream, postedFile.FileName, "File added by Aspose.PDF Editor");
                contentEditor.Save(documentFileName);

                return(Ok(new DocStatusModel
                {
                    d = postedFile.FileName,
                    Path = httpRequest.Form["documentId"]
                }));
            }
            else
            {
                //Or just save it locally
                var filePath = Path.Combine(fullPath, postedFile.FileName);
                postedFile.SaveAs(filePath);

                var model = new DocStatusModel
                {
                    d    = postedFile.FileName,
                    Path = httpRequest.Form["documentId"]
                };
                return(Ok(model));
            }
        }