Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
Visit our new
Tailored Solutions & Support
site and find out how we can assist you.
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Back
PDFsharp: First Steps
Modified on 2009/08/12 12:05
by
Thomas Hövel
Categorized as
Articles
,
PDFsharp Articles
Both PDFsharp and MigraDoc provide a lot of AddXxx functions. Typically these functions return the newly created objects. Once you’ve learned the basic principles it’s quite easy to work with. Intellisense helps a lot then. And the new help system that integrates with the Visual Studio online help will provide information about any class in PDFsharp and MigraDoc – simply by hitting F1. ==PDFsharp - Getting Started== A good place to start is the Samples folder that comes with the source code. This wiki also shows the [PDFsharpSamples|PDFsharp Samples]. We’ll discuss a few lines of the [HelloWorld-sample|Hello World sample] here. You’ll need a PDF document: {s:beginCsharp} PdfDocument document = new PdfDocument(); {s:endCsharp} And you need a page: {s:beginCsharp} PdfPage page = document.AddPage(); {s:endCsharp} Drawing is done with an XGraphics object: {s:beginCsharp} XGraphics gfx = XGraphics.FromPdfPage(page); {s:endCsharp} Then you'll create a font: {s:beginCsharp} XFont font = new XFont("Verdana", 20, XFontStyle.Bold); {s:endCsharp} And you use that font to draw a string: {s:beginCsharp} gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormat.Center); {s:endCsharp} When drawing is done, write the file: {s:beginCsharp} string filename = "HelloWorld.pdf"; document.Save(filename); {s:endCsharp} A PC application might show the file: {s:beginCsharp} Process.Start(filename); {s:endCsharp} A web application would return the PDF file in an HTTP response. Look at our web samples how to do this. The [HelloWorld-sample|Hello World sample] is also available as an [HelloWorld-sample-VB|Visual Basic sample]. See also: [PDFsharpSamples|PDFsharp Samples]
Meta Keywords:
Meta Description:
Change Comment:
Visit our new
Tailored Solutions & Support
site and find out how we can assist you.
Visit the new
Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6
and find information about the new version for Windows, Linux, and other platforms.
Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles
ScrewTurn Wiki version 3.0.5.600. Some of the icons created by
FamFamFam
.
Impressum - Privacy Policy, Data Protection Declaration, Legal Notice