title: VB.Net, how to detect end of page and continue writing on next page
body: <p>I have a VB.NET program that uses PDF Sharp to dump information to a PDF file.  The problem i'm having is I can't figure out how to jump to the next page if <code>ypoint</code> (length of the page) is at a certain value.  Indicated by ** before the if ** at the end if.  Below is a section of my pdf sharp dump.  I thought I could use an if then statement to increase a counter and add the variable to the end of the pdfpage... for example</p>
  
  <pre><code>pdfpage(ypointcounter)....
  </code></pre>
  
  <p>This doesn't work.  You'll see I tried separating the top portion (my heading), because I don't want to repeat that on the next page, and is not part of my loop through to dump the info from multiple datasets.  I know I can insert a new page, and I also know how to write to the second page.  What i'd like to do is setup the program, inside my loop, to automatically create the next page, and begin writing to it if i'm at the end of a page.  I assume I have to setup some sort of array?</p>
  
  <p>Any Help?</p>
  
  <p>My code is:</p>
  
  <pre><code>Try
  yPoint = 0
  
  Dim pdf As PdfDocument = New PdfDocument
  pdf.Info.Title = "Last Hour Comparison"
  Dim pdfPage As PdfPage = pdf.AddPage
  Dim pdfPage1 As PdfPage = pdf.AddPage
  Dim graph As XGraphics = XGraphics.FromPdfPage(pdfPage1)
  Dim fontheader As XFont = New XFont("Arial", 12, XFontStyle.Bold) ' I used this as a header.  Basically-
  'Just made the font bigger and style is BOLD
  Dim font As XFont = New XFont("Arial", 11, XFontStyle.Regular)
  
  'This sets the Header----------------------------------------------------------------------------
  
  graph.DrawString("Test Last Hour Comparison for week of " &amp; Weekstart, fontheader, XBrushes.Black, _
     New XRect(20, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  yPoint = yPoint + 40
  
  '---------------------------------
  'This is for building the Report ---------------------------------------------------------
  
  'If ds.Tables(0).Rows.Count &gt; 0 Then
  graph.DrawString("Location", font, XBrushes.Black, _
      New XRect(20, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  
  graph.DrawString("Date", font, XBrushes.Black, _
      New XRect(120, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  
  graph.DrawString("# 6-7 Visits ", font, XBrushes.Black, _
  New XRect(280, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  
  graph.DrawString("# 7-8 Visits ", font, XBrushes.Black, _
      New XRect(340, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  
  graph.DrawString("% Change ", font, XBrushes.Black, _
      New XRect(410, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft)
  Dim x As Integer
  x = 0
  LocationCounter = 1
  ypointcounter = 0
  **For i = 0 To 3
      GetLocation()
      yPoint = yPoint + 20
      If yPoint &gt; 840 Then
          yPoint = 20
          ypointcounter = ypointcounter + 1
  
  
      End If**
  
      graph.DrawString(LocationName, font, XBrushes.Black, _
      New XRect(20, yPoint, pdfPage(ypointcounter).Width.Point, pdfPage(ypointcounter).Height.Point), XStringFormats.TopLeft)
      dtstartdate = Today.AddDays(-6)
      firsthourweektotal = 0
      secondhourweektotal = 0
      For z = 0 To 6
          firsthour = ds.Tables(0).Rows(x).Item(0)
          secondhour = ds2.Tables(0).Rows(x).Item(0)
          firsthourweektotal = firsthourweektotal + ds.Tables(0).Rows(x).Item(0)
          secondhourweektotal = secondhourweektotal + ds2.Tables(0).Rows(x).Item(0)
          If ds.Tables(0).Rows(x).Item(0) = 0 Then
              Percentage = 0
          Else
              Percentage = Math.Round(ds2.Tables(0).Rows(x).Item(0) / ds.Tables(0).Rows(x).Item(0) * 100, 2)
          End If
  
          graph.DrawString(dtstartdate.DayOfWeek.ToString &amp; ", " &amp; dtstartdate.Month &amp; "/" &amp; dtstartdate.Day, font, XBrushes.Black, _
          New XRect(110, yPoint, pdfPage(ypointcounter).Width.Point, pdfPage(ypointcounter).Height.Point), XStringFormats.TopLeft)
  
          graph.DrawString(firsthour, font, XBrushes.Black, _
          New XRect(288, yPoint, pdfPage(ypointcounter).Width.Point, pdfPage(ypointcounter).Height.Point), XStringFormats.TopLeft)
  
          graph.DrawString(secondhour, font, XBrushes.Black, _
          New XRect(352, yPoint, pdfPage(ypointcounter).Width.Point, pdfPage(ypointcounter).Height.Point), XStringFormats.TopLeft)
  
          graph.DrawString(Percentage, font, XBrushes.Black, _
          New XRect(418, yPoint, pdfPage(ypointcounter).Width.Point, pdfPage(ypointcounter).Height.Point), XStringFormats.TopLeft)
          dtstartdate = dtstartdate.AddDays(1)
          yPoint = yPoint + 20
          x = x + 1
      Next
  </code></pre>