mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 17:47:12 +08:00
Allow to have a metadata stream in the document information entry (#322)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
using Parts;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Parse the dictionary from a PDF file trailer.
|
||||
@@ -21,8 +22,9 @@
|
||||
return DocumentInformation.Default;
|
||||
}
|
||||
|
||||
var infoParsed = DirectObjectFinder.Get<DictionaryToken>(trailer.Info.Value, pdfTokenScanner);
|
||||
|
||||
var token = DirectObjectFinder.Get<IToken>(trailer.Info.Value, pdfTokenScanner);
|
||||
if (token is DictionaryToken infoParsed)
|
||||
{
|
||||
var title = GetEntryOrDefault(infoParsed, NameToken.Title);
|
||||
var author = GetEntryOrDefault(infoParsed, NameToken.Author);
|
||||
var subject = GetEntryOrDefault(infoParsed, NameToken.Subject);
|
||||
@@ -35,6 +37,27 @@
|
||||
return new DocumentInformation(infoParsed, title, author, subject,
|
||||
keywords, creator, producer, creationDate, modifiedDate);
|
||||
}
|
||||
else if (token is StreamToken streamToken)
|
||||
{
|
||||
var streamDictionary = streamToken.StreamDictionary;
|
||||
if (!streamDictionary.TryGet(NameToken.Type, out NameToken typeNameToken) || typeNameToken != "Metadata")
|
||||
{
|
||||
throw new PdfDocumentFormatException($"Unknown document metadata type was found");
|
||||
}
|
||||
|
||||
if (!streamDictionary.TryGet(NameToken.Subtype, out NameToken subtypeToken) || subtypeToken != "XML")
|
||||
{
|
||||
throw new PdfDocumentFormatException($"Unknown document metadata subtype was found");
|
||||
}
|
||||
|
||||
// We are not fully supporting XMP Stream so we left the user fully deserialize the stream
|
||||
return DocumentInformation.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PdfDocumentFormatException($"Unknown document information token was found {token.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetEntryOrDefault(DictionaryToken infoDictionary, NameToken key)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user