public ActionResult Get(string file, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity, bool isdownload) { ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler(); Stream pdf = null; try { PdfFileOptions o = new PdfFileOptions(); if (watermarkText != "") { o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity); } pdf = handler.GetPdfFile(file, o).Stream; } catch (Exception x) { throw x; } if (isdownload) { Response.Headers.Add("content-disposition", "attachment; filename=" + Path.GetFileNameWithoutExtension(file) + ".pdf"); return(new FileStreamResult(pdf, "application/octet-stream")); } else { return(new FileStreamResult(pdf, "application/pdf")); } }
public static String GetPdfWithPrintDialog(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); var pdfFileOptions = new PdfFileOptions { // AddPrintAction = parameters.IsPrintable, Transformations = Transformation.Rotate | Transformation.Reorder, Watermark = GetWatermark(parameters), }; if (parameters.IsPrintable) { pdfFileOptions.Transformations |= Transformation.AddPrintAction; } var response = _htmlHandler.GetPdfFile(parameters.Path, pdfFileOptions); string contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString(); HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString); return(""); }
public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); var options = new PdfFileOptions { Guid = parameters.Path, Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth) }; if (parameters.IsPrintable) { options.AddPrintAction = true; } if (parameters.SupportPageRotation) { options.Transformations |= Transformation.Rotate; } options.Transformations |= Transformation.Reorder; var response = _htmlHandler.GetPdfFile(options); var contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString(); Response.AddHeader("Content-Disposition", contentDispositionString); return(File(((MemoryStream)response.Stream).ToArray(), "application/pdf")); }
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); }
public void ImageCreatePdfFileFromContentTest() { var file = TestFiles.PasswordProtectedDocx; var pdfFileOptions = new PdfFileOptions { Password = file.Password }; var request = new ImageCreatePdfFileFromContentRequest { PdfFileOptions = this.SerializeObject(pdfFileOptions), File = this.GetTestFileStream(file), FileName = null, FontsFolder = null, Folder = FromContentFolder, Storage = null }; var response = ViewerApi.ImageCreatePdfFileFromContent(request); Assert.IsNotEmpty(response.FileName); Assert.IsNotEmpty(response.Folder); Assert.IsNotEmpty(response.PdfFileName); Assert.IsNotEmpty(response.Url); }
public ActionResult GetFile(GetFileParameters parameters) { try { 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 options = new PdfFileOptions { Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth, parameters.WatermarkOpacity), }; if (parameters.IsPrintable) { options.Transformations |= Transformation.AddPrintAction; } if (parameters.SupportPageRotation) { options.Transformations |= Transformation.Rotate; } options.Transformations |= Transformation.Reorder; var pdfFileResponse = _htmlHandler.GetPdfFile(parameters.Path, options); 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 = "/" }); fileStream.Position = 0; using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); return(File(ms.ToArray(), "application/octet-stream", displayName)); } } catch (Exception e) { return(this.JsonOrJsonP(new FailedResponse { Reason = e.Message }, null)); } }
/// <summary> /// Initializes a new instance of the <see cref="ImageCreatePdfFileRequest"/> class. /// </summary> /// <param name="fileName">The file name.</param> /// <param name="pdfFileOptions">The PDF file rendering options.</param> /// <param name="fontsFolder">The folder with custom fonts in storage.</param> /// <param name="folder">The folder which contains specified file in storage.</param> /// <param name="storage">The file storage which have to be used.</param> public ImageCreatePdfFileRequest(string fileName, PdfFileOptions pdfFileOptions = null, string fontsFolder = null, string folder = null, string storage = null) { this.FileName = fileName; this.PdfFileOptions = pdfFileOptions; this.FontsFolder = fontsFolder; this.Folder = folder; this.Storage = storage; }
/// <summary> /// Initializes a new instance of the <see cref="HtmlCreatePdfFileFromUrlRequest"/> class. /// </summary> /// <param name="url">The URL to retrieve document.</param> /// <param name="pdfFileOptions">The PDF file rendering.</param> /// <param name="fileName">The file name.</param> /// <param name="fontsFolder">The folder with custom fonts in storage.</param> /// <param name="folder">The folder which contains specified file in storage.</param> /// <param name="storage">The file storage which have to be used.</param> public HtmlCreatePdfFileFromUrlRequest(string url, PdfFileOptions pdfFileOptions = null, string fileName = null, string fontsFolder = null, string folder = null, string storage = null) { this.Url = url; this.PdfFileOptions = pdfFileOptions; this.FileName = fileName; this.FontsFolder = fontsFolder; this.Folder = folder; this.Storage = storage; }
/// <summary> /// Render a document in PDF Form /// </summary> /// <param name="DocumentName"></param> public static void RenderDocumentAsPDF(String DocumentName) { //ExStart:RenderAsPdf // Create/initialize image handler ViewerImageHandler imageHandler = new ViewerImageHandler(Utilities.GetConfigurations()); //Initialize PdfFileOptions object PdfFileOptions options = new PdfFileOptions(); // Call GetPdfFile to get FileContainer type object which contains the stream of pdf file. FileContainer container = imageHandler.GetPdfFile(DocumentName, options); //Change the extension of the file and assign to a string type variable filename String filename = Path.GetFileNameWithoutExtension(DocumentName) + ".pdf"; //Save each image at disk Utilities.SaveFile(filename, container.Stream); //ExEnd:RenderAsPdf }
/// <summary> /// Multiple pages per sheet /// </summary> /// <param name="DocumentName"></param> public static void RenderMultiExcelSheetsInOnePage(String DocumentName) { // Setup GroupDocs.Viewer config ViewerConfig config = Utilities.GetConfigurations(); // Create image or html handler ViewerImageHandler imageHandler = new ViewerImageHandler(config); string guid = DocumentName; // Set pdf file one page per sheet option to false, default value of this option is true PdfFileOptions pdfFileOptions = new PdfFileOptions(); pdfFileOptions.Guid = guid; pdfFileOptions.CellsOptions.OnePagePerSheet = false; //Get pdf file FileContainer fileContainer = imageHandler.GetPdfFile(pdfFileOptions); Utilities.SaveFile("test.pdf", fileContainer.Stream); }
/// <summary> /// Get original file in Pdf format /// </summary> public static void Run() { Console.WriteLine("***** {0} *****", "Get original file in Pdf format"); /* ********************* SAMPLE ********************* */ // Setup GroupDocs.Viewer config ViewerConfig config = new ViewerConfig(); config.StoragePath = @"C:\storage"; // Create image handler ViewerImageHandler imageHandler = new ViewerImageHandler(config); PdfFileOptions options = new PdfFileOptions(); options.Guid = "word.doc"; // Get file as pdf FileContainer container = imageHandler.GetPdfFile(options); Console.WriteLine("Stream lenght: {0}", container.Stream.Length); }
public void HtmlCreatePdfFileFromUrl() { var file = TestFiles.FromUrlWithNotesPptx; var pdfFileOptions = new PdfFileOptions(); var request = new HtmlCreatePdfFileFromUrlRequest { Url = file.Url, PdfFileOptions = pdfFileOptions, FileName = null, FontsFolder = null, Folder = FromUrlFolder, Storage = null, }; var response = ViewerApi.HtmlCreatePdfFileFromUrl(request); Assert.IsNotEmpty(response.FileName); Assert.IsNotEmpty(response.Folder); Assert.IsNotEmpty(response.PdfFileName); }
public HttpResponseMessage Get(string file, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity, bool isdownload) { ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler(); Stream pdf = null; try { PdfFileOptions o = new PdfFileOptions(); if (watermarkText != "") { o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity); } pdf = handler.GetPdfFile(file, o).Stream; } catch (Exception x) { throw x; } using (var ms = new MemoryStream()) { pdf.CopyTo(ms); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(ms.ToArray()) }; if (isdownload) { result.Content.Headers.Add("content-disposition", "attachment; filename=\"" + Path.GetFileNameWithoutExtension(file) + ".pdf\""); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); } else { result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); } return(result); } }
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")); }
public static void Run() { // Setup GroupDocs.Viewer config ViewerConfig config = new ViewerConfig(); config.StoragePath = @"C:\storage"; // Create image or html handler ViewerImageHandler imageHandler = new ViewerImageHandler(config); string guid = "document.xlsx"; // Set pdf file one page per sheet option to false, default value of this option is true PdfFileOptions pdfFileOptions = new PdfFileOptions(); pdfFileOptions.Guid = guid; pdfFileOptions.CellsOptions.OnePagePerSheet = false; //Get pdf file FileContainer fileContainer = imageHandler.GetPdfFile(pdfFileOptions); //The pdf file stream Stream pdfStream = fileContainer.Stream; }
protected void Page_Load(object sender, EventArgs e) { var file = GetValueFromQueryString("file"); string watermarkText = GetValueFromQueryString("watermarkText"); int? watermarkColor = Convert.ToInt32(GetValueFromQueryString("watermarkColor")); WatermarkPosition watermarkPosition = (WatermarkPosition)Enum.Parse(typeof(WatermarkPosition), GetValueFromQueryString("watermarkPosition"), true); string widthFromQuery = GetValueFromQueryString("watermarkWidth"); int? watermarkWidth = GetValueFromQueryString("watermarkWidth") == "null" || GetValueFromQueryString("watermarkWidth") == "" ? null : (int?)Convert.ToInt32(GetValueFromQueryString("watermarkWidth")); byte watermarkOpacity = Convert.ToByte(GetValueFromQueryString("watermarkOpacity")); ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler(); Stream pdf = null; try { PdfFileOptions o = new PdfFileOptions(); if (watermarkText != "") { o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity); } pdf = handler.GetPdfFile(file, o).Stream; } catch (Exception x) { throw x; } using (var ms = new MemoryStream()) { pdf.CopyTo(ms); ms.WriteTo(HttpContext.Current.Response.OutputStream); Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileNameWithoutExtension(file) + ".pdf"); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } }
public void HtmlCreatePdfFile() { var file = TestFiles.PasswordProtectedDocx; var pdfFileOptions = new PdfFileOptions { Password = file.Password }; var request = new HtmlCreatePdfFileRequest { FileName = file.FileName, PdfFileOptions = pdfFileOptions, FontsFolder = null, Folder = file.Folder, Storage = null, }; var response = ViewerApi.HtmlCreatePdfFile(request); Assert.IsNotEmpty(response.FileName); Assert.IsNotEmpty(response.Folder); Assert.IsNotEmpty(response.PdfFileName); }
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)); }
protected void Page_Load(object sender, EventArgs e) { _config = new ViewerConfig { StoragePath = _storagePath, TempPath = _tempPath, UseCache = true }; _htmlHandler = new ViewerHtmlHandler(_config); _imageHandler = new ViewerImageHandler(_config); var parameters = (GetFileParameters)Session["fileparams"]; Session.RemoveAll(); var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); Stream fileStream; if (parameters.GetPdf || parameters.IsPrintable) { 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 HttpContext.Current.Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true") { Path = "/" }); byte[] Bytes = new byte[fileStream.Length]; fileStream.Read(Bytes, 0, Bytes.Length); string contentDispositionString = "attachment; filename=\"" + displayName + "\""; if (parameters.IsPrintable) { contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString(); } if (parameters.IsPrintable) { HttpContext.Current.Response.ContentType = "application/pdf"; } else { HttpContext.Current.Response.ContentType = "application/octet-stream"; } HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString); HttpContext.Current.Response.AddHeader("Content-Length", fileStream.Length.ToString()); HttpContext.Current.Response.OutputStream.Write(Bytes, 0, Bytes.Length); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }
public ActionResult GetFile(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); var guid = parameters.Path; Stream fileStream; if (parameters.GetPdf) { displayName = Path.ChangeExtension(displayName, "pdf"); var options = new PdfFileOptions(); options.Transformations |= Transformation.Reorder; if (!string.IsNullOrEmpty(parameters.WatermarkText)) options.Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth); if (parameters.IsPrintable) options.Transformations |= Transformation.AddPrintAction; if (parameters.SupportPageRotation) options.Transformations |= Transformation.Rotate; var pdfFileResponse = _htmlHandler.GetPdfFile(guid, options); fileStream = pdfFileResponse.Stream; } else { var fileResponse = _htmlHandler.GetFile(guid); fileStream = fileResponse.Stream; } //jquery.fileDownload uses this cookie to determine that a file download has completed successfully Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true") { Path = "/" }); fileStream.Position = 0; using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); return File(ms.ToArray(), "application/octet-stream", displayName); } }
public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters) { var displayName = string.IsNullOrEmpty(parameters.DisplayName) ? Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName); var guid = parameters.Path; var options = new PdfFileOptions(); options.Transformations |= Transformation.Reorder; if (!string.IsNullOrEmpty(parameters.WatermarkText)) options.Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth); if (parameters.IsPrintable) options.Transformations |= Transformation.AddPrintAction; if (parameters.SupportPageRotation) options.Transformations |= Transformation.Rotate; var response = _htmlHandler.GetPdfFile(guid, options); var contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString(); Response.AddHeader("Content-Disposition", contentDispositionString); return File(((MemoryStream)response.Stream).ToArray(), "application/pdf"); }
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"); }