Guest User

Untitled

a guest
Jan 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public ActionResult GenerateReport(string Param)
  2. {
  3. // Create a new PDF document
  4. PdfDocument document = new PdfDocument();
  5. document.Info.Title = "Created with PDFsharp";
  6.  
  7. // Create an empty page
  8. PdfPage page = document.AddPage();
  9.  
  10. // Get an XGraphics object for drawing
  11. XGraphics gfx = XGraphics.FromPdfPage(page);
  12.  
  13. // Create a font
  14. XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
  15.  
  16. // Draw the text
  17. gfx.DrawString("Hello, World!", font, XBrushes.Black,
  18. new XRect(0, 0, page.Width, page.Height),
  19. XStringFormats.Center);
  20.  
  21. MemoryStream stream = new MemoryStream();
  22. document.Save(stream, false);
  23. byte[] bytes = stream.ToArray();
  24.  
  25. return File(bytes, "application/pdf");
  26. }
  27.  
  28. public ActionResult GenerateReport(string Param)
  29. {
  30. // same as before
  31. ....
  32.  
  33. // save your pdf to a file
  34. File.WriteAllBytes("result.pdf", memoryStream.ToArray());
  35.  
  36. // get url to that pdf which can be browsed
  37. var pdfUrl = "some location which url can browse";
  38.  
  39. return Json(new {url = pdfUrl}, JsonBehaviour.AllowGet);
  40. }
  41.  
  42. $.getJSON( "your GenerateReport url", function( data ) {
  43. window.open(data.url,'_blank');
  44. }
Add Comment
Please, Sign In to add comment