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
»
Back
PDFsharp Sample: HelloWorld (VB)
Modified on 2015/09/14 10:25
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|HelloWorld-sample|PDFsharpSamples|Graphics-sample} This sample is the obligatory '''Hello World''' program written in Visual Basic .NET. It shows how to create a PDF document with one page, two lines, an ellipse, and the text "Hello, World!" written in its center. Nearly all samples of PDFsharp are written in C#. This is because C# is the language PDFsharp itself is written in and we, the developers of PDFsharp, choose C# as our favorite language. If you like to write your code in Visual Basic .NET or in any other .NET language, you can of cause use PDFsharp as well. Here is a similar C# version of [HelloWorld-sample|Hello World]. ==PDF Output File== See the PDF file created by this sample: {s:PdfLink|HelloWorld-VB/HelloWorld-vb.pdf|HelloWorld-vb.pdf} (3 kB) ==Source Code== This is the whole Visual Basic .NET source code needed to create the PDF file: {s:beginVB} Imports PdfSharp Imports PdfSharp.Drawing Imports PdfSharp.Pdf Module Program ' VB.NET version of 'Hello World' Sub Main() ' Create a new PDF document Dim document As PdfDocument = New PdfDocument document.Info.Title = "Created with PDFsharp" ' Create an empty page Dim page As PdfPage = document.AddPage ' Get an XGraphics object for drawing Dim gfx As XGraphics = XGraphics.FromPdfPage(page) ' Draw crossing lines Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0)) gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point)) gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point)) ' Draw an ellipse gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5) ' Create a font Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold) ' Draw the text gfx.DrawString("Hello, World!", font, XBrushes.Black, _ New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center) ' Save the document... Dim filename As String = "HelloWorld.pdf" document.Save(filename) ' ...and start a viewer. Process.Start(filename) End Sub End Module {s:endVB} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
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