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

Adding Page Breaks To A PDF Document In .NET

Learn to use the new AddPageBreak method introduced in v3.0.4.
By V. Subhash

In Version v3.0.4, we have introduced a new method named AddPageBreak() in the PDFDocument class. This method behaves like the similar feature in Microsoft Word and other word-processing applications. It inserts a new page and makes it the current page for further content rendering operations. However, the method does this only when it is creating a document. When this method is called after loading an existing document, then no new page is created but the next page is made the current page and the focus of further rendering operations.

To find out how this works, create a Windows Forms project, add two buttons and use the following click-event handlers.

// Illustrates AddPageBreak() behavior in creation mode
private void button1_Click(object sender, EventArgs e) {
  PDFDocument doc = 
     new PDFDocument("your-license-key");
  doc.OpenAfterCreate = true;
  doc.MeasurementUnit = PDFMeasurementUnit.Inches;
  doc.AutoPaginate = false;
  PDFFont fontCourier = new PDFFont(StdType1Font.Courier, PDFFontStyle.Fill, 24);

  for (float i = 1, y=0.5f; i <= 40; i++) {

    doc.WriteText(i.ToString() + 
                    ". I will not litter the classroom. ", 
                  fontCourier, 1, y);
    y += 0.5f;
    if ( (i % 10 == 0) & (i < 40)) {
        // Insert a new page
        doc.AddPageBreak();
        y = 0.5f;
    }

  }

  doc.Save("imposition.pdf");
  doc.Dispose(); 
}

// Illustrates AddPageBreak() behavior in reading mode
private void button2_Click(object sender, EventArgs e) {
  PDFDocument doc = 
     new PDFDocument("your-license-key");
  doc.Load("imposition.pdf");
  doc.OpenAfterCreate = true;
  doc.MeasurementUnit = PDFMeasurementUnit.Inches;
  doc.AutoPaginate = false;
  doc.Brush.Color = Color.Red;

  PDFFont fontCourier = new PDFFont(StdType1Font.Courier, PDFFontStyle.Fill, 24);

  for (float i = 1, y = 0.5f; i <= 40; i++) {
    doc.WriteText(" Now, behave! ", fontCourier, 5.5f, y);
    y += 0.5f;
    if ((i % 10 == 0) & (i < 40)) {
      // Move to the next page
      doc.AddPageBreak();
      y = 0.5f;
    }
  }

  doc.Save("imposition_reviewed.pdf");
  doc.Dispose();
  Close();
}

When you run the application and click on the first button, it will create a PDF document like this. The method AddPageBreak() creates a new page each time it is called.

When you click the second button, new pages are not created. However, the focus simply moves to the next page and rendering operations resume from there. Thanks to this behaviour, we are able to render content where it was previously left off when the document was first created.

---o0O0o---

Our Free Online Document-Processing Tools
Gnostice Apps

Gnostice Apps provides several PDF document-processing services over the Web. It enables you to merge, split, convert, secure and redact PDF documents - all for FREE. All you need to access these services is a HTML5-capable browser such as the latest version of Firefox/Seamonkey or IE 11.

Our Developer Tools
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.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

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

XtremeDocumentStudio .NET

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

PDFOne (for Java™)

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

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

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

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).