Opait PDF Library
Public Member Functions | Static Public Member Functions | Properties | List of all members
Opait.Pdf.PdfDocument Class Reference

This class represents a PDF document in memory. More...

Inheritance diagram for Opait.Pdf.PdfDocument:

Public Member Functions

PdfPage GetPage (int pageNumber)
 Loads and returns a specific page in the PDF document. More...
 
PdfPage AddPage ()
 Appends a new page to the PDF document. More...
 
PdfPage AddPage (PdfPage sourcePage)
 Appends a copy of an existing page to the document. The page may belong to another PDF document. More...
 
PdfPage InsertPage (int index)
 Insert a new page at the specified index. More...
 
PdfPage InsertPage (int index, PdfPage sourcePage)
 Insert a copy of an existing page at the specified index. The page may belong to another PDF document. More...
 
void DeletePage (int pageNumber)
 Deletes a specific page from the PDF document. Can only delete pages that have not yet been saved. More...
 
void DeletePage (PdfPage page)
 Deletes a specific page from the PDF document. Can only delete pages that have not yet been saved. More...
 
void Save ()
 Saves the document using its current file name.
 
void Save (string fileName, PdfDocument source=null)
 Saves the current document to the provided path. More...
 
void Save (Stream stream, PdfDocument source=null)
 Saves the current document to the provided stream. More...
 
void BeginSave (string fileName)
 Starts saving the document to a specified file. Together with SavePage and EndSave, this method allows incremental saving of PDF documents, reducing the memory and resource consumption. More...
 
void BeginSave (Stream stream)
 Start saving the document to a specified file. Together with SavePage and EndSave, this method allows incremental saving of PDF documents, reducing memory and resource consumption. More...
 
void SavePage (PdfPage page)
 Saves a specific page. Together with BeginPage and EndPage, this method allows incremental saving of PDF documents, reducing memory and resource consumption. More...
 
void SavePages ()
 Saves all unsaved pages. Together with BeginPage and EndPage, this method allows incremental saving of PDF documents, reducing memory and resource consumption.
 
void EndSave (PdfDocument source=null)
 Completes writing the PDF document and closes the file. Together with BeginPage and SavePage, this method allows incremental saving of PDF documents, reducing memory and resource consumption. More...
 
void Close ()
 Closes the current PDF document.
 
void Dispose ()
 Disposes the current PDF document.
 
List< PdfImagePageGetAllImages ()
 Get images used on all document pages. More...
 

Static Public Member Functions

static PdfDocument Create (PdfOptions options=null)
 Creates a new empty PDF document. More...
 
static PdfDocument Load (string fileName, string password=null)
 Loads a PDF document from the specified file. More...
 
static PdfDocument Load (Stream stream, string password=null)
 Loads a PDF document from the specified stream. More...
 
static int GetVersion (string fileName)
 Gets the version number of a PDF file. More...
 
static int GetVersion (Stream stream)
 Gets the version number of a PDF stream. More...
 
static int GetPageCount (string fileName)
 Get the number of pages in the specified PDF file. More...
 
static int GetPageCount (Stream stream)
 Get the number of pages in the specified PDF stream. More...
 
static FileFormat GetFileFormat (string fileName, out int pageCount)
 Gets the file format and the number of pages in a document. More...
 
static void ConvertToPdf (string sourceFile, string pdfFile)
 Converts a source file to a PDF file. More...
 

Properties

string FileName [get, set]
 File name of the PDF document.
 
int Version [get, set]
 PDF file version as a two digit number (major and minor).
 
int PageCount [get]
 Gets the number of pages in the document.
 
PdfInfo Info [get]
 Gets the PDF document information.
 
PdfOptions PdfOptions [get]
 The options for generating new PDF files.
 
PdfSecurity Security [get, set]
 Security options for PDF encryption.
 
List< PdfImagePageImages [get]
 Gets the list of image pages used in the PDF document.
 
List< PdfFontFonts [get]
 Gets the list of fonts used in the PDF document.
 
PdfBookmark Bookmarks [get]
 Gets the collection of bookmarks for this document.
 
PdfViewerPreferences ViewerPreferences [get]
 Gets the viewer preferences when this document is opened.
 
bool IsTagged [get]
 Gets a flag to indicate whether the document is a tagged PDF.
 
PdfPageMode PageMode [get, set]
 Gets or sets the page mode (i.e. how the document is initially displayed).
 
LayoutMode PageLayout [get, set]
 Gets or sets the page layout used when document is opened.
 

Detailed Description

This class represents a PDF document in memory.

Member Function Documentation

◆ AddPage() [1/2]

PdfPage Opait.Pdf.PdfDocument.AddPage ( )

Appends a new page to the PDF document.

Returns
The page that was just added.

◆ AddPage() [2/2]

PdfPage Opait.Pdf.PdfDocument.AddPage ( PdfPage  sourcePage)

Appends a copy of an existing page to the document. The page may belong to another PDF document.

Parameters
sourcePageThe source page to be added.
Returns
The added page.

◆ BeginSave() [1/2]

void Opait.Pdf.PdfDocument.BeginSave ( Stream  stream)

Start saving the document to a specified file. Together with SavePage and EndSave, this method allows incremental saving of PDF documents, reducing memory and resource consumption.

Parameters
streamThe open writable stream for saving the PDF.

◆ BeginSave() [2/2]

void Opait.Pdf.PdfDocument.BeginSave ( string  fileName)

Starts saving the document to a specified file. Together with SavePage and EndSave, this method allows incremental saving of PDF documents, reducing the memory and resource consumption.

Parameters
fileNamePath to the saved PDF.

