Table of Contents

Class PdfFile

Namespace
Rustaveli.Pdf
Assembly
Rustaveli.Pdf.Operations.dll

A PDF file being put together from others: its pages kept, reordered or added to from other files, and pages of other files laid beneath or over them, like a letterhead or a stamp. Nothing is written until it is saved.

public sealed class PdfFile
Inheritance
PdfFile
Inherited Members

Remarks

Pages are named as a print dialog names them: "1-3, 5, 8-last", from 1, ranges running either way and open at either end. Each operation works on the pages as they are when it is called.

Saving writes a new file. What the first file says of the document as a whole — its information, language, metadata and colour intents — is kept; its outline, named destinations and structure are kept too while its pages all are, in their order, at the start of the file. The layers and form fields of every file are kept with its pages, and links lead where they did in their own file.

Properties

PageCount

How many pages the file has now.

public int PageCount { get; }

Property Value

int

WasProtected

Whether the file was protected by a password when it was opened.

public bool WasProtected { get; }

Property Value

bool

Methods

AddMetadata(string)

Adds to the file's XMP metadata: each rdf:Description in xmp — the description of an electronic invoice, say, with the schema PDF/A needs to know it by — joins those already there.

public PdfFile AddMetadata(string xmp)

Parameters

xmp string

Returns

PdfFile

Append(PdfFile, string?)

Adds the pages of other, as they are now, after these — those pages names, or all.

public PdfFile Append(PdfFile other, string? pages = null)

Parameters

other PdfFile
pages string

Returns

PdfFile

Append(string, string?)

Adds the pages of the PDF file at path after these — those pages names, or all.

public PdfFile Append(string path, string? pages = null)

Parameters

path string
pages string

Returns

PdfFile

Attach(FileAttachment)

Attaches a file, listed among the attachments readers show and, for PDF/A-3, associated with the document by its relationship. The file's own attachments are kept whatever pages are.

public PdfFile Attach(FileAttachment attachment)

Parameters

attachment FileAttachment

Returns

PdfFile

KeepPages(string)

Keeps only the pages pages names, in the order it names them.

public PdfFile KeepPages(string pages)

Parameters

pages string

Returns

PdfFile

LiftRestrictions()

Drops the restrictions a signature places on the file — what its /Perms allow — so it can be changed freely.

public PdfFile LiftRestrictions()

Returns

PdfFile

Open(byte[], string?)

Opens the PDF file at path, with password — the owner's or the user's — if it is protected.

public static PdfFile Open(byte[] data, string? password = null)

Parameters

data byte[]
password string

Returns

PdfFile

Exceptions

IncorrectPasswordException

The file is protected, and the password does not open it.

UnreadableFileException

The file is not a PDF, or is damaged past repair.

NotSupportedException

The file is protected by a security handler other than the standard, password one, such as a certificate's.

Open(Stream, string?)

Opens a PDF file read from stream, which is read to its end and not closed.

public static PdfFile Open(Stream stream, string? password = null)

Parameters

stream Stream
password string

Returns

PdfFile

Exceptions

IncorrectPasswordException

The file is protected, and the password does not open it.

UnreadableFileException

The file is not a PDF, or is damaged past repair.

NotSupportedException

The file is protected by a security handler other than the standard, password one, such as a certificate's.

Open(string, string?)

Opens the PDF file at path, with password — the owner's or the user's — if it is protected.

public static PdfFile Open(string path, string? password = null)

Parameters

path string
password string

Returns

PdfFile

Exceptions

IncorrectPasswordException

The file is protected, and the password does not open it.

UnreadableFileException

The file is not a PDF, or is damaged past repair.

NotSupportedException

The file is protected by a security handler other than the standard, password one, such as a certificate's.

OptimizeForWeb()

Saves the file for viewing over the web as it downloads — Acrobat's fast web view — its first page first, then each other page with what it alone needs, with hints saying where everything lies.

public PdfFile OptimizeForWeb()

Returns

PdfFile

Overlay(PdfFile, string?, string?)

Draws pages of the PDF file at path over these, as a stamp: over the pages onto names, or all, the pages from names, or all, one each in turn and starting again when they run out — so a one-page stamp goes on every page.

public PdfFile Overlay(PdfFile layer, string? onto = null, string? from = null)

Parameters

layer PdfFile
onto string
from string

Returns

PdfFile

Overlay(string, string?, string?)

Draws pages of the PDF file at path over these, as a stamp: over the pages onto names, or all, the pages from names, or all, one each in turn and starting again when they run out — so a one-page stamp goes on every page.

public PdfFile Overlay(string path, string? onto = null, string? from = null)

Parameters

path string
onto string
from string

Returns

PdfFile

Protect(Protection)

Saves the file protected as protection says, in place of any protection it had.

public PdfFile Protect(Protection protection)

Parameters

protection Protection

Returns

PdfFile

Save(Stream)

Writes the file to stream, which is not closed.

public void Save(Stream stream)

Parameters

stream Stream

Save(string)

Writes the file at path, beside it first and then moved into place, so a failure leaves whatever was there — the file this one was opened from, say — as it was.

public void Save(string path)

Parameters

path string

ToArray()

Writes the file, returning its bytes.

public byte[] ToArray()

Returns

byte[]

Underlay(PdfFile, string?, string?)

Draws pages of the PDF file at path beneath these, as a letterhead: beneath the pages onto names, or all, the pages from names, or all, one each in turn and starting again when they run out.

public PdfFile Underlay(PdfFile layer, string? onto = null, string? from = null)

Parameters

layer PdfFile
onto string
from string

Returns

PdfFile

Underlay(string, string?, string?)

Draws pages of the PDF file at path beneath these, as a letterhead: beneath the pages onto names, or all, the pages from names, or all, one each in turn and starting again when they run out.

public PdfFile Underlay(string path, string? onto = null, string? from = null)

Parameters

path string
onto string
from string

Returns

PdfFile

Unprotect()

Saves the file without protection. A protected file keeps its protection, as it had it, unless this or Protect(Protection) says otherwise.

public PdfFile Unprotect()

Returns

PdfFile