Class PdfPageBase
- Namespace
- Syncfusion.Pdf
- Assembly
- Syncfusion.Pdf.Portable.dll
The abstract base class for all pages, Provides methods and properties to create PDF pages and its elements
public abstract class PdfPageBase
- Inheritance
-
PdfPageBase
- Derived
- Inherited Members
Properties
Annotations
Gets the collection of the page's annotations (Read only).
public PdfLoadedAnnotationCollection Annotations { get; }
Property Value
- PdfLoadedAnnotationCollection
The PdfLoadedAnnotationCollection that represents the page's annotations
Examples
//Load the document
PdfLoadedDocument lDoc = new PdfLoadedDocument("inputAnnotation.pdf");
//get the first page from the document
PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
//Get the annotation collection
PdfLoadedAnnotationCollection annotations = page.Annotations;
//Save the document
lDoc.Save("sample.pdf");
lDoc.Close(true);
'Load the document
Dim lDoc As New PdfLoadedDocument("inputAnnotation.pdf")
'Get the first page from the document
Dim page As PdfLoadedPage = TryCast(lDoc.Pages(0), PdfLoadedPage)
'Get the annotation collections
Dim annotations As PdfLoadedAnnotationCollection = page.Annotations
'Save the document
lDoc.Save("sample.pdf")
lDoc.Close(True)
- See Also
DefaultLayer
Gets the default layer of the page (Read only).
public PdfPageLayer DefaultLayer { get; }
Property Value
- PdfPageLayer
The PdfPageLayer of the Page
Examples
//Create new document.
PdfDocument document = new PdfDocument();
//Set page size.
document.PageSettings = new PdfPageSettings(new SizeF(350, 300));
//Add new page.
PdfPage page = document.Pages.Add();
//Create new instance for PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
//Draw the text.
page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, new PointF(150, 10));
//Add the first layer
page.Layers.Add();
//Get default layer graphics.
PdfGraphics graphics = page.DefaultLayer.Graphics;
graphics.TranslateTransform(100, 60);
//Create new instance for PDF pen.
PdfPen pen = new PdfPen(Color.Red, 50);
RectangleF rect = new RectangleF(0, 0, 50, 50);
//Draw arc.
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Blue, 30);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
pen = new PdfPen(Color.Yellow, 20);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Green, 10);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
//Add another layer on the page
page.Layers.Add();
//Increment the layer
page.DefaultLayerIndex += 1;
graphics = page.DefaultLayer.Graphics;
graphics.TranslateTransform(100, 180);
graphics.SkewTransform(0, 50);
//Draw another set of elements
pen = new PdfPen(Color.Red, 50);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Blue, 30);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
pen = new PdfPen(Color.Yellow, 20);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Green, 10);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
//Save the pdf document.
document.Save("Layer.pdf");
//Close the document.
document.Close(true);
'Create new document.
Dim document As PdfDocument = New PdfDocument()
'Set page size.
document.PageSettings = New PdfPageSettings(New SizeF(350, 300))
'Add new page.
Dim page As PdfPage = document.Pages.Add()
'Create new instance for PDF font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 16)
'Draw the text.
page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, New PointF(150, 10))
'Add the first layer
page.Layers.Add()
'Get default layer graphics.
Dim graphics As PdfGraphics = page.DefaultLayer.Graphics
graphics.TranslateTransform(100, 60)
'Create new instance for PDF pen.
Dim pen As PdfPen = New PdfPen(Color.Red, 50)
Dim rect As RectangleF = New RectangleF(0, 0, 50, 50)
'Draw arc.
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Blue, 30)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
pen = New PdfPen(Color.Yellow, 20)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Green, 10)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
'Add another layer on the page
page.Layers.Add()
'Increment the layer
page.DefaultLayerIndex += 1
graphics = page.DefaultLayer.Graphics
graphics.TranslateTransform(100, 180)
graphics.SkewTransform(0, 50)
'Draw another set of elements
pen = New PdfPen(Color.Red, 50)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Blue, 30)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
pen = New PdfPen(Color.Yellow, 20)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Green, 10)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
'Save and close the document.
document.Save("Layer.pdf")
document.Close(True)
- See Also
DefaultLayerIndex
Gets or sets index of the default layer.
public int DefaultLayerIndex { get; set; }
Property Value
Examples
//Create new document.
PdfDocument document = new PdfDocument();
//Set page size.
document.PageSettings = new PdfPageSettings(new SizeF(350, 300));
//Add new page.
PdfPage page = document.Pages.Add();
//Create new instance for PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
//Draw the text.
page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, new PointF(150, 10));
//Add the first layer
page.Layers.Add();
//Get default layer graphics.
PdfGraphics graphics = page.DefaultLayer.Graphics;
graphics.TranslateTransform(100, 60);
//Create new instance for PDF pen.
PdfPen pen = new PdfPen(Color.Red, 50);
RectangleF rect = new RectangleF(0, 0, 50, 50);
//Draw arc.
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Blue, 30);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
pen = new PdfPen(Color.Yellow, 20);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Green, 10);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
//Add another layer on the page
page.Layers.Add();
//Increment the layer
page.DefaultLayerIndex += 1;
graphics = page.DefaultLayer.Graphics;
graphics.TranslateTransform(100, 180);
graphics.SkewTransform(0, 50);
//Draw another set of elements
pen = new PdfPen(Color.Red, 50);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Blue, 30);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
pen = new PdfPen(Color.Yellow, 20);
graphics.DrawArc(pen, rect, 360, 360);
pen = new PdfPen(Color.Green, 10);
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
//Save the pdf document.
document.Save("Layer.pdf");
//Close the document.
document.Close(true);
'Create new document.
Dim document As PdfDocument = New PdfDocument()
'Set page size.
document.PageSettings = New PdfPageSettings(New SizeF(350, 300))
'Add new page.
Dim page As PdfPage = document.Pages.Add()
'Create new instance for PDF font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 16)
'Draw the text.
page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, New PointF(150, 10))
'Add the first layer
page.Layers.Add()
'Get default layer graphics.
Dim graphics As PdfGraphics = page.DefaultLayer.Graphics
graphics.TranslateTransform(100, 60)
'Create new instance for PDF pen.
Dim pen As PdfPen = New PdfPen(Color.Red, 50)
Dim rect As RectangleF = New RectangleF(0, 0, 50, 50)
'Draw arc.
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Blue, 30)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
pen = New PdfPen(Color.Yellow, 20)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Green, 10)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
'Add another layer on the page
page.Layers.Add()
'Increment the layer
page.DefaultLayerIndex += 1
graphics = page.DefaultLayer.Graphics
graphics.TranslateTransform(100, 180)
graphics.SkewTransform(0, 50)
'Draw another set of elements
pen = New PdfPen(Color.Red, 50)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Blue, 30)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
pen = New PdfPen(Color.Yellow, 20)
graphics.DrawArc(pen, rect, 360, 360)
pen = New PdfPen(Color.Green, 10)
graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360)
'Save and close the document.
document.Save("Layer.pdf")
document.Close(True)
- See Also
FormFieldsTabOrder
Gets or sets the tab order type for form fields
public PdfFormFieldsTabOrder FormFieldsTabOrder { get; set; }
Property Value
Examples
//Create a new document.
PdfDocument document = new PdfDocument();
//Create a new page.
PdfPage page = document.Pages.Add();
//Set form fields tab order.
page.FormFieldsTabOrder = PdfFormFieldsTabOrder.Manual;
//Create new text box field.
PdfTextBoxField field = new PdfTextBoxField(page, "Hello");
//Set field tab index as 3.
field.TabIndex = 3;
//Set field bounds.
field.Bounds = new RectangleF(0, 0, 100, 30);
//Create new text box field.
PdfTextBoxField field1 = new PdfTextBoxField(page, "Hello1");
//Set field tab index as 2.
field.TabIndex = 2;
//Set field bounds.
field1.Bounds = new RectangleF(200, 0, 100, 30);
//Create new text box field.
PdfTextBoxField field2 = new PdfTextBoxField(page, "Hello2");
//Set field tab index as 1.
field.TabIndex = 1;
//Set field bounds.
field2.Bounds = new RectangleF(0, 50, 100, 30);
//Create new text box field.
PdfTextBoxField field3 = new PdfTextBoxField(page, "Hello3");
//Set field tab index as 0.
field.TabIndex = 0;
//Set field bounds.
field3.Bounds = new RectangleF(200, 50, 100, 30);
//Adds the form field to the document.
document.Form.Fields.Add(field);
document.Form.Fields.Add(field1);
document.Form.Fields.Add(field2);
document.Form.Fields.Add(field3);
//Save the pdf document.
document.Save("TabOrder.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As PdfDocument = New PdfDocument()
'Creates a new page.
Dim page As PdfPage = document.Pages.Add()
'Set form fields tab order.
page.FormFieldsTabOrder = PdfFormFieldsTabOrder.Manual
'Create new text box field.
Dim field As PdfTextBoxField = New PdfTextBoxField(page, "Hello")
'Set field tab index as 3.
field.TabIndex = 3
'Set field bounds.
field.Bounds = New RectangleF(0, 0, 100, 30)
'Create new text box field.
Dim field1 As PdfTextBoxField = New PdfTextBoxField(page, "Hello1")
'Set field tab index as 2.
field.TabIndex = 2
'Set field bounds.
field1.Bounds = New RectangleF(200, 0, 100, 30)
'Create new text box field.
Dim field2 As PdfTextBoxField = New PdfTextBoxField(page, "Hello2")
'Set field tab index as 1.
field.TabIndex = 1
'Set field bounds.
field2.Bounds = New RectangleF(0, 50, 100, 30)
'Create new text box field.
Dim field3 As PdfTextBoxField = New PdfTextBoxField(page, "Hello3")
'Set field tab index as 0.
field.TabIndex = 0
'Set field bounds.
field3.Bounds = New RectangleF(200, 50, 100, 30)
'Adds the form field to the document.
document.Form.Fields.Add(field)
document.Form.Fields.Add(field1)
document.Form.Fields.Add(field2)
document.Form.Fields.Add(field3)
'Save document to disk.
document.Save("TabOrder.pdf")
'Close the document.
document.Close(True)
- See Also
Graphics
Gets the graphics of the DefaultLayer.
public PdfGraphics Graphics { get; }
Property Value
- PdfGraphics
The PdfGraphics that represents a graphics of the page.
Examples
//Create a PDF document
PdfDocument document = new PdfDocument();
//Create a PDF page
PdfPage page = document.Pages.Add();
//Get graphics
PdfGraphics graphics = page.Graphics;
//Draw a rectangle
graphics.DrawRectangle(PdfBrushes.Red, new RectangleF(0, 0, 100, 200));
//Save and close the document
document.Save("output.pdf");
document.Close(true);
'Create a PDF document
Dim document As New PdfDocument()
'Create a PDF page
Dim page As PdfPage = document.Pages.Add()
'Get graphics
Dim graphics As PdfGraphics = page.Graphics
'Draw a rectangle
graphics.DrawRectangle(PdfBrushes.Red, New RectangleF(0, 0, 100, 200))
'Save and close the document
document.Save("output.pdf")
document.Close(True)
- See Also
IsBlank
Gets the PdfLoadedPage is blank or not;Default value is false
public bool IsBlank { get; }
Property Value
Examples
//load the existing pdf document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//set the bool value
bool value = true;
//load first page
bool page = loadedDocument.Pages[0].IsBlank;
//return the bool value of IsBlank property
page.Equals(value);
//close the loaded document
loadedDocument.Close(true)
'load the existing pdf document.
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'set the bool value
Dim value As Boolean = True
'load first page.
Dim page As Boolean = loadedDocument.Pages(0).IsBlank
'return the bool value of IsBlank property.
page.Equals(value)
'close the loaded document.
loadedDocument.Close(True)
Layers
Gets the collection of the page's layers (Read only).
public PdfPageLayerCollection Layers { get; }
Property Value
- PdfPageLayerCollection
The PdfPageLayerCollection that represents the page's layers
Examples
//Create a PDF document
PdfDocument document = new PdfDocument();
//Add page to the document
PdfPage page=document.Pages.Add();
//Get the page layer
PdfPageLayerCollection angle = page.Layers;
//Save and close the PDF document
document.Save("output.Pdf");
document.Close(true);
'Create a PDF document
Dim document As New PdfDocument()
'Add page to the document
Dim page As PdfPage = document.Pages.Add()
'Get the page layer
Dim angle As PdfPageLayerCollection = page.Layers
'Save and close the PDF document
document.Save("output.Pdf")
document.Close(True)
- See Also
Rotation
Gets or sets the PDF page rotation.
public PdfPageRotateAngle Rotation { get; set; }
Property Value
- PdfPageRotateAngle
The PdfPageRotateAngle that represents the page rotation
Examples
//Create a PDF document
PdfDocument document = new PdfDocument();
//Create a page
PdfPage page = new PdfPage();
//Insert page in the document
document.Pages.Insert(0, page);
//Get rotation
PdfPageRotateAngle angle = page.Rotation;
//Save and close the PDF document
document.Save("output.Pdf");
document.Close(true);
'Create a PDF document
Dim document As New PdfDocument()
'Create a page
Dim page As New PdfPage()
'Insert page in the document
document.Pages.Insert(0, page)
'Get rotation
Dim angle As PdfPageRotateAngle = page.Rotation
'Save and close the PDF document
document.Save("output.Pdf")
document.Close(True)
Size
Gets the size of the page (Read only).
public abstract SizeF Size { get; }
Property Value
- SizeF
Examples
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("Input.pdf");
//Get size of first page
SizeF size = ldoc.Pages[0].Size;
//Save and close the document.
ldoc.Save("Output.pdf");
ldoc.Close(true);
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'Get size of first page
Dim size As SizeF = ldoc.Pages(0).Size
'Save and close the document.
ldoc.Save("Output.pdf")
ldoc.Close(True)
- See Also
Methods
CreateTemplate()
Creates a template from page content and all annotation appearances.
public PdfTemplate CreateTemplate()
Returns
- PdfTemplate
The created PdfTemplate.
Examples
//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
//Load the page
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
//Create the template from the page.
PdfTemplate template = loadedPage.CreateTemplate();
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Set the document margin
document.PageSettings.SetMargins(2);
//Add the page
PdfPage page = document.Pages.Add();
//Create the graphics
PdfGraphics graphics = page.Graphics;
//Draw the template
graphics.DrawPdfTemplate(template, PointF.Empty,new SizeF(page.Size.Width/2,page.Size.Height));
//Save the new document.
document.Save("output.pdf");
//Close the documents
loadedDocument.Close(true);
document.Close(true);
'Load the existing PDF document.
Dim loadedDocument As New PdfLoadedDocument(fileName)
'Load the page
Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage)
'Create the template from the page.
Dim template As PdfTemplate = loadedPage.CreateTemplate()
'Create a new PDF document
Dim document As New PdfDocument()
'Set the document margin
document.PageSettings.SetMargins(2)
'Add the page
Dim page As PdfPage = document.Pages.Add()
'Create the graphics
Dim graphics As PdfGraphics = page.Graphics
'Draw the template
graphics.DrawPdfTemplate(template, PointF.Empty, New SizeF(page.Size.Width \ 2, page.Size.Height))
'Save the new document.
document.Save("output.pdf")
'Close the documents
loadedDocument.Close(True)
ExtractText()
Extracts text from the PDF Page.
public string ExtractText()
Returns
- string
The Extracted Text.
Examples
//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
//Load the first page.
PdfPageBase page = loadedDocument.Pages[0];
//Extract text from first page.
string extractedText = page.ExtractText();
//Close the document
loadedDocument.Close(true);
'Load an existing PDF.
Dim loadedDocument As New PdfLoadedDocument(fileName)
'Load the first page.
Dim page As PdfPageBase = loadedDocument.Pages(0)
'Extract the text from first page.
Dim extractedText As String = page.ExtractText()
'close the document.
loadedDocument.Close(True)
ExtractText(out TextLineCollection)
Extracts text from the page of the PDF document.
public string ExtractText(out TextLineCollection textLineCollection)
Parameters
textLineCollection
TextLineCollectionHolds the lines with bounds in the page.
Returns
- string
The Extracted Text.
ExtractText(bool)
Extracts text from the PDF Page based on its layout
public string ExtractText(bool IsLayout)
Parameters
IsLayout
boolExtracts text based on the Layout of PDF Document if the parameter is set to true, else Extracts text normally.
Returns
- string
The Extracted Text.
Examples
//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
//Load first page.
PdfPageBase page = loadedDocument.Pages[0];
//Extract text from first page.
string extractedTexts = page.ExtractText(true);
//close the document
loadedDocument.Close(true);
'Load an existing PDF.
Dim loadedDocument As New PdfLoadedDocument(fileName)
'Load first page.
Dim page As PdfPageBase = loadedDocument.Pages(0)
'Extract text from first page.
Dim extractedTexts As String = page.ExtractText(True)
'close the document
loadedDocument.Close(True)
Remarks
Extracting the text based on the layout may take additional processing time when compared to the normal extraction.