Skip to content

# PDFFileEx

Namespace: O2S.Components.PDF4NET.Core

The PDFFileEx class extends the PDFFile class with file update capabilities.

    public class PDFFileEx : PDFFile

Inheritance Object → PDFFile → PDFFileEx

Remarks

The PDFFileEx class allows to load the entire PDF file and perform changes but without the overhead addded by PDFFixedDocument class. The updated file can be saved back to file or stream.

## Constructors

### PDFFileEx(String, String)

Initializes a new PDFFileEx object from a PDF file.

    public PDFFileEx(string fileName, string password)

Parameters

`fileName` String
Path to the PDF file.

`password` String
Password for decrypting the PDF file.

### PDFFileEx(Stream, String)

Initializes a new PDFFileEx object from a stream.

    public PDFFileEx(Stream stream, string password)

Parameters

`stream` Stream
Stream with the PDF file.

`password` String
Password for decrypting the PDF file.

Remarks

The 'stream' after the constructor executed can be disposed as the whole file has been loaded.

## Properties

### PageCount

Gets the number of pages.

    public int PageCount { get; }

Property Value

Int32
The number of pages in the PDF file.

### SecurityHandler

Gets the file security handler.

    public PDFSecurityHandler SecurityHandler { get; }

Property Value

PDFSecurityHandler
The security handler that was used to encrypt the PDF file.

## Methods

### FlattenFormFields()

Flattens the form fields in the file.

    public void FlattenFormFields()

### GetPageCanvas(Int32, PDFPageCanvasPosition)

Gets the page canvas for the specified page.

    public PDFPageCanvas GetPageCanvas(int pageNumber, PDFPageCanvasPosition pageCanvasPosition)

Parameters

`pageNumber` Int32
The page number for which the canvas surface should be retrieved.

`pageCanvasPosition` PDFPageCanvasPosition
The position of page canvas, under or on top of existing page content.

Returns

PDFPageCanvas
A PDFPageCanvas object that allows to draw on page surface.

### GetPageCosDictionary(Int32)

Gets the COS dictionary representing the specified page.

    public PDFCosDictionary GetPageCosDictionary(int pageNumber)

Parameters

`pageNumber` Int32
The page number for which to retrieve the COS dictionary.

Returns

PDFCosDictionary
The COS dictionary of the specified page.

Exceptions

ArgumentOutOfRangeException
Thrown when pageNumber is less than 0 or greater then or equal to PDFFile.PageCount.

### GetPageNumberForFieldWidget(String, Int32)

Gets the number of the page that includes the specified field widget.

    public int GetPageNumberForFieldWidget(string fieldName, int widgetIndex)

Parameters

`fieldName` String
The field that owns the widget.

`widgetIndex` Int32
Index of the widget.

Returns

Int32
The number of the page that includes the specified field widget or -1 if the field name is invalid.

### GetPositionForFieldWidget(String, Int32)

Gets the position on the page for the specified field widget.

    public PDFDisplayRectangle GetPositionForFieldWidget(string fieldName, int widgetIndex)

Parameters

`fieldName` String
The field that owns the widget.

`widgetIndex` Int32
Index of the widget.

Returns

PDFDisplayRectangle
A PDFDisplayRectangle specifying the position of the widget on the page.

### Save(String, PDFSecurityHandler, Boolean)

Saves the PDF file to disk.

    public void Save(string fileName, PDFSecurityHandler securityHandler, bool enableObjectCompression)

Parameters

`fileName` String
Path where the PDF file will be saved.

`securityHandler` PDFSecurityHandler
Security handler for encrypting the merged file.

`enableObjectCompression` Boolean
True if the merged file should compress the PDF file structure.

### Save(Stream, PDFSecurityHandler, Boolean)

Saves the PDF file to given stream.

    public void Save(Stream output, PDFSecurityHandler securityHandler, bool enableObjectCompression)

Parameters

`output` Stream
Stream where the PDF file will be saved.

`securityHandler` PDFSecurityHandler
Security handler for encrypting the merged file.

`enableObjectCompression` Boolean
True if the merged file should compress the PDF file structure.

### SetFieldValue(String, Object)

Sets the given field with the specified value.

    public void SetFieldValue(string fieldName, object value)

Parameters

`fieldName` String
Field to set

`value` Object
Value to set on the field.

Remarks

If the 'fieldName' does not exist nothing happens.

### SetFormFillOptions(PDFFormFillOptions)

Sets the options for filling form fields.

    public void SetFormFillOptions(PDFFormFillOptions options)

Parameters

`options` PDFFormFillOptions
Options for filling form fields.