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
WasProtected
Whether the file was protected by a password when it was opened.
public bool WasProtected { get; }
Property Value
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
xmpstring
Returns
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
Returns
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
Returns
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
attachmentFileAttachment
Returns
KeepPages(string)
Keeps only the pages pages names, in the order it names them.
public PdfFile KeepPages(string pages)
Parameters
pagesstring
Returns
LiftRestrictions()
Drops the restrictions a signature places on the file — what its /Perms allow — so it can be changed freely.
public PdfFile LiftRestrictions()
Returns
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
Returns
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
Returns
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
Returns
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
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
Returns
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
Returns
Protect(Protection)
Saves the file protected as protection says, in place of any protection it had.
public PdfFile Protect(Protection protection)
Parameters
protectionProtection
Returns
Save(Stream)
Writes the file to stream, which is not closed.
public void Save(Stream stream)
Parameters
streamStream
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
pathstring
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
Returns
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
Returns
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()