Namespace: PdfSharp.Pdf
Represents a PDF document.
public sealed class PdfDocument : PdfObject, System.ICloneable, System.IDisposable
Inheritance Object → PdfItem → PdfObject → PdfDocument
Implements ICloneable, IDisposable
Gets or sets a user defined object that contains arbitrary information associated with this document. The tag is not used by PDFsharp.
public object Tag { get; set; }
Encapsulates the document’s events.
public DocumentEvents Events { get; }
Gets the document options used for saving the document.
public PdfDocumentOptions Options { get; }
Gets PDF specific document settings.
public PdfDocumentSettings Settings { get; }
Gets or sets the PDF version number. Return value 14 e.g. means PDF 1.4 / Acrobat 5 etc.
public int Version { get; set; }
Gets the number of pages in the document.
public int PageCount { get; }
Gets the file size of the document.
public long FileSize { get; }
Gets the full qualified file name if the document was read form a file, or an empty string otherwise.
public string FullPath { get; }
Gets a Guid that uniquely identifies this instance of PdfDocument.
public Guid Guid { get; }
Returns a value indicating whether the document was newly created or opened from an existing document. Returns true if the document was opened with the PdfReader.Open function, false otherwise.
public bool IsImported { get; }
Returns a value indicating whether the document is read only or can be modified.
public bool IsReadOnly { get; }
Gets information about the document.
public PdfDocumentInformation Info { get; }
This function is intended to be undocumented.
public PdfCustomValues CustomValues { get; set; }
Get the pages dictionary.
public PdfPages Pages { get; }
Gets or sets a value specifying the page layout to be used when the document is opened.
public PdfPageLayout PageLayout { get; set; }
Gets or sets a value specifying how the document should be displayed when opened.
public PdfPageMode PageMode { get; set; }
Gets the viewer preferences of this document.
public PdfViewerPreferences ViewerPreferences { get; }
Gets the root of the outline (or bookmark) tree.
public PdfOutlineCollection Outlines { get; }
Get the AcroForm dictionary.
public PdfAcroForm AcroForm { get; }
Gets or sets the default language of the document.
public string Language { get; set; }
Gets the security settings of this document.
public PdfSecuritySettings SecuritySettings { get; }
Gets the PdfInternals object of this document, that grants access to some internal structures which are not part of the public interface of PdfDocument.
public PdfInternals Internals { get; }
Gets the standard security handler and creates it, if not existing.
public PdfStandardSecurityHandler SecurityHandler { get; }
Gets the PdfDocument this object belongs to.
public PdfDocument Owner { get; }
Indicates whether the object is an indirect object.
public bool IsIndirect { get; }
Gets the PdfInternals object of this document, that grants access to some internal structures which are not part of the public interface of PdfDocument.
public PdfObjectInternals Internals { get; }
Gets the indirect reference of this object. If the value is null, this object is a direct object.
public PdfReference Reference { get; internal set; }
Gets the indirect reference of this object. Throws if it is null.
public PdfReference ReferenceNotNull { get; }
InvalidOperationException
The indirect reference must be not null here.
Creates a new PDF document in memory. To open an existing PDF file, use the PdfReader class.
public PdfDocument()
Creates a new PDF document with the specified file name. The file is immediately created and kept locked until the document is closed. At that time the document is saved automatically. Do not call Save() for documents created with this constructor, just call Close(). To open an existing PDF file and import it, use the PdfReader class.
public PdfDocument(string filename)
filename
String
Creates a new PDF document using the specified stream. The stream won’t be used until the document is closed. At that time the document is saved automatically. Do not call Save() for documents created with this constructor, just call Close(). To open an existing PDF file, use the PdfReader class.
public PdfDocument(Stream outputStream)
outputStream
Stream
Disposes all references to this document stored in other documents. This function should be called for documents you finished importing pages from. Calling Dispose is technically not necessary but useful for earlier reclaiming memory of documents you do not need anymore.
public void Dispose()
Closes this instance.
public void Close()
Saves the document to the specified path. If a file already exists, it will be overwritten.
public void Save(string path)
path
String
Saves the document to the specified stream.
public void Save(Stream stream, bool closeStream)
stream
Stream
closeStream
Boolean
Saves the document to the specified stream. The stream is not closed by this function. (Older versions of PDFsharp closes the stream. That was not very useful.)
public void Save(Stream stream)
stream
Stream
Dispatches PrepareForSave to the objects that need it.
internal void PrepareForSave()
Determines whether the document can be saved.
public bool CanSave(String& message)
message
String&
internal bool HasVersion(string version)
version
String
Adjusts the version if the current version is lower than the required version.
public bool SetRequiredVersion(int requiredVersion)
requiredVersion
Int32
The minimum version number to set version to.
Boolean
True, if Version was modified.
internal Exception DocumentNotImported()
Imports the fields from the specified PdfAcroForm into the current document.
If the current document does not contain an AcroForm, a new one is created automatically.
This method should be called after importing pages into the current document.
public void ImportAcroForm(PdfAcroForm remoteForm, Action<PdfAcroField, PdfAcroField> fieldHandler)
remoteForm
PdfAcroForm
The PdfDocument.AcroForm to import
fieldHandler
Action<PdfAcroField, PdfAcroField>
A method that allows modifying a field after it was imported.
It receives the original (remote) field and the imported (local) field as parameters.
Remarks:
While importing, the new fields may be renamed, if a field with the same name is already present.
The new field receives a number-suffix in this case, starting at 2.
i.e. if the new field has the name myField and there is already a field myField present,
the new field is renamed to myField2.
If more fields with the same name are imported, the number-suffix will increase automatically.
This is useful when merging multiple versions of the same document. (e.g.with different field-values)
Gets the existing PdfAcroForm or creates a new one, if there is no PdfAcroForm in the current document
public PdfAcroForm GetOrCreateAcroForm()
PdfAcroForm
The PdfAcroForm associated with this document
Creates a new page and adds it to this document. Depending on the IsMetric property of the current region the page size is set to A4 or Letter respectively. If this size is not appropriate it should be changed before any drawing operations are performed on the page.
public PdfPage AddPage()
Adds the specified page to this document. If the page is from an external document, it is imported to this document. In this case the returned page is not the same object as the specified one.
public PdfPage AddPage(PdfPage page)
page
PdfPage
Creates a new page and inserts it in this document at the specified position.
public PdfPage InsertPage(int index)
index
Int32
Inserts the specified page in this document. If the page is from an external document, it is imported to this document. In this case the returned page is not the same object as the specified one.
public PdfPage InsertPage(int index, PdfPage page)
index
Int32
page
PdfPage
Adds a named destination to the document.
public void AddNamedDestination(string destinationName, int destinationPage, PdfNamedDestinationParameters parameters)
destinationName
String
The Named Destination’s name.
destinationPage
Int32
The page to navigate to.
parameters
PdfNamedDestinationParameters
The PdfNamedDestinationParameters defining the named destination’s parameters.
Adds an embedded file to the document.
public void AddEmbeddedFile(string name, string path)
name
String
The name used to refer and to entitle the embedded file.
path
String
The path of the file to embed.
Adds an embedded file to the document.
public void AddEmbeddedFile(string name, Stream stream)
name
String
The name used to refer and to entitle the embedded file.
stream
Stream
The stream containing the file to embed.
Flattens the AcroField’s widget annotations of this document.
Other annotations are unaffected.
public void FlattenAcroForm()
Occurs when the specified document is not used anymore for importing content.
internal void OnExternalDocumentFinalized(DocumentHandle handle)
handle
DocumentHandle