private List <string> GetDocumentPages(string file, string folderName, int currentPage) { List <string> lstOutput = new List <string>(); string outfileName = "page_{0}"; string outPath = Config.Configuration.OutputDirectory + folderName + "/" + outfileName; currentPage = currentPage - 1; Directory.CreateDirectory(Config.Configuration.OutputDirectory + folderName); string imagePath = string.Format(outPath, currentPage) + ".jpeg"; if (System.IO.File.Exists(imagePath) && currentPage > 0) { lstOutput.Add(imagePath); return(lstOutput); } int i = currentPage; var filename = System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file) ? Config.Configuration.WorkingDirectory + folderName + "/" + file : Config.Configuration.OutputDirectory + folderName + "/" + file; using (FilePathLock.Use(filename)) { try { Aspose.Note.Live.Demos.UI.Models.License.SetAsposeNoteLicense(); // Load the document from disk. Aspose.Note.Document doc = new Aspose.Note.Document(filename); Aspose.Note.Saving.ImageSaveOptions options = new Aspose.Note.Saving.ImageSaveOptions(Aspose.Note.SaveFormat.Jpeg); // Save each page of the document as image. options.PageIndex = currentPage; doc.Save(imagePath, options); lstOutput.Add(doc.GetChildNodes <Aspose.Note.Page>().Count.ToString()); lstOutput.Add(imagePath); return(lstOutput); } catch (Exception ex) { throw ex; } } }
protected Response Process(string controllerName, string fileName, string folderName, string outFileExtension, bool createZip, bool checkNumberofPages, string methodName, ActionDelegate action, bool deleteSourceFolder = true, string zipFileName = null) { string guid = Guid.NewGuid().ToString(); string outFolder = ""; string sourceFolder = Aspose.App.Live.Demos.UI.Config.Configuration.WorkingDirectory + folderName; fileName = sourceFolder + "\\" + fileName; string fileExtension = Path.GetExtension(fileName).ToLower(); // Check if tiff file have more than one number of pages to create zip file or not if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeImagingConversionController") && (Path.GetExtension(fileName).ToLower() == ".tiff" || Path.GetExtension(fileName).ToLower() == ".tif")) { // Get the frame dimension list from the image of the file and Image _image = Image.FromFile(fileName); // Get the globally unique identifier (GUID) Guid objGuid = _image.FrameDimensionsList[0]; // Create the frame dimension FrameDimension dimension = new FrameDimension(objGuid); // Gets the total number of frames in the .tiff file int noOfPages = _image.GetFrameCount(dimension); createZip = noOfPages > 1; _image.Dispose(); } // Check word file have more than one number of pages or not to create zip file else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeWordsConversionController")) { Aspose.Words.Document doc = new Aspose.Words.Document(fileName); createZip = doc.PageCount > 1; } // Check presentation file have one or more slides to create zip file else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeSlidesAPIsController")) { Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(fileName); createZip = presentation.Slides.Count > 1; } // Check visio file have one or more pages to create zip file else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeDiagramConversionController")) { Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(fileName); createZip = diagram.Pages.Count > 1; } // Check email file have one or more pages to create zip file else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeEmailConversionController")) { Aspose.Email.MailMessage msg = Aspose.Email.MailMessage.Load(fileName); MemoryStream msgStream = new MemoryStream(); msg.Save(msgStream, Aspose.Email.SaveOptions.DefaultMhtml); Aspose.Words.Document document = new Aspose.Words.Document(msgStream); createZip = document.PageCount > 1; } //Check excel file have more than on workseets to create zip or not else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeCellsAPIsController") && (outFileExtension != ".svg")) { Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(fileName); createZip = workbook.Worksheets.Count > 1; } //Check note file have more than on pages to create zip or not else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeNoteConversionController")) { Aspose.Note.Document document = new Aspose.Note.Document(fileName); int count = document.GetChildNodes <Aspose.Note.Page>().Count; createZip = count > 1; } //Check pdf file have more than on pages to create zip or not else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposePdfConversionController")) { Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fileName); createZip = pdfDocument.Pages.Count > 1; } //Check excel file have more than on workseets to create zip or not else if ((checkNumberofPages) && (createZip) && (controllerName == "AsposeCellsAPIsController") && (outFileExtension == ".svg")) { Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(fileName); if (workbook.Worksheets.Count > 1) { createZip = true; } else { Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions(); imgOptions.OnePagePerSheet = true; Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(workbook.Worksheets[0], imgOptions); int srPageCount = sr.PageCount; createZip = srPageCount > 1; } } string outfileName = Path.GetFileNameWithoutExtension(fileName) + outFileExtension; string outPath = ""; string zipOutFolder = Aspose.App.Live.Demos.UI.Config.Configuration.OutputDirectory + guid; string zipOutfileName, zipOutPath; if (string.IsNullOrEmpty(zipFileName)) { zipOutfileName = guid + ".zip"; zipOutPath = Aspose.App.Live.Demos.UI.Config.Configuration.OutputDirectory + zipOutfileName; } else { var guid2 = Guid.NewGuid().ToString(); outFolder = guid2; zipOutfileName = zipFileName + ".zip"; zipOutPath = Aspose.App.Live.Demos.UI.Config.Configuration.OutputDirectory + guid2; Directory.CreateDirectory(zipOutPath); zipOutPath += "/" + zipOutfileName; } if (createZip) { outfileName = Path.GetFileNameWithoutExtension(fileName) + outFileExtension; outPath = zipOutFolder + "/" + outfileName; Directory.CreateDirectory(zipOutFolder); } else { outFolder = guid; outPath = Aspose.App.Live.Demos.UI.Config.Configuration.OutputDirectory + outFolder; Directory.CreateDirectory(outPath); outPath += "/" + outfileName; } string statusValue = "OK"; int statusCodeValue = 200; try { action(fileName, outPath, zipOutFolder); if (createZip) { ZipFile.CreateFromDirectory(zipOutFolder, zipOutPath); Directory.Delete(zipOutFolder, true); outfileName = zipOutfileName; } if (deleteSourceFolder) { System.GC.Collect(); System.GC.WaitForPendingFinalizers(); Directory.Delete(sourceFolder, true); } } catch (Exception ex) { statusCodeValue = 500; statusValue = "500 " + ex.Message; } return(new Response { FileName = outfileName, FolderName = outFolder, Status = statusValue, StatusCode = statusCodeValue, }); }
protected Response Process(string modelName, string fileName, string folderName, string outFileExtension, bool createZip, bool checkNumberofPages, string methodName, ActionDelegate action, bool deleteSourceFolder = true, string zipFileName = null) { string guid = Guid.NewGuid().ToString(); string outFolder = ""; string sourceFolder = Config.Configuration.WorkingDirectory + folderName; fileName = sourceFolder + "\\" + fileName; string fileExtension = Path.GetExtension(fileName).ToLower(); if ((checkNumberofPages) && (createZip) && (modelName == "AsposeNoteConversion")) { Aspose.Note.Document document = new Aspose.Note.Document(fileName); int count = document.GetChildNodes <Aspose.Note.Page>().Count; createZip = count > 1; } string outfileName = Path.GetFileNameWithoutExtension(fileName) + outFileExtension; string outPath = ""; string zipOutFolder = Config.Configuration.OutputDirectory + guid; string zipOutfileName, zipOutPath; if (string.IsNullOrEmpty(zipFileName)) { zipOutfileName = guid + ".zip"; zipOutPath = Config.Configuration.OutputDirectory + zipOutfileName; } else { var guid2 = Guid.NewGuid().ToString(); outFolder = guid2; zipOutfileName = zipFileName + ".zip"; zipOutPath = Config.Configuration.OutputDirectory + guid2; Directory.CreateDirectory(zipOutPath); zipOutPath += "/" + zipOutfileName; } if (createZip) { outfileName = Path.GetFileNameWithoutExtension(fileName) + outFileExtension; outPath = zipOutFolder + "/" + outfileName; Directory.CreateDirectory(zipOutFolder); } else { outFolder = guid; outPath = Config.Configuration.OutputDirectory + outFolder; Directory.CreateDirectory(outPath); outPath += "/" + outfileName; } string statusValue = "OK"; int statusCodeValue = 200; try { action(fileName, outPath, zipOutFolder); if (createZip) { ZipFile.CreateFromDirectory(zipOutFolder, zipOutPath); Directory.Delete(zipOutFolder, true); outfileName = zipOutfileName; } if (deleteSourceFolder) { System.GC.Collect(); System.GC.WaitForPendingFinalizers(); Directory.Delete(sourceFolder, true); } } catch (Exception ex) { statusCodeValue = 500; statusValue = "500 " + ex.Message; } return(new Response { FileName = outfileName, FolderName = outFolder, Status = statusValue, StatusCode = statusCodeValue, }); }