Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteDocument(int id)
        {
            Document docDelete = await dr.GetByIdAsync(id);

            if (docDelete != null)
            {
                string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "documents", docDelete.Name + "." + docDelete.FileType);
                System.IO.File.Delete(filePath);
                await dr.DeleteByIdAsync(docDelete);
            }
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ConvertToPdf(int id)
        {
            Document docConvert = await dr.GetByIdAsync(id);

            docConvert.ToPdf();
            await dr.AddAsync(new Document
            {
                Name        = "Convert - " + docConvert.Name,
                FileType    = FileType.PDF,
                DirectoryId = 1
            });

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        public static void ToHtml(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".html");

            if (docConvert.FileType == FileType.PDF)
            {
                var pdfFile = new Aspose.Pdf.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                pdfFile.Save(pathSave, Aspose.Pdf.SaveFormat.Html);
            }
            else if (docConvert.FileType == FileType.DOCX || docConvert.FileType == FileType.DOC)
            {
                var docFile = new Aspose.Words.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                docFile.Save(pathSave, Aspose.Words.SaveFormat.Html);
            }
        }
Ejemplo n.º 4
0
        public static string CompareDocument(this Document doc1, Document doc2)
        {
            if (doc1.FileType != "docx" || doc2.FileType != "docx")
            {
                return("Cant Compare");
            }
            var             document1       = new Aspose.Words.Document(Path.Combine(GetPath(), doc1.Name + "." + doc1.FileType));
            var             document2       = new Aspose.Words.Document(Path.Combine(GetPath(), doc2.Name + "." + doc2.FileType));
            string          compareFileName = "Compare " + doc1.Name + " - " + doc2.Name + ".docx";
            var             documentCompare = new Aspose.Words.Document(Path.Combine(GetPath(), doc1.Name + "." + doc1.FileType));
            DocumentBuilder builder         = new DocumentBuilder(documentCompare);

            //TODO: extends compare (use Revision Document)
            document1.Compare(document2, "nhan1110i", DateTime.Now);
            document1.Save(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Temp", compareFileName));
            return(compareFileName);
        }
Ejemplo n.º 5
0
        public static void ToPdf(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".pdf");

            if (docConvert.FileType == FileType.DOCX || docConvert.FileType == FileType.DOC)
            {
                var wordFile = new Aspose.Words.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                wordFile.Save(pathSave, Aspose.Words.SaveFormat.Pdf);
            }
            else if (docConvert.FileType == FileType.HTML)
            {
                HTMLDocument htmlFile = new HTMLDocument(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));

                Converter.ConvertHTML(htmlFile, new Aspose.Html.Saving.PdfSaveOptions {
                    JpegQuality = 100
                }, pathSave);
            }
        }
Ejemplo n.º 6
0
        public async Task <FileResult> CompareDocument(int doc1, int doc2)
        {
            Document firstDocument = await dr.GetByIdAsync(doc1);

            Document secondDocument = await dr.GetByIdAsync(doc2);

            //var compareWord = new Aspose.Words.Document(firstDocument.CompareDocument(secondDocument));
            var result = new Document
            {
                Name     = firstDocument.CompareDocument(secondDocument),
                FileType = FileType.DOCX,
                Id       = 0
            };
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Temp", result.Name);

            byte[] file = System.IO.File.ReadAllBytes(filePath);
            return(File(file, "application/force-download", result.Name));
        }
Ejemplo n.º 7
0
        public static void ToWord(this Document docConvert)
        {
            var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".docx");

            if (docConvert.FileType == FileType.PDF)
            {
                var            pdfFile = new Aspose.Pdf.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                DocSaveOptions opt     = new DocSaveOptions()
                {
                    Format = DocSaveOptions.DocFormat.DocX
                };
                pdfFile.Save(pathSave, opt);
            }
            else if (docConvert.FileType == FileType.HTML)
            {
                var htmlFile = new HTMLDocument(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType));
                //TODO: convert
            }
        }