Class PdfSection
Represents a section entity. A section it's a set of the pages with similar page settings.
Inheritance
System.Object
PdfSection
Implements
System.Collections.IEnumerable
Namespace: Syncfusion.Pdf
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfSection : Object, IPdfWrapper, IEnumerable
Remarks
To know more about PdfSection refer this link.
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)
Properties
PageLabel
Gets or sets the PdfPageLabel of the section.
Declaration
public PdfPageLabel PageLabel { get; set; }
Property Value
Type |
---|
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
Pages
Gets the collection of pages in a section (Read only).
Declaration
public PdfSectionPageCollection Pages { get; }
Property Value
Type |
---|
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
PageSettings
Gets or sets the PdfPageSettings of the section.
Declaration
public PdfPageSettings PageSettings { get; set; }
Property Value
Type |
---|
PdfPageSettings |
Remarks
To know more about refer this link .
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)
See Also
Template
Gets or sets the PdfSectionTemplate for the pages in the section.
Declaration
public PdfSectionTemplate Template { get; set; }
Property Value
Type |
---|
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
add_PageAdded(PageAddedEventHandler)
Declaration
public void add_PageAdded(PageAddedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
PageAddedEventHandler | value |
GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
public IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An System.Collections.IEnumerator object that can be used to iterate through the collection. |
OnPageAdded(PageAddedEventArgs)
Called when the page has been added
Declaration
protected virtual void OnPageAdded(PageAddedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
PageAddedEventArgs | args | Event arguments. |
remove_PageAdded(PageAddedEventHandler)
Declaration
public void remove_PageAdded(PageAddedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
PageAddedEventHandler | value |
Events
PageAdded
Event rises when the new page has been added
Declaration
public event PageAddedEventHandler PageAdded
Event Type
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
Implements
System.Collections.IEnumerable