Class PdfDocument
Represents a PDF document.
Inheritance
Implements
Namespace: Sartorius.SAF.Pdf
Assembly: Sartorius.SAF.Pdf.dll
Syntax
public sealed class PdfDocument : IDisposable
Examples
The following example shows how to open a PdfDocument from a System.IO.Stream.
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Sartorius.SAF.Help.pdf"))
{
using (var source = new PdfDocumentSource(stream))
{
using (var doc = source.LoadDocument())
{
// work with document
}
}
}
The following example shows how to access the bookmark tree of a PDF document.
private void PrintBookmarks(PdfDocument doc)
{
PrintBookmarks(doc.Bookmarks);
}
private void PrintBookmarks(IReadOnlyList<Bookmark> bookmarks, Int32 indent = 0)
{
foreach (var bookmark in bookmarks)
{
Console.WriteLine("new");
Console.WriteLine("{");
Console.Write(new String('\t', indent));
Console.Write($"Name = \"{bookmark.Title}\",");
Console.WriteLine($"{GetActionString(bookmark)},");
Console.WriteLine("Children = new dynamic[]");
Console.WriteLine("{");
PrintBookmarks(bookmark.Children, indent + 1);
Console.WriteLine("}");
Console.WriteLine("},");
}
}
private String GetActionString(Bookmark bookmark)
{
if (bookmark.Action != null)
{
switch (bookmark.Action.Type)
{
case ActionType.Unsupported:
return "Unsupported Action";
case ActionType.Goto:
return $"Page = {((GotoAction) bookmark.Action).DestinationPage}";
case ActionType.RemoteGoto:
return $"Goto page {((GotoAction) bookmark.Action).DestinationPage} in {((RemoteGotoAction) bookmark.Action).FilePath}";
case ActionType.Uri:
return $"Open URI {((UriAction) bookmark.Action).Uri}";
case ActionType.Launch:
return $"Open File {((LaunchAction) bookmark.Action).FilePath}";
}
}
return String.Empty;
}
Constructors
View SourcePdfDocument(PdfDocument)
Initializes a new instance of the PdfDocument class by copying the content of another .
Declaration
public PdfDocument(PdfDocument pdfDocument)
Parameters
Type | Name | Description |
---|---|---|
PdfDocument | pdfDocument | The PDF document. |
Properties
View SourceBookmarks
Gets the bookmarks of this document.
Declaration
public IReadOnlyList<Bookmark> Bookmarks { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<Bookmark> | The bookmarks. |
Examples
The following example shows how to access the bookmark tree of a PDF document.
private void PrintBookmarks(PdfDocument doc)
{
PrintBookmarks(doc.Bookmarks);
}
private void PrintBookmarks(IReadOnlyList<Bookmark> bookmarks, Int32 indent = 0)
{
foreach (var bookmark in bookmarks)
{
Console.WriteLine("new");
Console.WriteLine("{");
Console.Write(new String('\t', indent));
Console.Write($"Name = \"{bookmark.Title}\",");
Console.WriteLine($"{GetActionString(bookmark)},");
Console.WriteLine("Children = new dynamic[]");
Console.WriteLine("{");
PrintBookmarks(bookmark.Children, indent + 1);
Console.WriteLine("}");
Console.WriteLine("},");
}
}
private String GetActionString(Bookmark bookmark)
{
if (bookmark.Action != null)
{
switch (bookmark.Action.Type)
{
case ActionType.Unsupported:
return "Unsupported Action";
case ActionType.Goto:
return $"Page = {((GotoAction) bookmark.Action).DestinationPage}";
case ActionType.RemoteGoto:
return $"Goto page {((GotoAction) bookmark.Action).DestinationPage} in {((RemoteGotoAction) bookmark.Action).FilePath}";
case ActionType.Uri:
return $"Open URI {((UriAction) bookmark.Action).Uri}";
case ActionType.Launch:
return $"Open File {((LaunchAction) bookmark.Action).FilePath}";
}
}
return String.Empty;
}
View Source
Metadata
Gets the metadata for this document.
Declaration
public Metadata Metadata { get; }
Property Value
Type | Description |
---|---|
Metadata | The metadata. |
PageCount
Gets the page count.
Declaration
public int PageCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The page count. |
PageSizes
Gets the page sizes.
Declaration
public PageSize[] PageSizes { get; }
Property Value
Type | Description |
---|---|
PageSize[] | The page sizes. |
Methods
View SourceAppendPages(PdfDocument)
Appends all pages from another PdfDocument.
Declaration
public void AppendPages(PdfDocument other)
Parameters
Type | Name | Description |
---|---|---|
PdfDocument | other | The other document. |
Exceptions
Type | Condition |
---|---|
PdfException | An error occured in Pdfium. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Finalize()
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
Declaration
protected void Finalize()
Save(Stream)
Saves the document to the specified stream.
Declaration
public void Save(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The stream. |
Save(String)
Saves the document to the specified path.
Declaration
public void Save(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path. |