PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jul 17, 2019 10:30 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue May 07, 2019 9:13 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 18
I am having problems getting started.
Trying the Hello World (VB version) I was able to figure out how to add the PDFsharp class by adding the dll file, but with out something to initiate the code it would not run, so I created a form with a button on it, however that caused an error:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
I commented the sub main as this caused even more errors.
Can you help me understand where I am going wrong. I am not very experienced so help would be appreciated.

Code:
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf

Module Program
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        ' 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


Top
 Profile  
Reply with quote  
PostPosted: Wed May 08, 2019 9:37 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2952
Location: Cologne, Germany
Creating a console application would be the simple approach without UI and without button.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri May 10, 2019 10:39 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 18
In copying the code into the button script, I missed out the Public Class Form1.
Also, removed the module declaration.
Problem solved!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group