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.Diagram.Live.Demos.UI.Models.License.SetAsposeDiagramLicense(); // Load the document from disk. Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(filename); Aspose.Diagram.Saving.ImageSaveOptions options = new Aspose.Diagram.Saving.ImageSaveOptions(SaveFileFormat.JPEG); options.PageCount = 1; // Save each page of the document as image. options.PageIndex = currentPage; diagram.Save(imagePath, options); lstOutput.Add(diagram.Pages.Count.ToString()); lstOutput.Add(imagePath); return(lstOutput); } catch (Exception ex) { throw ex; } } }
private string ConvertDoc(string fileName, string fileNameWithOutExtension, string filePath, string fileDirectory, string outputType) { string outPath; var saveOpt = GetSaveOptions(outputType.Trim().ToLower()); var diagram = new Aspose.Diagram.Diagram(filePath); if ((diagram.Pages.Count > 1 && IsImage(outputType)) || saveOpt.SaveFileFormat == Aspose.Diagram.SaveFileFormat.HTML) { var zipOutFolder = Path.Combine(fileDirectory, fileNameWithOutExtension).TrimEnd(); var zipOutPath = zipOutFolder + ".zip"; Directory.CreateDirectory(zipOutFolder); if (saveOpt.SaveFileFormat == Aspose.Diagram.SaveFileFormat.HTML) { diagram.Save(Path.Combine(zipOutFolder, fileName), saveOpt.SaveFileFormat); } else { for (int index = 0; index < diagram.Pages.Count; index++) { if (saveOpt.SaveFileFormat == Aspose.Diagram.SaveFileFormat.SVG) { SVGSaveOptions opt = new SVGSaveOptions(); opt.PageIndex = index; diagram.Save(Path.Combine(zipOutFolder, diagram.Pages[index].Name + "." + outputType), opt); } else { ImageSaveOptions opt = new ImageSaveOptions(saveOpt.SaveFileFormat); opt.PageIndex = index; diagram.Save(Path.Combine(zipOutFolder, diagram.Pages[index].Name + "." + outputType), opt); } } } ZipFile.CreateFromDirectory(zipOutFolder, zipOutPath); Directory.Delete(zipOutFolder, true); outPath = zipOutPath; } else { outPath = Path.Combine(fileDirectory, fileName); diagram.Save(outPath, saveOpt.SaveFileFormat); } return(outPath); }
private static void GenerateDiagramPreview(int previewsFolderId, Stream docStream) { var document = new Aspose.Diagram.Diagram(docStream); if (StartIndex == 0) { SetPageCount(document.Pages.Count); } var firstIndex = 0; var lastIndex = 0; SetIndexes(StartIndex, document.Pages.Count, out firstIndex, out lastIndex, MaxPreviewCount); for (var i = firstIndex; i <= lastIndex; i++) { //if (!CheckActuality(file)) // break; try { using (var imgStream = new MemoryStream()) { var options = new Aspose.Diagram.Saving.ImageSaveOptions(Aspose.Diagram.SaveFileFormat.PNG) { PageIndex = i, Resolution = 300 }; document.Save(imgStream, options); if (imgStream.Length == 0) { continue; } SavePreviewAndThumbnail(imgStream, i + 1, previewsFolderId); } } catch (Exception ex) { Logger.WriteError(ContentId, i + 1, ex: ex, startIndex: StartIndex, version: Version); SaveEmptyPreview(i + 1, previewsFolderId); } } }
public Response Merge(Diagram[] visioDocs, string outputType) { Aspose.Diagram.Live.Demos.UI.Models.License.SetAsposeDiagramLicense(); Aspose.Diagram.Diagram dgs = visioDocs[0]; int iter = 0; foreach (var dg in visioDocs) { if (iter != 0) { dgs.Combine(dg); } iter++; } string folderName = Guid.NewGuid().ToString(); string fileName = "Merged document." + outputType.ToLower(); string strOutputFolder = Config.Configuration.OutputDirectory + folderName + "\\"; System.IO.Directory.CreateDirectory(strOutputFolder); string outpath = strOutputFolder + fileName; if (outputType.ToLower() == "vsdm") { dgs.Save(outpath, Aspose.Diagram.SaveFileFormat.VSDM); } else { dgs.Save(outpath, Aspose.Diagram.SaveFileFormat.VSDX); } return(new Response() { DownloadFileLink = outpath, FolderName = folderName, FileName = fileName, Status = "Ok", StatusCode = 200, FileProcessingErrorCode = FileProcessingErrorCode.OK }); }
private Result ImportFile(string filePath) { string xml = ""; if (Path.GetExtension(filePath) != ".vsdx") { Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(filePath); using (MemoryStream memoryStream = new MemoryStream()) { diagram.Save(memoryStream, Aspose.Diagram.SaveFileFormat.VSDX); memoryStream.Position = 0; xml = _zip.ReadXml(memoryStream); } } else { using (Stream stream = File.OpenRead(filePath)) { xml = _zip.ReadXml(stream); } } return(ResultFactory.buildSuccessResult("Success", xml)); }
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 WorkingDirectory = Aspose.Diagram.Live.Demos.UI.Config.Configuration.WorkingDirectory; string OutputDirectory = Aspose.Diagram.Live.Demos.UI.Config.Configuration.OutputDirectory; string sourceFolder = WorkingDirectory + folderName; fileName = sourceFolder + "\\" + fileName; string fileExtension = Path.GetExtension(fileName).ToLower(); if ((checkNumberofPages) && (createZip) && (modelName == "AsposeDiagramConversion")) { Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(fileName); createZip = diagram.Pages.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; // Log error message to NLogging database } return(new Response { FileName = outfileName, FolderName = outFolder, Status = statusValue, StatusCode = statusCodeValue, FileProcessingErrorCode = FileProcessingErrorCode.OK }); }