SautinSoft Knowledge Base

Latest Code Examples
"Create a page tree in C# and VB.NET" $keywords "tree,create,page,documents,C#,VB.NET,Sautinsoft.PDF .Net,library,component" $description "Shows how to create a page tree with Sautinsoft.Pdf .NET library in Sautinsoft.PDF .Net library in C# and VB.NET." $pageID "L2PageTree" include_once($_SERVER['DOCUMENT_ROOT'] . '/supplements/top.php') include_once($_SERVER['DOCUMENT_ROOT'] . '/supplements/header_example.php') ?>

With " target"_blank">PDF .Net, you can get, create, remove or reorder PDF document pages in your C# or VB.NET application.

The pages of a PDF document are accessed through a structure known as the page tree, which defines the ordering of pages in the document. The tree structure allows PDF consumer applications, using only limited memory, to quickly open a PDF document containing thousands of pages. For more information, see Document Structure help page.

The following example shows how you can create a page tree structure from scratch.

Complete code

using System
using SautinSoft.Pdf
using System.IO

class Program
	static void Main()
		// This property is necessary only for licensed version.
		//SautinSoft.Pdf.Serial  "XXXXXXXXXXX"

		using (var document  new PdfDocument())
			using (var formattedText  new PdfFormattedText())
				// Get a page tree root node.
				var rootNode  document.Pages
				// Set page rotation for a whole set of pages.
				rootNode.Rotate  90

				// Create a left page tree node.
				var childNode  rootNode.Kids.AddPages()
				// Overwrite a parent tree node rotation value.
				childNode.Rotate  0

				// Create a first page.
				var page  childNode.Kids.AddPage()
				formattedText.Append("FIRST PAGE")
				page.Content.DrawText(formattedText, new PdfPoint(0, 0))

				// Create a second page and set a page media box value.
				page  childNode.Kids.AddPage()
				page.SetMediaBox(0, 0, 200, 400)
				formattedText.Append("SECOND PAGE")
				page.Content.DrawText(formattedText, new PdfPoint(0, 0))

				// Create a right page tree node.
				childNode  rootNode.Kids.AddPages()
				// Set a media box value.
				childNode.SetMediaBox(0, 0, 100, 200)

				// Create a third page.
				page  childNode.Kids.AddPage()
				formattedText.Append("THIRD PAGE")
				page.Content.DrawText(formattedText, new PdfPoint(0, 0))

				// Create a fourth page and overwrite a rotation value.
				page  childNode.Kids.AddPage()
				page.Rotate  0
				formattedText.Append("FOURTH PAGE")
				page.Content.DrawText(formattedText, new PdfPoint(0, 0))

			document.Save("Page Tree.pdf")


" target"_blank">Download.

9 Items | Last Updated: 2023/12/01