Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
150924 | Jan 24,2020 10:56 AM UTC | Jan 30,2020 05:54 PM UTC | ASP.NET MVC - EJ 2 | 7 |
![]() |
Tags: FileManager |
function onFileLoad(args) {
if (args.module == "LargeIconsView" && args.fileDetails.type == ".pdf") {
args.element.firstElementChild.removeChild(args.element.querySelectorAll(".e-list-icon.e-fe-pdf")[0]);
var dynamicImgEle = ej.base.createElement('img', {
className: "e-list-img",
attrs: { src: getImageUrl(this, args.fileDetails) }
});
args.element.firstElementChild.insertBefore(dynamicImgEle, args.element.firstElementChild.querySelectorAll(".e-list-text")[0]);
}
}
function getImageUrl(parent, item) {
var baseUrl = parent.ajaxSettings.getImageUrl ? parent.ajaxSettings.getImageUrl : parent.ajaxSettings.url;
var imgUrl;
var fileName = ej.base.getValue('name', item);
var fPath = ej.base.getValue('filterPath', item);
if (parent.hasId) {
// path contains ID while using ID based support
var imgId = ej.base.getValue('id', item);
imgUrl = baseUrl + '?path=' + parent.path + '&id=' + imgId;
} else if (fPath != null) {
// path is formed based on filter path while using search operation.
imgUrl = baseUrl + '?path=' + fPath.replace(/\\/g, '/') + fileName;
} else {
// If the image does not contains filter path, path is generated based on file name.
imgUrl = baseUrl + '?path=' + parent.path + fileName;
}
imgUrl = imgUrl + '&time=' + (new Date().getTime()).toString();
return imgUrl;
} |
public ActionResult GetImage(FileManagerDirectoryContent args)
{
//Validate the image files and return the correponding pdf or excel file first page thumbnail conversion image file
if (args.Path.Contains(".pdf"))
{
//return this.operation.GetImage(this.basePath + "\\" + this.path, null, false, null, null);
return operation.GetImage("/Pictures/Employees/1.png", null, false, null, null);
}
else
{
return operation.GetImage(args.Path, args.Id, false, null, null);
}
} |
//Validate the image files and return the correponding pdf or excel file first page thumbnail conversion image file
if (args.Path.Contains(".pdf"))
{
count = count + 1;
var path = HostingEnvironment.MapPath("~/Content/Files");
// Save the Image file path
var path1 = HostingEnvironment.MapPath("~/Content/Files/");
//Uses the Syncfusion.EJ2.PdfViewer assembly
PdfRenderer pdfExportImage = new PdfRenderer();
//Loads the PDF document
pdfExportImage.Load(path + (args.Path).Replace(@"/", @"\"));
//Exports the PDF document pages into images
// method parameters
// ExportAsImage (pageIndex , capture_image_width, capture_image_size)
Bitmap bitmapimage = pdfExportImage.ExportAsImage(0,200, 200);
//Save the exported image in disk
var ImageSave = path1 + count + ".png";
bitmapimage.Save(ImageSave);
ImageSave = ImageSave.Replace("\\", "/");
FileStream fileStreamInput = new FileStream(ImageSave, FileMode.Open, FileAccess.Read);
FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
// Return the image.
return fileStreamResult;
} |
Document Files |
Syncfusion.DocIO.AspNetMvc5, Syncfusion.OfficeChartToImageConverter.WPF,
Syncfusion.SfChart.WPF |
Excel Files |
Syncfusion.XlsIO.AspNet.MVC5 |
public ActionResult GetImage(FileManagerDirectoryContent args, string filename)
{
var path = HostingEnvironment.MapPath("~/Content/Files");
var path1 = HostingEnvironment.MapPath("~/Content");
//Validate the image files and return the correponding pdf or excel file first page thumbnail conversion image file
if (args.Path.Contains(".pdf"))
{
count = count + 1;
// Save the Image file path
//var path1 = HostingEnvironment.MapPath("~/Content/Files/");
//Uses the Syncfusion.EJ2.PdfViewer assembly
PdfRenderer pdfExportImage = new PdfRenderer();
//Loads the PDF document
pdfExportImage.Load(path + (args.Path).Replace(@"/", @"\"));
//Exports the PDF document pages into images
Bitmap bitmapimage = pdfExportImage.ExportAsImage(0,200, 200);
//Save the exported image in disk
var ImageSave = path1 + count + ".png";
bitmapimage.Save(ImageSave);
ImageSave = ImageSave.Replace("\\", "/");
FileStream fileStreamInput = new FileStream(ImageSave, FileMode.Open, FileAccess.Read);
FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
// Return the image.
return fileStreamResult;
}
else if(args.Path.Contains(".docx"))
{
count = 3;
WordDocument wordDocument = new WordDocument(path + (args.Path).Replace(@"/", @"\"), FormatType.Docx);
//Initializes the ChartToImageConverter for converting charts during Word to image conversion
wordDocument.ChartToImageConverter = new ChartToImageConverter();
//Sets the scaling mode for charts (Normal mode reduces the file size)
wordDocument.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Normal;
//Converts word document to image
Image[] images = wordDocument.RenderAsImages(Syncfusion.DocIO.DLS.ImageType.Bitmap);
var ImageSave = path1 + count + ".png";
images[0].Save(ImageSave, ImageFormat.Jpeg);
//Closes the document
ImageSave = ImageSave.Replace("\\", "/");
FileStream fileStreamInput = new FileStream(ImageSave, FileMode.Open, FileAccess.Read);
FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
// Return the image.
return fileStreamResult;
}
else if(args.Path.Contains(".xlsx"))
{
count = 4;
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
Syncfusion.XlsIO.IWorkbook workbook = application.Workbooks.Open(path + (args.Path).Replace(@"/", @"\"), ExcelOpenType.Automatic);
IWorksheet sheet = workbook.Worksheets[0];
var ImageSave = path1 + count + ".png";
//Convert as bitmap
Image image = sheet.ConvertToImage(1, 1, 10, 20);
image.Save(ImageSave, ImageFormat.Png);
ImageSave = ImageSave.Replace("\\", "/");
FileStream fileStreamInput = new FileStream(ImageSave, FileMode.Open, FileAccess.Read);
FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
// Return the image.
return fileStreamResult;
}
else
{
return operation.GetImage(args.Path, args.Id, false, null, null);
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.