PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How do I make my current page my PDF?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3221
Page 1 of 1

Author:  msterling [ Tue Oct 27, 2015 6:26 pm ]
Post subject:  How do I make my current page my PDF?

Hello

I want to use this product but have been yet to discern how to create a PDF document from the current page that I'm on? For example, in your Hello world example, I would think that on line #19 I would want to use the current document (the .aspx page that is the presentation of page for the C# code that I would be working on), to be my PDF page, not HelloWorld.pdf. How do I make my current page the PDF? Or how do I point to a specific page in my file directory structure to be the .pdf file that I'm creating?

14.class Program
15.{
16. static void Main(string[] args)
17. {
18. // Create a new PDF document
19. PdfDocument document = new PdfDocument(); <--I think here I would want to make this document be my current page (the .aspx page) that I'm doing the code behing for here.
20. document.Info.Title = "Created with PDFsharp";
21.
22. // Create an empty page
23. PdfPage page = document.AddPage();
24.
25. // Get an XGraphics object for drawing
26. XGraphics gfx = XGraphics.FromPdfPage(page);
27.
28. // Create a font
29. XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
30.
31. // Draw the text
32. gfx.DrawString("Hello, World!", font, XBrushes.Black,
33. new XRect(0, 0, page.Width, page.Height),
34. XStringFormats.Center);
35.
36. // Save the document...
37. const string filename = "HelloWorld.pdf";
38. document.Save(filename);
39. // ...and start a viewer.
40. Process.Start(filename);
41. }
42. }

Author:  TH-Soft [ Tue Oct 27, 2015 7:15 pm ]
Post subject:  Re: How do I make my current page my PDF?

Hi!

When creating an .aspx page, you probably don't want to create a PDF file on the file system, instead write the PDF file to a MemoryStream and return the byte array in the response.

See this example:
http://pdfsharp.net/wiki/Clock-sample.ashx

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/