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.Slides.Live.Demos.UI.Models.License.SetAsposeSlidesLicense(); // Load the document from disk. Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(filename); if (currentPage <= presentation.Slides.Count) { lstOutput.Add(presentation.Slides.Count.ToString()); i = 0; // Save each slide of the document as image. // Loop through all the slides foreach (var slide in presentation.Slides) { if (i == currentPage) { System.Drawing.Bitmap bitmap = slide.GetThumbnail(1.0f, 1.0f); if (bitmap != null) { bitmap.Save(imagePath); lstOutput.Add(imagePath); } } i++; } } } catch (Exception ex) { throw ex; } return(lstOutput); } }
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.Cells.Live.Demos.UI.Models.License.SetAsposeCellsLicense(); // Load the document from disk. Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(filename, new Aspose.Cells.LoadOptions()); Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions(); options.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg; Aspose.Cells.Rendering.WorkbookPrintingPreview workbookPrintingPreview = new Aspose.Cells.Rendering.WorkbookPrintingPreview(workbook, options); int pagesCounts = workbookPrintingPreview.EvaluatedPageCount; lstOutput.Add(pagesCounts.ToString()); Aspose.Cells.Rendering.WorkbookRender renderer = new Aspose.Cells.Rendering.WorkbookRender(workbook, options); if (renderer.PageCount > 0) { renderer.ToImage(currentPage, imagePath); lstOutput.Add(imagePath); } } catch (Exception ex) { throw ex; } return(lstOutput); } }
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 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.PSD.Live.Demos.UI.Models.License.SetAsposePSDLicense(); // Load the document from disk. Aspose.PSD.Image diagram = Aspose.PSD.Image.Load(Config.Configuration.WorkingDirectory + folderName + "/" + file); Aspose.PSD.ImageOptions.JpegOptions options = new Aspose.PSD.ImageOptions.JpegOptions(); options.Quality = 100; diagram.Save(imagePath, options); lstOutput.Add("1"); lstOutput.Add(imagePath); return(lstOutput); } catch (Exception ex) { throw ex; } } }
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 { if (!System.IO.File.Exists(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf")) { Aspose.Page.Live.Demos.UI.Models.License.SetAsposePageLicense(); System.IO.FileStream pdfStream = new System.IO.FileStream(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf", System.IO.FileMode.CreateNew, System.IO.FileAccess.Write); System.IO.FileStream psStream = new System.IO.FileStream(Config.Configuration.WorkingDirectory + folderName + "/" + file, System.IO.FileMode.Open, System.IO.FileAccess.Read); try { if (file.ToLower().EndsWith(".xps")) { Page.XPS.XpsDocument document = new XpsDocument(psStream, new Page.XPS.XpsLoadOptions()); Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions(); Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream, new Size(595, 842)); document.Save(device, options); } else { PsDocument document = new PsDocument(psStream); Aspose.Page.EPS.Device.PdfSaveOptions options = new Aspose.Page.EPS.Device.PdfSaveOptions(true); Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new Size(595, 842)); document.Save(device, options); } } finally { psStream.Close(); pdfStream.Close(); } } PdfConverter objConverter = new PdfConverter(); objConverter.BindPdf(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf"); objConverter.DoConvert(); objConverter.CoordinateType = PageCoordinateType.CropBox; if (currentPage < objConverter.PageCount) { lstOutput.Add(objConverter.PageCount.ToString()); i = 0; while (objConverter.HasNextImage() && i < objConverter.PageCount) { objConverter.StartPage = (currentPage + 1); objConverter.GetNextImage(imagePath, System.Drawing.Imaging.ImageFormat.Png); lstOutput.Add(imagePath); break; } } objConverter.Close(); } catch (Exception ex) { throw ex; } return(lstOutput); } }
public HttpResponseMessage DownloadDocument(string file, string folderName, bool isImage) { string outfileName = Path.GetFileNameWithoutExtension(file) + "_Out.zip"; string outPath; if (!isImage) { if (System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file)) { outPath = Config.Configuration.WorkingDirectory + folderName + "/" + file; } else { outPath = Config.Configuration.OutputDirectory + folderName + "/" + file; } } else { outPath = Config.Configuration.OutputDirectory + outfileName; } using (FilePathLock.Use(outPath)) { if (isImage) { if (System.IO.File.Exists(outPath)) { System.IO.File.Delete(outPath); } List <string> lst = GetDocumentPages(file, folderName, 1); if (lst.Count > 1) { int tmpPageCount = int.Parse(lst[0]); for (int i = 2; i <= tmpPageCount; i++) { GetDocumentPages(file, folderName, i); } } ZipFile.CreateFromDirectory(Config.Configuration.OutputDirectory + folderName + "/", outPath); } if ((!System.IO.File.Exists(outPath)) || !Path.GetFullPath(outPath).StartsWith(Path.GetFullPath(System.Web.HttpContext.Current.Server.MapPath("~/Assets/")))) { var exception = new HttpResponseException(HttpStatusCode.NotFound); throw exception; } try { using (var fileStream = new FileStream(outPath, FileMode.Open, FileAccess.Read)) { using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(ms.ToArray()) }; result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = (isImage ? outfileName : file) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return(result); } } } catch (Exception x) { Console.WriteLine(x.Message); } } return(null); }
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.CAD.Live.Demos.UI.Models.License.SetAsposeCADLicense(); // Load an existing CAD document Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(filename); // Create an instance of CadRasterizationOptions Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); // Set image width & height rasterizationOptions.PageWidth = 1024; rasterizationOptions.PageHeight = 1024; // Set the drawing to render at the center of image //rasterizationOptions.CenterDrawing = true; //rasterizationOptions.TypeOfEntities = Aspose.CAD.ImageOptions.TypeOfEntities.Entities3D; rasterizationOptions.AutomaticLayoutsScaling = true; rasterizationOptions.NoScaling = false; rasterizationOptions.ContentAsBitmap = true; // Set Graphics options rasterizationOptions.GraphicsOptions.SmoothingMode = Aspose.CAD.SmoothingMode.HighQuality; rasterizationOptions.GraphicsOptions.TextRenderingHint = Aspose.CAD.TextRenderingHint.AntiAliasGridFit; rasterizationOptions.GraphicsOptions.InterpolationMode = Aspose.CAD.InterpolationMode.HighQualityBicubic; // Get the layers in an instance of CadLayersDictionary var layersList = image.Layers; lstOutput.Add(layersList.Count.ToString()); i = 0; // Iterate over the layers foreach (var layerName in layersList.GetLayersNames()) { if (i == currentPage) { // Add the layer name to the CadRasterizationOptions's layer list rasterizationOptions.Layers[i] = layerName; // Create an instance of PngOptions for the resultant image Aspose.CAD.ImageOptions.JpegOptions options = new Aspose.CAD.ImageOptions.JpegOptions(); // Set rasterization options options.VectorRasterizationOptions = rasterizationOptions; image.Save(imagePath, options); lstOutput.Add(imagePath); image.Dispose(); break; } i++; } if (!image.Disposed) { image.Dispose(); } } catch (Exception ex) { throw ex; } return(lstOutput); } }
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.Tasks.Live.Demos.UI.Models.License.SetAsposeTasksLicense(); // Load the document from disk. Tasks.Project doc = new Aspose.Tasks.Project(filename); var taskSheets = doc.GetPageCount(Tasks.Visualization.PresentationFormat.TaskSheet); var taskUsages = doc.GetPageCount(Tasks.Visualization.PresentationFormat.TaskUsage); var resourceSheets = doc.GetPageCount(Tasks.Visualization.PresentationFormat.ResourceSheet); var ganttCharts = doc.GetPageCount(Tasks.Visualization.PresentationFormat.GanttChart); var pageFormats = new List <(Tasks.Visualization.PresentationFormat, int)>(); pageFormats.AddRange(Enumerable.Range(1, taskSheets).Select(x => (Tasks.Visualization.PresentationFormat.TaskSheet, x))); pageFormats.AddRange(Enumerable.Range(1, taskUsages).Select(x => (Tasks.Visualization.PresentationFormat.TaskUsage, x))); pageFormats.AddRange(Enumerable.Range(1, resourceSheets).Select(x => (Tasks.Visualization.PresentationFormat.ResourceSheet, x))); pageFormats.AddRange(Enumerable.Range(1, ganttCharts).Select(x => (Tasks.Visualization.PresentationFormat.GanttChart, x))); if (currentPage >= pageFormats.Count) { return(null); } var(format, index) = pageFormats[currentPage]; // create ImageS1aveOptions with desired format var options = new Aspose.Tasks.Saving.ImageSaveOptions(Aspose.Tasks.Saving.SaveFileFormat.JPEG) { // set quality JpegQuality = 100, PageSize = Tasks.Visualization.PageSize.A4, PresentationFormat = format, Pages = { index }, SaveToSeparateFiles = true }; // render project data to image format doc.Save(imagePath, options); lstOutput.Add(pageFormats.Count.ToString()); lstOutput.Add(imagePath); } catch (Exception ex) { throw ex; } return(lstOutput); } }