Rozvrh.Exporters.ImportExport.DownloadAsBITMAP C# (CSharp) Метод

DownloadAsBITMAP() публичный Метод

Exports lectures to bitmap format.
public DownloadAsBITMAP ( List lectures, string title, System.DateTime created, string linkToInfo, string path, string format ) : System.Web.Mvc.FileResult
lectures List List of lectures.
title string Title displayed at top-left corner of the image.
created System.DateTime Date the timetable was created from config.
linkToInfo string Hyperlink to webpage with additional information.
path string Path to folder where temp files will be created and where Inkspace folder is.
format string Bitmap format to export ie. png jpg pdf
Результат System.Web.Mvc.FileResult
        public FileResult DownloadAsBITMAP(List<TimetableField> lectures, string title, DateTime created, string linkToInfo,
            string path, string format)
        {
            SvgGenerator gen = new SvgGenerator();
            string text = gen.generateSVG(lectures, title, created, linkToInfo);
            Guid id = Guid.NewGuid();
            string svgName = string.Format(@"{0}.svg", id);
            string svgFileName = path + svgName;
            using (StreamWriter outfile = new StreamWriter(svgFileName))
            {
                outfile.Write(text);
            }

            string expName = string.Format(@"{0}.{1}", id, format);
            string expFileName = path + expName;

            string inkscapeArgs = string.Format(@"-f ""{0}"" -w 1600 -h 728 -e ""{1}""", svgFileName, expFileName);
            string inkspacePath = path + "InkscapePortable/InkscapePortable.exe";

            Process inkscape = Process.Start(new ProcessStartInfo(inkspacePath, inkscapeArgs));

            inkscape.WaitForExit(3000);
            FileStream fs = File.OpenRead(expFileName);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            var res = new FileContentResult(data, "image/" + format);
            res.FileDownloadName = "FJFIRozvrh." + format;
            fs.Close();
            File.Delete(expFileName);
            File.Delete(svgFileName);
            return res;
        }

Usage Example

Пример #1
0
        public ActionResult ExportToPNG()
        {
            ImportExport instance = new ImportExport();

            return instance.DownloadAsBITMAP(M.CustomTimetableFields, M.SelectedTimetable.m_timetableInfo.TimetableLabel, M.SelectedTimetable.m_timetableInfo.Created,
                M.SelectedTimetable.m_timetableInfo.LinkToAdditionalInformation, Server.MapPath("~/App_Data/"), "png");
        }