Exemple #1
0
        public ActionResult PdfToDoc(HttpPostedFileBase pdfFile)
        {
            if (pdfFile != null)
            {
                var outputStream = new MemoryStream();
                var fileName     = Path.GetFileNameWithoutExtension(pdfFile.FileName);
                var fileExt      = Path.GetExtension(pdfFile.FileName);
                if (fileExt == ".pdf")
                {
                    string uploadedPath;
                    if (SaveFile(pdfFile, out uploadedPath))
                    {
                        var document    = new Aspose.Pdf.Document(uploadedPath);
                        var saveOptions = new Aspose.Pdf.DocSaveOptions();
                        document.Save(outputStream, saveOptions);

                        outputStream.Position = 0;
                        return(File(outputStream, "application/msword", fileName + ".doc"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "File saving error : X001");
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "File format error : X002");
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        protected void Converter(string path, string extension)
        {
            switch (extension)
            {
            case ".pdf":
                Aspose.Pdf.Document       pdfDoc = new Aspose.Pdf.Document(path);
                Aspose.Pdf.DocSaveOptions opts   = new Aspose.Pdf.DocSaveOptions();
                opts.Format = Aspose.Pdf.DocSaveOptions.DocFormat.Doc;
                opts.Mode   = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow;
                pdfDoc.Save(HttpContext.Current.Server.MapPath("Convert/input.doc"), opts);
                // Load in the document
                Document docpdf = new Document(HttpContext.Current.Server.MapPath("Convert/input.doc"));

                docpdf.Range.Replace("\t", "\n", false, true);
                docpdf.Save(HttpContext.Current.Server.MapPath("Input/input.txt"));
                break;

            case ".doc":
            case ".docx":
            case ".txt":
            case ".rtf":
            {
                // Load in the document
                Document doc = new Document(path);
                doc.Save(HttpContext.Current.Server.MapPath("Input/input.txt"));
                break;
            }
            }
            ConvertDocument(HttpContext.Current.Server.MapPath("Input/input.txt"));
        }
Exemple #3
0
        protected void Converter(string path, string extension)
        {
            switch (extension)
            {
            case ".pdf":
                Aspose.Pdf.Document       pdfDoc = new Aspose.Pdf.Document(ExtensionClass.AttchmentFolder + "\\" + path);
                Aspose.Pdf.DocSaveOptions opts   = new Aspose.Pdf.DocSaveOptions();
                opts.Format = Aspose.Pdf.DocSaveOptions.DocFormat.Doc;
                opts.Mode   = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow;
                pdfDoc.Save(ApplicationSettings.Outputurl + "/output.doc", opts);
                // Load in the document
                Document docpdf = new Document(ApplicationSettings.Outputurl + "/output.doc");

                docpdf.Range.Replace("\t", "\n");
                docpdf.Save(ApplicationSettings.Outputurl + "/output.txt");
                break;

            case ".doc":
            case ".docx":
            case ".txt":
            case ".rtf":
            {
                // Load in the document
                Document doc = new Document(path);
                doc.Save(ApplicationSettings.Outputurl + "/output.doc");
                break;
            }
            }
            ConvertDocument(ApplicationSettings.Outputurl + "/output.doc");
        }
Exemple #4
0
        public Aspose.Words.Document convertirPDFBase64ADocx(String base64Pdf)
        {
            var binaryPdf = Convert.FromBase64String(base64Pdf);

            Aspose.Words.Document finalDoc = null;
            using (var pdfInput = new MemoryStream(binaryPdf))
            {
                Aspose.Pdf.Document       pdfDoc      = new Aspose.Pdf.Document(pdfInput);
                Aspose.Pdf.DocSaveOptions saveOptions = new Aspose.Pdf.DocSaveOptions();
                saveOptions.Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX;

                /*saveOptions.RasterImagesSavingMode = Aspose.Pdf.HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
                 * saveOptions.FontSavingMode = Aspose.Pdf.HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
                 * saveOptions.PartsEmbeddingMode = Aspose.Pdf.HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
                 * saveOptions.LettersPositioningMethod = Aspose.Pdf.HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
                 * saveOptions.SplitIntoPages = false;
                 * saveOptions.CustomHtmlSavingStrategy = new Aspose.Pdf.HtmlSaveOptions.HtmlPageMarkupSavingStrategy(SavingToStream);
                 */
                string tempFile = Path.GetTempFileName();
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
                pdfDoc.Save(tempFile, saveOptions);
                finalDoc = new Aspose.Words.Document(tempFile);
                File.Delete(tempFile);
            }
            return(finalDoc);
        }
Exemple #5
0
        ///<Summary>
        /// ConvertPdfToDoc to convert PDF to doc
        ///</Summary>
        public Response ConvertPdfToDoc(string fileName, string folderName, string userEmail, string type)
        {
            return(ProcessTask(fileName, folderName, "." + type, false, userEmail, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                // Open the source PDF document
                Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inFilePath);

                // Instantiate DocSaveOptions object
                Aspose.Pdf.DocSaveOptions saveOptions = new Aspose.Pdf.DocSaveOptions();
                type = type.ToLower();
                if (type == "docx")
                {
                    // Specify the output format as DOCX
                    saveOptions.Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX;
                }
                else if (type == "doc")
                {
                    // Specify the output format as DOC
                    saveOptions.Format = Aspose.Pdf.DocSaveOptions.DocFormat.Doc;
                }

                pdfDocument.Save(outPath, saveOptions);
            }));
        }
        public HttpResponseMessage Download(string fileName, string folderName, string outputType)
        {
            Opts.AppName    = "Viewer";
            Opts.FileName   = fileName;
            Opts.FolderName = folderName;
            Opts.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (Opts.FolderName.Contains(".."))
                {
                    throw new Exception("Break-in attempt");
                }

                if (string.IsNullOrEmpty(outputType))
                {
                    outputType = Path.GetExtension(Opts.FileName);
                }
                var fn         = Path.GetFileNameWithoutExtension(Opts.FileName) + outputType;
                var resultfile = Config.Configuration.OutputDirectory + Opts.FolderName + "/" + fn;
                if (!File.Exists(resultfile))
                {
                    if (string.IsNullOrEmpty(outputType) ||
                        Path.GetExtension(Opts.FileName).ToLower() == Path.GetExtension(outputType).ToLower())
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(resultfile));
                        File.Copy(Opts.WorkingFileName, resultfile);
                    }
                    else
                    {
                        var doc = new Document(Opts.WorkingFileName);
                        switch (outputType.ToLower())
                        {
                        case ".html":
                            var so = new Aspose.Pdf.HtmlSaveOptions()
                            {
                                DocumentType = Pdf.HtmlDocumentType.Html5,
                            };
                            doc.Save(resultfile, so);
                            break;

                        case ".docx":
                            var docSO = new Aspose.Pdf.DocSaveOptions()
                            {
                                Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX
                            };
                            doc.Save(resultfile, docSO);
                            break;

                        default:
                            doc.Save(resultfile);
                            break;
                        }
                    }
                }

                var response = new Response()
                {
                    FileName   = HttpUtility.UrlEncode(fn),
                    FolderName = Opts.FolderName,
                    StatusCode = 200
                };
                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                return(ExceptionResponse(ex));
            }
        }