PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 20, 2019 4:52 am

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Txt to pdf in vb.net
PostPosted: Mon Apr 02, 2018 12:39 am 

Joined: Mon Apr 02, 2018 12:15 am
Posts: 1
I am trying to write a simple vb.net program to convert text files to pdfs. The pgm creates the correct number of pages but displays all the text on the first page of the pdf. What am I missing? Thanks!

Code follows:

Imports System.IO
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf

Public Class Form1
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim line As String
            Dim readFile As System.IO.TextReader = New StreamReader("c:\a\Test.txt")
            Dim yPoint As Integer = 0

            Dim pdf As PdfDocument = New PdfDocument
            pdf.Info.Title = "Text File to PDF"

            Dim pdfPage As PdfPage = pdf.AddPage
            Dim graph As XGraphics = XGraphics.FromPdfPage(pdfPage)

            Dim font As XFont = New XFont("courier new", 10, XFontStyle.Regular)


            line = readFile.ReadLine()
            If line Is Nothing Then GoTo AllDone :
            If line <> Chr(12) Then GoTo Page1

            yPoint = 0

            ' pdfPage = pdf.
            pdfPage = pdf.AddPage()

            graph.DrawString(line, font, XBrushes.Black,
            New XRect(10, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
            yPoint = yPoint + 10
            GoTo nextline


            Dim pdfFilename As String = "c:\a\newpdf.pdf"
            readFile = Nothing
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    End Sub
End Class

Reply with quote  
 Post subject: Re: Txt to pdf in vb.net
PostPosted: Mon Apr 02, 2018 6:37 am 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 467
Location: CCAA
Ballwin wrote:
What am I missing?
You missed that the Sample forum is for good code that works.

You missed that the XGraphics class does the drawing - you only create such an object for the first page, so all drawing goes there.

Best regards
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

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

All times are UTC

Who is online

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