PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 02, 2024 5:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Oct 27, 2015 6:26 pm 
Offline

Joined: Tue Oct 27, 2015 6:14 pm
Posts: 1
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. }


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 27, 2015 7:15 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group