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 Cloud-based document-processing
Gnostice StarDocs

Gnostice StarDocs is a scalable, fault-tolerant document-processing server solution, designed to be the central go-to place for all kinds of electronic document-processing work. StarDocs includes a web application (as seen at stardocs.gnostice.com) that frees your end-users from the need to have format-specific software to merge, split, redact, convert, edit, and sign documents - all they need is a network connection and a HTML5 browser. StarDocs provides a REST-based API that your developers can use to add document-processing functions to a variety of software applications. As the REST API is platform agnostic, your developers can write software on a wide variety of platforms - from desktop to mobile devices to Web services in any development language. To get them started quickly, StarDocs is supported by language-specific native SDK. StarDocs document server has load-balancing built-in and is designed to be scalable across enterprise Intranets and the Internet. StarDocs is available as packaged software for on-premise hosting and also as a subscription-based cloud service.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio 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.

XtremePDFConverter VCL

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

Our .NET Developer Tools
XtremeDocumentStudio .NET

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

PDFOne .NET

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

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 office-productivity applications
Free PDF Reader

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

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