public ActionResult GetFile(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); Stream fileStream; if (parameters.GetPdf) { displayName = Path.ChangeExtension(displayName, "pdf"); var getPdfFileRequest = new PdfFileOptions { Guid = parameters.Path, AddPrintAction = parameters.IsPrintable, Transformations = Transformation.Rotate | Transformation.Reorder, Watermark = GetWatermark(parameters), }; var pdfFileResponse = _htmlHandler.GetPdfFile(getPdfFileRequest); fileStream = pdfFileResponse.Stream; } else { var fileResponse = _htmlHandler.GetFile(parameters.Path); fileStream = fileResponse.Stream; } //jquery.fileDownload uses this cookie to determine that a file download has completed successfully Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true") { Path = "/" }); return File(GetBytes(fileStream), "application/octet-stream", displayName); }
private Watermark GetWatermark(GetFileParameters request) { if (string.IsNullOrWhiteSpace(request.WatermarkText)) return null; return new Watermark(request.WatermarkText) { Color = request.WatermarkColor.HasValue ? Color.FromArgb(request.WatermarkColor.Value) : (Color?)Color.Red, Position = ToWatermarkPosition(request.WatermarkPosition), Width = request.WatermarkWidth }; }
public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); var pdfFileOptions = new PdfFileOptions { Guid = parameters.Path, AddPrintAction = parameters.IsPrintable, Transformations = Transformation.Rotate | Transformation.Reorder, Watermark = GetWatermark(parameters), }; var response = _htmlHandler.GetPdfFile(pdfFileOptions); string contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString(); Response.AddHeader("Content-Disposition", contentDispositionString); return File(((MemoryStream)response.Stream).ToArray(), "application/pdf"); }