Doc AddPage Function. Adds a page to the current document. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

Adds a page to the current document.

 

   
Syntax  

[C#]
int AddPage()
int AddPage(int page)

[Visual Basic]
Function AddPage() As Integer
Function AddPage(page As Integer) As Integer

 

   

Params
 
Name Description
page

The page insertion location.

By default pages are added at the end of the document.

return The Object ID of the newly added Page Object.

 

   

Notes
 

Adds a page to the current document.

The AddPage function returns the Object ID of the newly added Page Object. Typically you will want to assign this return value to the document Page property using code of the form.

theDoc.Page = theDoc.AddPage()

Pages are added at the end of the document. However you can use the PageNum parameter to insert pages at other locations. The following code inserts a page at the start of a document.

theDoc.Page = theDoc.AddPage(1)

Any existing page and all subsequent pages will be shifted towards the end of the document to make room for the insertion.

 

   

Example
 

The following code adds three pages to a document. Each page is marked with the page number and page Object ID.

[C#]
Doc theDoc = new Doc();
theDoc.FontSize = 96; // big text
theDoc.TextStyle.HPos = 0.5; // centered
theDoc.TextStyle.VPos = 0.5; // ...
for (int i = 1; i <= 3; i++) {
  theDoc.Page = theDoc.AddPage();
  string txt;
  txt = "Page " + i.ToString() + ", ID=";
  txt = txt + theDoc.Page.ToString();
  theDoc.AddText(txt);
}
theDoc.Save(Server.MapPath("docaddpage.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.FontSize = 96 ' big text
theDoc.TextStyle.HPos = 0.5 ' centered
theDoc.TextStyle.VPos = 0.5 ' ...
For i As Integer = 1 To 3
  theDoc.Page = theDoc.AddPage()
  Dim txt As String
  txt = "Page " + i.ToString() + ", ID="
  txt = txt + theDoc.Page.ToString()
  theDoc.AddText(txt)
Next
theDoc.Save(Server.MapPath("docaddpage.pdf"))
theDoc.Clear()


docaddpage.pdf