#57 add access to document metadata and expose wrapper type

This commit is contained in:
Eliot Jones
2019-08-11 12:41:51 +01:00
parent 2d6e49426a
commit 0349bedd3e
8 changed files with 120 additions and 7 deletions

View File

@@ -7,10 +7,12 @@
using CrossReference;
using Encryption;
using Exceptions;
using Filters;
using IO;
using Logging;
using Parser;
using Tokenization.Scanner;
using Tokens;
using Util.JetBrains.Annotations;
/// <inheritdoc />
@@ -39,7 +41,9 @@
[NotNull]
private readonly IPdfTokenScanner pdfScanner;
private readonly IFilterProvider filterProvider;
[NotNull]
private readonly Pages pages;
@@ -81,6 +85,7 @@
DocumentInformation information,
EncryptionDictionary encryptionDictionary,
IPdfTokenScanner pdfScanner,
IFilterProvider filterProvider,
AcroFormFactory acroFormFactory)
{
this.log = log;
@@ -90,6 +95,7 @@
this.cachingProviders = cachingProviders ?? throw new ArgumentNullException(nameof(cachingProviders));
this.encryptionDictionary = encryptionDictionary;
this.pdfScanner = pdfScanner ?? throw new ArgumentNullException(nameof(pdfScanner));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
Information = information ?? throw new ArgumentNullException(nameof(information));
pages = new Pages(log, catalog, pageFactory, isLenientParsing, pdfScanner);
Structure = new Structure(catalog, crossReferenceTable, pdfScanner);
@@ -153,9 +159,36 @@
}
}
/// <summary>
/// Get the document level metadata if present.
/// The metadata is XML in the (Extensible Metadata Platform) XMP format.
/// </summary>
/// <remarks>This will throw a <see cref="ObjectDisposedException"/> if called on a disposed <see cref="PdfDocument"/>.</remarks>
/// <param name="metadata">The metadata stream if it exists.</param>
/// <returns><see langword="true"/> if the metadata is present, <see langword="false"/> otherwise.</returns>
public bool TryGetXmpMetadata(out XmpMetadata metadata)
{
if (isDisposed)
{
throw new ObjectDisposedException("Cannot access the document metadata after the document is disposed.");
}
metadata = null;
if (!Structure.Catalog.CatalogDictionary.TryGet(NameToken.Metadata, pdfScanner, out StreamToken xmpStreamToken))
{
return false;
}
metadata = new XmpMetadata(xmpStreamToken, filterProvider);
return true;
}
/// <summary>
/// Gets the form if this document contains one.
/// </summary>
/// <remarks>This will throw a <see cref="ObjectDisposedException"/> if called on a disposed <see cref="PdfDocument"/>.</remarks>
/// <returns>An <see cref="AcroForm"/> from the document or <see langword="null"/> if not present.</returns>
internal AcroForm GetForm()
{