◆ ConvertToPdf()

static void Opait.Pdf.PdfDocument.ConvertToPdf ( string  sourceFile,
string  pdfFile 
)
static

Converts a source file to a PDF file.

The following file formats are supported:

PDF: No conversion is performed. The operation becomes a file copy.

Images: JPEG, PNG, Bitmap and multi-page TIFF files are converted to PDF

Microsoft Office: Word, Excel, PowerPoint and Visio files are converted to PDF if Office is installed.

Text: ASCII and EBCDIC files with or without ASA carriage control characters are converted to PDF.

Parameters
sourceFileThe source file to convert.
pdfFileThe converted PDF file.

◆ Create()

static PdfDocument Opait.Pdf.PdfDocument.Create ( PdfOptions  options = null)
static

Creates a new empty PDF document.

Parameters
optionsOptional PDF creation parameters.
Returns
An empty PDF document.

◆ DeletePage() [1/2]

void Opait.Pdf.PdfDocument.DeletePage ( int  pageNumber)

Deletes a specific page from the PDF document. Can only delete pages that have not yet been saved.

Parameters
pageNumberThe page to be deleted, counting from zero.

◆ DeletePage() [2/2]

void Opait.Pdf.PdfDocument.DeletePage ( PdfPage  page)

Deletes a specific page from the PDF document. Can only delete pages that have not yet been saved.

Parameters
pageThe page to be deleted.

◆ EndSave()

void Opait.Pdf.PdfDocument.EndSave ( PdfDocument  source = null)

Completes writing the PDF document and closes the file. Together with BeginPage and SavePage, this method allows incremental saving of PDF documents, reducing memory and resource consumption.

Parameters
sourceCopy catalog from this source document.

◆ GetAllImages()

List< PdfImagePage > Opait.Pdf.PdfDocument.GetAllImages ( )

Get images used on all document pages.

Returns
A list of images found on all pages.

◆ GetFileFormat()

static FileFormat Opait.Pdf.PdfDocument.GetFileFormat ( string  fileName,
out int  pageCount 
)
static

Gets the file format and the number of pages in a document.

Parameters
fileNameThe path to the document.
pageCountReceives the number of pages in the document.
Returns
The format of the document.

◆ GetPage()

PdfPage Opait.Pdf.PdfDocument.GetPage ( int  pageNumber)

Loads and returns a specific page in the PDF document.

Parameters
pageNumberThe page number starting from zero.
Returns
The PDF page at the specified page number.

◆ GetPageCount() [1/2]

static int Opait.Pdf.PdfDocument.GetPageCount ( Stream  stream)
static

Get the number of pages in the specified PDF stream.

Parameters
streamThe PDF stream.
Returns
The number of pages in the PDF file.

◆ GetPageCount() [2/2]

static int Opait.Pdf.PdfDocument.GetPageCount ( string  fileName)
static

Get the number of pages in the specified PDF file.

Parameters
fileNameThe PDF document.
Returns
The number of pages in the PDF file.

◆ GetVersion() [1/2]

static int Opait.Pdf.PdfDocument.GetVersion ( Stream  stream)
static

Gets the version number of a PDF stream.

Parameters
streamThe PDF stream.
Returns
PDF version as a 2 digit number (e.g. 14 for 1.4), or zero if not a valid PDF.

◆ GetVersion() [2/2]

static int Opait.Pdf.PdfDocument.GetVersion ( string  fileName)
static

Gets the version number of a PDF file.

Parameters
fileNameThe path to the PDF file.
Returns
PDF version as a 2 digit number (e.g. 14 for 1.4), or zero if not a valid PDF.

◆ InsertPage() [1/2]

PdfPage Opait.Pdf.PdfDocument.InsertPage ( int  index)

Insert a new page at the specified index.

Parameters
indexThe zero-based Index of the inserted page.
Returns
The page that was just inserted.

◆ InsertPage() [2/2]

PdfPage Opait.Pdf.PdfDocument.InsertPage ( int  index,
PdfPage  sourcePage 
)

Insert a copy of an existing page at the specified index. The page may belong to another PDF document.

Parameters
indexThe zero-based Index of the inserted page.
sourcePageThe page to be inserted.
Returns
The page that was just inserted.

◆ Load() [1/2]

static PdfDocument Opait.Pdf.PdfDocument.Load ( Stream  stream,
string  password = null 
)
static

Loads a PDF document from the specified stream.

Parameters
streamA PDF file stream.
passwordOptional password if the file is encrypted.
Returns
The loaded PDF document.

◆ Load() [2/2]

static PdfDocument Opait.Pdf.PdfDocument.Load ( string  fileName,
string  password = null 
)
static

Loads a PDF document from the specified file.

Parameters
fileNameThe path to the existing PDF file.
passwordOptional password if the file is encrypted.
Returns
The loaded PDF document.

◆ Save() [1/2]

void Opait.Pdf.PdfDocument.Save ( Stream  stream,
PdfDocument  source = null 
)

Saves the current document to the provided stream.

Parameters
streamThe open writable stream for saving the PDF.
sourceThe source document for copying catalog attributes.

◆ Save() [2/2]

void Opait.Pdf.PdfDocument.Save ( string  fileName,
PdfDocument  source = null 
)

Saves the current document to the provided path.

Parameters
fileNamePath to the saved PDF.
sourceThe source document for copying catalog attributes.

◆ SavePage()

void Opait.Pdf.PdfDocument.SavePage ( PdfPage  page)

Saves a specific page. Together with BeginPage and EndPage, this method allows incremental saving of PDF documents, reducing memory and resource consumption.

Parameters
pageThe PDF page to save.