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:
Code:
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
Try
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)
nextline:
line = readFile.ReadLine()
If line Is Nothing Then GoTo AllDone :
If line <> Chr(12) Then GoTo Page1
yPoint = 0
' pdfPage = pdf.
pdfPage = pdf.AddPage()
Page1:
graph.DrawString(line, font, XBrushes.Black,
New XRect(10, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
yPoint = yPoint + 10
GoTo nextline
AllDone:
Dim pdfFilename As String = "c:\a\newpdf.pdf"
pdf.Save(pdfFilename)
readFile.Close()
readFile = Nothing
Process.Start(pdfFilename)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End
End Sub
End Class