Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

Auto-Pagination in PDFOne .NET

Learn how auto-pagination works in PDFOne .NET
By Santhanam

PDFOne .NET uses separate objects for PDF documents and PDF pages. After a document object is created, several page objects can be added to the document object. PDF elements such as text, images, and shapes can be added directly to the document object or to specific to page objects.

In some situations, it is possible that the amount of text that needs to be written cannot be known beforehand. As a result, the number of PDFPage objects that need to be created and added to a PDFDocument object is also not known. For such situations, PDFOne .NET offers a feature called auto-pagination.

Autopagination automatically creates and adds new PDFPage objects to a PDFDocument object when the text written by the PDFDocument's methods exceeds the space available in the last page in the document.

To set autopagination to work, the PDFDocument.AutoPaginate property needs to be set to true. Here is a code example that illustrates autopagination.

using System;
using System.Drawing.Printing;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;

namespace PDFOne_NET {
 class Program {
  static void Main(string[] args) {
   // Create a new document
   PDFDocument d = new PDFDocument();

   // Create an A4-size page
   PDFPage p = new PDFPage(PaperKind.A4);

   // Add the page to the docuemnt

   // Set autopagination on
   d.AutoPaginate = true;

   // Create a string that will be written to the document
   String s = "One, two, buckle my shoe. " +
              "Three, four, knock at the door. " +
              "Five, six, pick up sticks. " +
              "Seven, eight, lay them straight. " +
              "Nine, ten, a big fat hen.";

   // Write the string in a loop
   for (int i = 1; i < 101; i++) {
    // Reset x-coordinate of next writing location to 0
    d.GetPage(d.CurrentPageNo).CursorPosX = 0;
    // Write the string
    // Set y-coordinatee of next writing location 
    // to 40 points below
    d.GetPage(d.CurrentPageNo).CursorPosY = 
      d.GetPage(d.CurrentPageNo).CursorPosY + 40;

   d.OpenAfterCreate = true;

   // Save document to file


Above, we added only one page to the document and started writing text to the page inside a loop. Each time the writing location went beyond the boundaries of the page, PDFOne .NET automatically created and added a new page.

Another thing to note is that the new page added by PDFOne .NET will have the same size, margins, and header and footer lengths as the last page.


Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2019 Gnostice Information Technologies Private Limited. All rights reserved.