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 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 Sample: HelloWorld
Modified on 2015/09/14 10:25
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationUpNext|PDFsharpSamples|HelloWorld-sample-VB} This sample is the obligatory '''Hello World''' program. It shows how to create a PDF document with one page and the text "Hello, World!" written in its center. Here is a similar Visual Basic .NET version of [HelloWorld-sample-VB|HelloWorld]. ==PDF Output File== See the PDF file created by this sample: {s:PdfLink|HelloWorld/HelloWorld.pdf|HelloWorld.pdf} (3 kB) ==Source Code== This is the whole source code needed to create the PDF file: {s:beginCsharp} using System; using System.Diagnostics; using System.IO; using PdfSharp; using PdfSharp.Drawing; using PdfSharp.Pdf; using PdfSharp.Pdf.IO; namespace HelloWorld { /// <summary> /// This sample is the obligatory Hello World program. /// </summary> class Program { static void Main(string[] args) { // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfPage page = document.AddPage(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); // Draw the text gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); // Save the document... const string filename = "HelloWorld.pdf"; document.Save(filename); // ...and start a viewer. Process.Start(filename); } } } {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
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