MigraDoc Made EZR: VB.NET Sample that creates PDF file

I revisited my VB.NET sample for MigraDoc, but this time achieving the same and more using my new MigraDoc Made EZR library. Achieve the same document, but with fewer lines of code. And in my humble opinion those lines are even easier to read (and to write).

Also see my VB.NET sample that uses MigraDoc directly. It explains how to get MigraDoc from NuGet and add references.

The Imports we need:

Imports MigraDoc.DocumentObjectModel
Imports MigraDocMadeEZ

And the sub Main() that does all the work:

Sub Main()
    Dim mez As MigraDocMadeEZR = New MigraDocMadeEZR

    mez.InfoAuthor = "TH Software"
    mez.InfoTitle = "Demo Document"
    ' Comment does not appear in the PDF file.
    mez.InfoComment = "Demontration of creating PDF files using MigraDoc Made EZR and VB.NET."
    mez.InfoKeywords = "Demontration of creating PDF files using MigraDoc Made EZR and VB.NET"
    mez.InfoSubject = "Demo Document"

    ' Properties set for "Normal" will be inherited by all other styles.
    mez.Style(StyleNames.Normal).Font("Book Antiqua")

    ' The font set for "Heading1" will be inherited by all other headings.
    mez.Style(StyleNames.Heading1).Font("Arial", 16).Bold(True)

    mez.AddHeading1("My Heading")

    mez.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. " & _
                 "Donec sodales nunc quis vehicula faucibus. Fusce cursus " & _
                 "fermentum magna, id porttitor nisi feugiat sit amet. Nunc " & _
                 "ligula purus, porta ac ligula id, placerat tempus est. " & _
                 "Duis mollis venenatis libero, eget luctus risus accumsan et. " & _
                 "Donec finibus ultricies lacus porta auctor. Etiam tristique " & _
                 "urna sit amet faucibus placerat. Mauris ut est vel urna " & _
                 "sodales bibendum a bibendum nisi. In condimentum odio eu " & _
                 "quam pretium, et feugiat est accumsan. Aenean lacinia massa " & _
                 "quam, sit amet rhoncus mauris pulvinar sed. Nullam sed lacus " & _
                 "a nunc interdum dignissim sed at nunc. Interdum et malesuada " & _
                 "fames ac ante ipsum primis in faucibus. Duis a sodales ex. " & _
                 "Nulla leo est, laoreet nec est a, mollis maximus dui.")

    ' Create a PDF and open it in the default viewer.
    mez.MakePdf("Demo1.pdf", True)
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *