Register   |  Login

Sample: PdfToText

   Minimize
  PdfToText Reader Sample for C# / VB.NET


Download the sample here
 
[C#]
PdfDocumentBuilder builder = new PdfDocumentBuilder();
IPdfDocument pdfDoc = builder.CreateDocument();
IPdfPage page = pdfDoc.Pages.AddNew();
IPdfGraphics g = page.Graphics;
IPdfBrush b = PdfBrushFactory.Black;
IPdfFont f = builder.FontFactory.CreateStandardFont(PdfStandardFontFamilies.Helvetica, 20f);
for (int i = 0; i < 100; i++)
  g.DrawString("Hello world!", f, b, new PointF(20, 20 * i));
pdfDoc.Save(fileName);
using (PdfTextReader r = new PdfTextReader(fileName))
{
      System.Console.WriteLine(r.ReadToEnd());
}
[VB.NET]

Dim builder As New PdfDocumentBuilder()
Dim pdfDoc As IPdfDocument = builder.CreateDocument()

Dim page As IPdfPage = pdfDoc.Pages.AddNew()
Dim g As IPdfGraphics = page.Graphics
Dim b As IPdfBrush = PdfBrushFactory.Black

Dim f As IPdfFont = builder.FontFactory.CreateStandardFont(PdfStandardFontFamilies.Helvetica, 20.0F)

For i As Integer = 0 To 99
    g.DrawString("Hello world!", f, b, New PointF(20, 20 * i))
Next

If System.IO.File.Exists(fileName) Then
    System.IO.File.Delete(fileName)
End If

pdfDoc.Save(fileName)

Dim r As PdfTextReader = New PdfTextReader(fileName)

System.Console.WriteLine(r.ReadToEnd())