Table of Contents

Class PdfSection

Namespace
Syncfusion.Pdf
Assembly
Syncfusion.Pdf.Portable.dll

Represents a section entity. A section it's a set of the pages with similar page settings.

public class PdfSection : IEnumerable
Inheritance
PdfSection
Implements
Inherited Members

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Get the document section collection.
PdfSectionCollection sections = document.Sections;
//Add the section.
PdfSection section = sections.Add();
//Add pages to the section.
PdfPage page = section.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Get the document section collection.
Dim sections As PdfSectionCollection = document.Sections
'Add the section.
Dim section As PdfSection = sections.Add()
'Add pages to the section.
Dim page As PdfPage = section.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Set the font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

To know more about PdfSection refer this link.

Properties

PageLabel

Gets or sets the PdfPageLabel of the section.

public PdfPageLabel PageLabel { get; set; }

Property Value

PdfPageLabel

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the section.
PdfSection section = document.Sections.Add();
//Add pages to the section.
PdfPage page = section.Pages.Add();
//Create the page label.
PdfPageLabel label = new PdfPageLabel();
label.NumberStyle = PdfNumberStyle.LowerRoman;
label.StartNumber = 2;
section.PageLabel = label;
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add the section.
Dim section As PdfSection = document.Sections.Add()
'Add pages to the section.
Dim page As PdfPage = section.Pages.Add()
'Create the page label.
Dim label As New PdfPageLabel()
label.NumberStyle = PdfNumberStyle.LowerRoman
label.StartNumber = 2
section.PageLabel = label
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Set the font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
See Also

PageSettings

Gets or sets the PdfPageSettings of the section.

public PdfPageSettings PageSettings { get; set; }

Property Value

PdfPageSettings

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the section.
PdfSection section = document.Sections.Add();
//Add pages to the section.
PdfPage page = section.Pages.Add();
//Add another section.
PdfSection section1 = document.Sections.Add();
//Add the pages to section1.
PdfPage page1 = section1.Pages.Add();
//Set the page settings.
section.PageSettings.Orientation = PdfPageOrientation.Landscape;
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add the section.
Dim section As PdfSection = document.Sections.Add()
'Add pages to the section.
Dim page As PdfPage = section.Pages.Add()
'Add another section.
Dim section1 As PdfSection = document.Sections.Add()
'Add the pages to section1.
Dim page1 As PdfPage = section1.Pages.Add()
'Set the page settings.
section.PageSettings.Orientation = PdfPageOrientation.Landscape
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Set the font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

To know more about refer this link .

See Also

Pages

Gets the collection of pages in a section (Read only).

public PdfSectionPageCollection Pages { get; }

Property Value

PdfSectionPageCollection

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the section
PdfSection section = document.Sections.Add();
//Get the page collection from a section.
PdfSectionPageCollection pageCollection = document.Sections[0].Pages;
//Add the page
PdfPage page = pageCollection.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add the section.
Dim section As PdfSection = document.Sections.Add()
'Get the page collection from a section.
Dim pageCollection As PdfSectionPageCollection = document.Sections(0).Pages
'Add the page.
Dim page As PdfPage = pageCollection.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Set the font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
See Also

Template

Gets or sets the PdfSectionTemplate for the pages in the section.

public PdfSectionTemplate Template { get; set; }

Property Value

PdfSectionTemplate

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the section.
PdfSection section = document.Sections.Add();
//Add pages to the section.
PdfPage page = section.Pages.Add();
//Create a header and draw the image.
RectangleF bounds = new RectangleF(0, 0, document.Pages[0].GetClientSize().Width, 50);
PdfSectionTemplate template = new PdfSectionTemplate();
template.ApplyDocumentTopTemplate = true;
//Create a page template.
PdfPageTemplateElement header = new PdfPageTemplateElement(bounds);
PdfImage image = new PdfBitmap(@"Input.jpg");
//Draw the image in the header.
header.Graphics.DrawImage(image, bounds);
template.Top = header;
//Add the header at the top of the section
section.Template = template;
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add the section.
Dim section As PdfSection = document.Sections.Add()
'Add pages to the section.
Dim page As PdfPage = section.Pages.Add()
'Create a header and draw the image.
Dim bounds As New RectangleF(0, 0, document.Pages(0).GetClientSize().Width, 50)
Dim template As New PdfSectionTemplate()
template.ApplyDocumentTopTemplate = True
'Create a page template.
Dim header As New PdfPageTemplateElement(bounds)
Dim image As PdfImage = New PdfBitmap("Input.jpg")
'Draw the image in the header.
header.Graphics.DrawImage(image, bounds)
template.Top = header
'Add the header at the top of the section.
section.Template = template
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
See Also

Methods

GetEnumerator()

Returns an enumerator that iterates through a collection.

public IEnumerator GetEnumerator()

Returns

IEnumerator

An IEnumerator object that can be used to iterate through the collection.

See Also

OnPageAdded(PageAddedEventArgs)

Called when the page has been added

protected virtual void OnPageAdded(PageAddedEventArgs args)

Parameters

args PageAddedEventArgs

Event arguments.

See Also

Events

PageAdded

Event rises when the new page has been added

public event PageAddedEventHandler PageAdded

Event Type

PageAddedEventHandler

Examples

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add the section.
PdfSection section = document.Sections.Add();
//Set page size. 
document.PageSettings = new PdfPageSettings(new SizeF(300, 400));
//Add the event.
section.PageAdded += new PageAddedEventHandler(sec_PageAdded);
//Add new page to section.
section.Pages.Add();
//Add new page document.
document.Pages.Add();
//Save and close the document.
document.Save("PageCreatedTest.pdf");
document.Close(true);
//Event handler for PageAdded event
void sec_PageAdded(object sender, PageAddedEventArgs args)
{
PdfPage page = args.Page;
PdfSection section = (sender as PdfSection);
//Get page graphics.
PdfGraphics graphics = page.Graphics;
//Create new font instance.
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f);
//Create new brush instance.
PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
string text = String.Format("Page number : {0} added to Section", section.Pages.Count);
//Draw the text. 
graphics.DrawString(text, font, brush, PointF.Empty);
}
'Create a new PDF document.
Dim document As PdfDocument = New PdfDocument()
'Add the section.
Dim section As PdfSection = document.Sections.Add()
'Set page size. 
document.PageSettings = New PdfPageSettings(New SizeF(300, 400))
'Add the event.
section.PageAdded += New PageAddedEventHandler(sec_PageAdded)
'Add new page to section.
section.Pages.Add()
'Add new page document.
document.Pages.Add()
'Save and close the document.
document.Save("PageCreatedTest.pdf")
document.Close(True)
'Event handler for PageAdded event
Private Sub sec_PageAdded(sender As Object, args As PageAddedEventArgs)
Dim page As PdfPage = args.Page
Dim section As PdfSection = (TryCast(sender, PdfSection))
Dim graphics As PdfGraphics = page.Graphics
Dim font As PdfStandardFont = New PdfStandardFont(PdfFontFamily.TimesRoman, 14.0F)
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Blue)
Dim text As String = String.Format("Page number : {0} added to Section", section.Pages.Count)
graphics.DrawString(text, font, brush, PointF.Empty)
End Sub
See Also

See Also