Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. protected void btnUpload_Click(object sender, EventArgs e)
  2. {
  3. if (fileUpload.HasFile)
  4. {
  5. string ghostDllPath = HttpContext.Current.Server.MapPath("~/bin/External");
  6. GhostscriptRasterizer rasterizer = null;
  7. GhostscriptVersionInfo vesion = null;
  8. if (Environment.Is64BitProcess)
  9. vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"gsdll64.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
  10. else
  11. vesion = new Ghostscript.NET.GhostscriptVersionInfo(new Version(0, 0, 0), ghostDllPath + @"gsdll32.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);
  12. using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
  13. {
  14. rasterizer.Open(fileUpload.PostedFile.InputStream, vesion, false);
  15. if (rasterizer.PageCount > 0)
  16. {
  17. int dpi = 90;
  18. System.Drawing.Image img = rasterizer.GetPage(dpi, dpi, 1);
  19. using (MemoryStream ms = new MemoryStream())
  20. {
  21. string file = Guid.NewGuid().ToString() + ".png";
  22. img.Save(ms, ImageFormat.Png);
  23. Response.ContentType = "image/png";
  24. byte[] data = ms.ToArray();
  25. Response.OutputStream.Write(data, 0, data.Length);
  26. Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
  27. Response.Flush();
  28. }
  29. }
  30. rasterizer.Close();
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment