Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- if (fileUpload.HasFile)
- {
- string ghostDllPath = HttpContext.Current.Server.MapPath("~/bin/External");
- GhostscriptRasterizer rasterizer = null;
- GhostscriptVersionInfo vesion = null;
- if (Environment.Is64BitProcess)
- vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"gsdll64.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
- else
- vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"gsdll32.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
- using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
- {
- rasterizer.Open(fileUpload.PostedFile.InputStream, vesion, false);
- if (rasterizer.PageCount > 0)
- {
- int dpi = 90;
- System.Drawing.Image img = rasterizer.GetPage(dpi, dpi, 1);
- using (MemoryStream ms = new MemoryStream())
- {
- string file = Guid.NewGuid().ToString() + ".png";
- img.Save(ms, ImageFormat.Png);
- Response.ContentType = "image/png";
- byte[] data = ms.ToArray();
- Response.OutputStream.Write(data, 0, data.Length);
- Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
- Response.Flush();
- }
- }
- rasterizer.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment