public ActionResult ViewDocument(ViewDocumentParameters request) { if (Utils.IsValidUrl(request.Path)) { request.Path = DownloadToStorage(request.Path); } var result = new ViewDocumentResponse { pageCss = new string[] { }, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), pdfPrintUrl = GetPdfPrintUrl(request), url = GetFileUrl(request), path = request.Path, name = Path.GetFileName(request.Path) }; if (request.UseHtmlBasedEngine) { ViewDocumentAsHtml(request, result); } else { ViewDocumentAsImage(request, result); } return(new LargeJsonResult { Data = result }); }
public override void ProcessRequest(HttpContext context) { try { JavaScriptSerializer serializer = new JavaScriptSerializer() { MaxJsonLength = CommonConstants.MaxJsonLength }; string json; bool isJsonP = context.Request.HttpMethod == "GET"; if (isJsonP) { json = context.Request.Params["data"]; } else { using (StreamReader streamReader = new StreamReader(context.Request.InputStream)) { json = streamReader.ReadToEnd(); } } ViewDocumentParameters parameters = serializer.Deserialize <ViewDocumentParameters>(json); OperationStatusResponse data = ViewDocument(_urlsCreator, parameters); string serializedData = serializer.Serialize(data); CreateJsonOrJsonpResponse(context, serializedData); } catch (Exception exception) { OnException(exception, context); } }
public static ViewDocumentResponse ViewDocument(ViewDocumentParameters request) { if (Utils.IsValidUrl(request.Path)) { request.Path = DownloadToStorage(request.Path); } else if (_streams.ContainsKey(request.Path)) { request.Path = SaveStreamToStorage(request.Path); } var fileName = Path.GetFileName(request.Path); var result = new ViewDocumentResponse { pageCss = new string[] { }, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), pdfPrintUrl = GetPdfPrintUrl(request), url = GetFileUrl(request), path = request.Path, name = fileName }; if (request.UseHtmlBasedEngine) { ViewDocumentAsHtml(request, result, fileName); } else { ViewDocumentAsImage(request, result, fileName); } return(result); }
public ActionResult ViewDocument(ViewDocumentParameters request) { string fileName = Path.GetFileName(request.Path); ViewDocumentResponse result = new ViewDocumentResponse { pageCss = new string[] { }, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), url = GetFileUrl(request), path = request.Path, name = fileName }; DocumentInfoContainer docInfo = annotator.GetDocumentInfo(request.Path); result.documentDescription = new FileDataJsonSerializer(docInfo.Pages).Serialize(true); result.docType = docInfo.DocumentType.ToLower(); result.fileType = docInfo.FileType.ToLower(); string applicationHost = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/'); var preloadCount = request.PreloadPagesCount; int pageCount = preloadCount ?? 1; int[] pageNumbers = new int[docInfo.Pages.Count]; for (int i = 0; i < pageNumbers.Length; i++) { pageNumbers[i] = i; } GetImageUrlsParameters imageUrlParameters = new GetImageUrlsParameters() { Path = request.Path, FirstPage = 0, PageCount = pageNumbers.Length, UsePdf = docInfo.Extension.ToLower().Equals("pdf"), Width = docInfo.Pages[0].Width, SupportPageRotation = false, UseHtmlBasedEngine = false }; result.imageUrls = GetImageUrls(applicationHost, pageNumbers, imageUrlParameters); //result.imageUrls = urls.ToArray(); JavaScriptSerializer serializer = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }; string serializedData = serializer.Serialize(result); // invoke event new DocumentOpenSubscriber().HandleEvent(request.Path); return(Content(serializedData, "application/json")); }
private static string GetPdfDownloadUrl(ViewDocumentParameters request) { return(GetFileUrl(request.Path, true, true, false, request.FileDisplayName, request.WatermarkText, request.WatermarkColor, request.WatermarkPosition, request.WatermarkWidth, request.IgnoreDocumentAbsence, request.UseHtmlBasedEngine, request.SupportPageRotation)); }
private static void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, string fileName) { var htmlHandler = (ViewerHtmlHandler)HttpContext.Current.Session["htmlHandler"]; var docInfo = htmlHandler.GetDocumentInfo(new DocumentInfoOptions(request.Path)); var maxWidth = 0; var maxHeight = 0; foreach (var pageData in docInfo.Pages) { if (pageData.Height > maxHeight) { maxHeight = pageData.Height; maxWidth = pageData.Width; } } var fileData = new FileData { DateCreated = DateTime.Now, DateModified = docInfo.LastModificationDate, PageCount = docInfo.Pages.Count, Pages = docInfo.Pages, MaxWidth = maxWidth, MaxHeight = maxHeight }; result.documentDescription = new FileDataJsonSerializer(fileData, new FileDataOptions()).Serialize(false); result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; var htmlOptions = new HtmlOptions { // IsResourcesEmbedded = Utils.IsImage(fileName), IsResourcesEmbedded = false, HtmlResourcePrefix = string.Format("/GetResourceForHtml.aspx?documentPath={0}", fileName) + "&pageNumber={page-number}&resourceName=", }; if (request.PreloadPagesCount.HasValue && request.PreloadPagesCount.Value > 0) { htmlOptions.PageNumber = 1; htmlOptions.CountPagesToConvert = request.PreloadPagesCount.Value; } List <string> cssList; var htmlPages = GetHtmlPages(fileName, htmlOptions, out cssList); result.pageHtml = htmlPages.Select(_ => _.HtmlContent).ToArray(); result.pageCss = new[] { string.Join(" ", cssList) }; }
private static Watermark GetWatermark(ViewDocumentParameters request) { if (string.IsNullOrWhiteSpace(request.WatermarkText)) { return(null); } return(new Watermark(request.WatermarkText) { Color = request.WatermarkColor.HasValue ? Color.FromArgb(request.WatermarkColor.Value) : Color.Red, Position = ToWatermarkPosition(request.WatermarkPosition), Width = request.WatermarkWidth }); }
public ActionResult ViewDocument(ViewDocumentParameters request) { try { if (Utils.IsValidUrl(request.Path)) { request.Path = DownloadToStorage(request.Path); } else if (_streams.ContainsKey(request.Path)) { request.Path = SaveStreamToStorage(request.Path); } var fileName = Path.GetFileName(request.Path); var result = new ViewDocumentResponse { pageCss = new string[] { }, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), pdfPrintUrl = GetPdfPrintUrl(request), url = GetFileUrl(request), path = request.Path, name = fileName }; if (request.UseHtmlBasedEngine) { ViewDocumentAsHtml(request, result, fileName); } else { ViewDocumentAsImage(request, result, fileName); } return(ToJsonResult(result)); } catch (Exception e) { return(this.JsonOrJsonP(new FailedResponse { Reason = e.Message }, null)); } }
private static void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result, string fileName) { var docInfo = _imageHandler.GetDocumentInfo(new DocumentInfoOptions(request.Path)); var maxWidth = 0; var maxHeight = 0; foreach (var pageData in docInfo.Pages) { if (pageData.Height > maxHeight) { maxHeight = pageData.Height; maxWidth = pageData.Width; } } var fileData = new FileData { DateCreated = DateTime.Now, DateModified = docInfo.LastModificationDate, PageCount = docInfo.Pages.Count, Pages = docInfo.Pages, MaxWidth = maxWidth, MaxHeight = maxHeight }; result.documentDescription = new FileDataJsonSerializer(fileData, new FileDataOptions()).Serialize(true); result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; DocumentInfoOptions documentInfoOptions = new DocumentInfoOptions(request.Path); DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions); int[] pageNumbers = new int[documentInfoContainer.Pages.Count]; for (int i = 0; i < documentInfoContainer.Pages.Count; i++) { pageNumbers[i] = documentInfoContainer.Pages[i].Number; } string applicationHost = GetApplicationHost(); result.imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, request); }
private static Watermark GetWatermark(ViewDocumentParameters request) { if (string.IsNullOrWhiteSpace(request.WatermarkText)) { return(null); } string hexString = request.WatermarkColor.ToString(); int red = int.Parse(hexString.Substring(1, 2), NumberStyles.HexNumber); int green = int.Parse(hexString.Substring(3, 2), NumberStyles.HexNumber); int blue = int.Parse(hexString.Substring(5, 2), NumberStyles.HexNumber); return(new Watermark(request.WatermarkText) { Color = request.WatermarkColor.HasValue ? Color.FromArgb(red, green, blue) : Color.Red, Position = ToWatermarkPosition(request.WatermarkPosition), Width = request.WatermarkWidth, }); }
private void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result) { var guid = request.Path; var fileName = Path.GetFileName(request.Path); // Get document info var documentInfo = _htmlHandler.GetDocumentInfo(guid); // Serialize document info SerializationOptions serializationOptions = new SerializationOptions { UsePdf = false, IsHtmlMode = true, SupportListOfBookmarks = request.SupportListOfBookmarks, SupportListOfContentControls = request.SupportListOfContentControls }; var documentInfoJson = new DocumentInfoJsonSerializer(documentInfo, serializationOptions).Serialize(); // Build html options var htmlOptions = new HtmlOptions { IsResourcesEmbedded = Utils.IsImage(fileName), HtmlResourcePrefix = GetHtmlResourcePrefix(guid), PageNumber = 1, CountPagesToRender = request.PreloadPagesCount.GetValueOrDefault(1) }; var htmlPageContents = GetHtmlPageContents(guid, htmlOptions); // Build result result.pageHtml = htmlPageContents .Select(_ => _.Html) .ToArray(); result.pageCss = htmlPageContents .Where(_ => !string.IsNullOrEmpty(_.Css)) .Select(_ => _.Css) .ToArray(); result.documentDescription = documentInfoJson; result.docType = documentInfo.DocumentType; result.fileType = GetFileTypeOrEmptyString(documentInfo.FileType); }
private void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result) { var guid = request.Path; // Get document info var documentInfo = _imageHandler.GetDocumentInfo(guid); // Serialize document info SerializationOptions serializationOptions = new SerializationOptions { UsePdf = request.UsePdf, SupportListOfBookmarks = request.SupportListOfBookmarks, SupportListOfContentControls = request.SupportListOfContentControls }; var documentInfoJson = new DocumentInfoJsonSerializer(documentInfo, serializationOptions) .Serialize(); // Build result result.documentDescription = documentInfoJson; result.docType = documentInfo.DocumentType; result.fileType = documentInfo.FileType; int[] pageNumbers = documentInfo.Pages.Select(_ => _.Number).ToArray(); result.imageUrls = ImageUrlHelper.GetImageUrls(GetApplicationHost(), pageNumbers, request); }
public HttpResponseMessage ViewDocument(ViewDocumentParameters parameters) { OperationStatusResponse data = _coreHandler.ViewDocument(this, parameters); return(CreateJsonOrJsonpResponse(data, parameters.Callback)); }
private static string GetFileUrl(ViewDocumentParameters request) { return(GetFileUrl(request.Path, true, false, false, request.FileDisplayName)); }
private static string GetPdfDownloadUrl(ViewDocumentParameters request) { return(GetFileUrl(request.Path, true, false, request.FileDisplayName, request.IgnoreDocumentAbsence, request.UseHtmlBasedEngine)); }
private void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, string fileName) { var docInfo = _htmlHandler.GetDocumentInfo(request.Path); var maxWidth = 0; var maxHeight = 0; foreach (var pageData in docInfo.Pages) { if (pageData.Height > maxHeight) { maxHeight = pageData.Height; maxWidth = pageData.Width; } } var fileData = new FileData { DateCreated = DateTime.Now, DateModified = docInfo.LastModificationDate, PageCount = docInfo.Pages.Count, Pages = docInfo.Pages, MaxWidth = maxWidth, MaxHeight = maxHeight }; var htmlOptions = new HtmlOptions() { IsResourcesEmbedded = false, HtmlResourcePrefix = string.Format( "/document-viewer/GetResourceForHtml?documentPath={0}", HttpUtility.UrlEncode(fileName)) + "&pageNumber={page-number}&resourceName=", Watermark = Utils.GetWatermark(request.WatermarkText, request.WatermarkColor, request.WatermarkPosition, request.WatermarkWidth, request.WatermarkOpacity), }; if (request.PreloadPagesCount.HasValue && request.PreloadPagesCount.Value > 0) { htmlOptions.PageNumber = 1; htmlOptions.CountPagesToRender = request.PreloadPagesCount.Value; } ///// List <string> cssList; var htmlPages = GetHtmlPages(fileName, htmlOptions, out cssList); foreach (AttachmentBase attachment in docInfo.Attachments) { var attachmentPath = _tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name; var attachmentHtmlOptions = new HtmlOptions() { IsResourcesEmbedded = Utils.IsImage(fileName), HtmlResourcePrefix = string.Format("/document-viewer/GetResourceForHtml?documentPath={0}", HttpUtility.UrlEncode(attachmentPath)) + "&pageNumber={page-number}&resourceName=", }; List <PageHtml> pages = _htmlHandler.GetPages(attachment, attachmentHtmlOptions); var attachmentInfo = _htmlHandler.GetDocumentInfo(attachmentPath); fileData.PageCount += attachmentInfo.Pages.Count; fileData.Pages.AddRange(attachmentInfo.Pages); List <string> attachmentCSSList; var attachmentPages = GetHtmlPages(attachmentInfo.Guid, attachmentHtmlOptions, out attachmentCSSList); cssList.AddRange(attachmentCSSList); htmlPages.AddRange(attachmentPages); } ///// result.documentDescription = new FileDataJsonSerializer(fileData, new FileDataOptions()).Serialize(false); result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; result.pageHtml = htmlPages.Select(_ => _.HtmlContent).ToArray(); result.pageCss = new[] { string.Join(" ", cssList) }; }
public ActionResult ViewDocument(ViewDocumentParameters request) { var fileName = Path.GetFileName(request.Path); var result = new ViewDocumentResponse { pageCss = new string[] {}, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), pdfPrintUrl = GetPdfPrintUrl(request), url = GetFileUrl(request), path = request.Path, name = fileName }; var docInfo = _imageHandler.GetDocumentInfo(new DocumentInfoOptions(request.Path)); result.documentDescription = new FileDataJsonSerializer(docInfo.Pages, new FileDataOptions()).Serialize(true); result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; var imageOptions = new ImageOptions { Watermark = GetWatermark(request) }; var imagePages = _imageHandler.GetPages(request.Path, imageOptions); // Provide images urls var urls = new List <string>(); // If no cache - save images to temp folder //var tempFolderPath = Path.Combine(Microsoft.SqlServer.Server.MapPath("~"), "Content", "TempStorage"); var tempFolderPath = Path.Combine(HttpContext.Server.MapPath("~"), "Content", "TempStorage"); foreach (var pageImage in imagePages) { var docFoldePath = Path.Combine(tempFolderPath, request.Path); if (!Directory.Exists(docFoldePath)) { Directory.CreateDirectory(docFoldePath); } var pageImageName = string.Format("{0}\\{1}.png", docFoldePath, pageImage.PageNumber); using (var stream = pageImage.Stream) using (FileStream fileStream = new FileStream(pageImageName, FileMode.Create)) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(fileStream); } var baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; urls.Add(string.Format("{0}Content/TempStorage/{1}/{2}.png", baseUrl, request.Path, pageImage.PageNumber)); } result.imageUrls = urls.ToArray(); var serializer = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }; var serializedData = serializer.Serialize(result); return(Content(serializedData, "application/json")); }
private static void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result, string fileName) { var docInfo = _imageHandler.GetDocumentInfo(request.Path); var maxWidth = 0; var maxHeight = 0; foreach (var pageData in docInfo.Pages) { if (pageData.Height > maxHeight) { maxHeight = pageData.Height; maxWidth = pageData.Width; } } var fileData = new FileData { DateCreated = DateTime.Now, DateModified = docInfo.LastModificationDate, PageCount = docInfo.Pages.Count, Pages = docInfo.Pages, MaxWidth = maxWidth, MaxHeight = maxHeight }; int[] pageNumbers = new int[docInfo.Pages.Count]; for (int i = 0; i < docInfo.Pages.Count; i++) { pageNumbers[i] = docInfo.Pages[i].Number; } string applicationHost = GetApplicationHost(); var documentUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, request); string[] attachmentUrls = new string[0]; foreach (AttachmentBase attachment in docInfo.Attachments) { List <PageImage> pages = _imageHandler.GetPages(attachment); var attachmentInfo = _imageHandler.GetDocumentInfo(_tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name); fileData.PageCount += pages.Count; fileData.Pages.AddRange(attachmentInfo.Pages); ViewDocumentParameters attachmentResponse = request; attachmentResponse.Path = attachmentInfo.Guid; int[] attachmentPageNumbers = new int[pages.Count]; for (int i = 0; i < pages.Count; i++) { attachmentPageNumbers[i] = pages[i].PageNumber; } Array.Resize <string>(ref attachmentUrls, (attachmentUrls.Length + pages.Count)); string[] attachmentImagesUrls = new string[pages.Count]; attachmentImagesUrls = ImageUrlHelper.GetImageUrls(applicationHost, attachmentPageNumbers, attachmentResponse); attachmentImagesUrls.CopyTo(attachmentUrls, (attachmentUrls.Length - pages.Count)); } SerializationOptions serializationOptions = new SerializationOptions { UsePdf = request.UsePdf, SupportListOfBookmarks = request.SupportListOfBookmarks, SupportListOfContentControls = request.SupportListOfContentControls }; var documentInfoJson = new DocumentInfoJsonSerializer(docInfo, serializationOptions).Serialize(); result.documentDescription = documentInfoJson; result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; if (docInfo.Attachments.Count > 0) { var imagesUrls = new string[attachmentUrls.Length + documentUrls.Length]; documentUrls.CopyTo(imagesUrls, 0); attachmentUrls.CopyTo(imagesUrls, documentUrls.Length); result.imageUrls = imagesUrls; } else { result.imageUrls = documentUrls; } }
private static void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, string fileName) { var htmlHandler = (ViewerHtmlHandler)HttpContext.Current.Session["htmlHandler"]; var docInfo = htmlHandler.GetDocumentInfo(request.Path); var maxWidth = 0; var maxHeight = 0; foreach (var pageData in docInfo.Pages) { if (pageData.Height > maxHeight) { maxHeight = pageData.Height; maxWidth = pageData.Width; } } var fileData = new FileData { DateCreated = DateTime.Now, DateModified = docInfo.LastModificationDate, PageCount = docInfo.Pages.Count, Pages = docInfo.Pages, MaxWidth = maxWidth, MaxHeight = maxHeight }; var htmlOptions = new HtmlOptions { // IsResourcesEmbedded = Utils.IsImage(fileName), IsResourcesEmbedded = false, HtmlResourcePrefix = string.Format("/GetResourceForHtml.aspx?documentPath={0}", fileName) + "&pageNumber={page-number}&resourceName=", }; if (request.PreloadPagesCount.HasValue && request.PreloadPagesCount.Value > 0) { htmlOptions.PageNumber = 1; htmlOptions.CountPagesToRender = request.PreloadPagesCount.Value; } List <string> cssList; var htmlPages = GetHtmlPages(fileName, fileName, htmlOptions, out cssList); foreach (AttachmentBase attachment in docInfo.Attachments) { var attachmentPath = _tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name; var attachmentResourcePath = HttpUtility.UrlEncode(_tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name.Replace(".", "_")); var attachmentHtmlOptions = new HtmlOptions() { IsResourcesEmbedded = Utils.IsImage(fileName), HtmlResourcePrefix = string.Format("/GetResourceForHtml.aspx?documentPath={0}", HttpUtility.UrlEncode(attachmentPath)) + "&pageNumber={page-number}&resourceName=", }; List <PageHtml> pages = _htmlHandler.GetPages(attachment, attachmentHtmlOptions); var attachmentInfo = _htmlHandler.GetDocumentInfo(attachmentPath); fileData.PageCount += attachmentInfo.Pages.Count; fileData.Pages.AddRange(attachmentInfo.Pages); List <string> attachmentCSSList; var attachmentPages = GetHtmlPages(attachmentPath, attachmentResourcePath, attachmentHtmlOptions, out attachmentCSSList); cssList.AddRange(attachmentCSSList); htmlPages.AddRange(attachmentPages); } SerializationOptions serializationOptions = new SerializationOptions { UsePdf = request.UsePdf, SupportListOfBookmarks = request.SupportListOfBookmarks, SupportListOfContentControls = request.SupportListOfContentControls }; var documentInfoJson = new DocumentInfoJsonSerializer(docInfo, serializationOptions).Serialize(); result.documentDescription = documentInfoJson; result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; result.pageHtml = htmlPages.Select(_ => _.HtmlContent).ToArray(); result.pageCss = new[] { string.Join(" ", cssList) }; }
public ActionResult ViewDocument(ViewDocumentParameters parameters) { OperationStatusResponse data = _coreHandler.ViewDocument(this, parameters); return CreateJsonOrJsonpResponse(data, parameters.Callback); }
public static string[] GetImageUrls(string applicationHost, int[] pageNumbers, ViewDocumentParameters parameters) { return(GetImageUrls(applicationHost, parameters.Path, 0, pageNumbers.Length, parameters.Width, parameters.Quality, parameters.UsePdf, parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkOpacity, parameters.WatermarkPosition, parameters.WatermarkWidth, parameters.IgnoreDocumentAbsence, parameters.UseHtmlBasedEngine, parameters.SupportPageRotation, parameters.InstanceIdToken, null, pageNumbers)); }
public ActionResult ViewDocument(ViewDocumentParameters request) { string fileName = Path.GetFileName(request.Path); ViewDocumentResponse result = new ViewDocumentResponse { pageCss = new string[] { }, lic = true, pdfDownloadUrl = GetPdfDownloadUrl(request), url = GetFileUrl(request), path = request.Path, name = fileName }; DocumentInfoContainer docInfo = annotator.GetDocumentInfo(request.Path); result.documentDescription = new FileDataJsonSerializer(docInfo.Pages).Serialize(true); result.docType = docInfo.DocumentType; result.fileType = docInfo.FileType; List <PageImage> imagePages = annotator.GetPages(request.Path); // Provide images urls List <string> urls = new List <string>(); // If no cache - save images to temp folder string tempFolderPath = Path.Combine(HttpContext.Server.MapPath("~"), "Content", "TempStorage"); foreach (PageImage pageImage in imagePages) { string docFoldePath = Path.Combine(tempFolderPath, request.Path); if (!Directory.Exists(docFoldePath)) { Directory.CreateDirectory(docFoldePath); } string pageImageName = string.Format("{0}\\{1}.png", docFoldePath, pageImage.PageNumber); using (Stream stream = pageImage.Stream) using (FileStream fileStream = new FileStream(pageImageName, FileMode.Create)) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(fileStream); } string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; urls.Add(string.Format("{0}Content/TempStorage/{1}/{2}.png", baseUrl, request.Path, pageImage.PageNumber)); } result.imageUrls = urls.ToArray(); JavaScriptSerializer serializer = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }; string serializedData = serializer.Serialize(result); // invoke event new DocumentOpenSubscriber().HandleEvent(request.Path); return(Content(serializedData, "application/json")); }