allow writing custom metadata to document builder #669 (#715)

* allow writing custom metadata to document builder #669

* skip null entries
This commit is contained in:
Eliot Jones
2023-10-22 10:33:06 +01:00
committed by GitHub
parent c6e2de1b0c
commit 96ba82ad4e

View File

@@ -1092,6 +1092,11 @@ namespace UglyToad.PdfPig.Writer
/// </summary>
public class DocumentInformationBuilder
{
/// <summary>
/// Consumer applications can store custom metadata in the document information dictionary.
/// </summary>
public Dictionary<string, string> CustomMetadata { get; } = new Dictionary<string, string>();
/// <summary>
/// <see cref="DocumentInformation.Title"/>.
/// </summary>
@@ -1136,6 +1141,16 @@ namespace UglyToad.PdfPig.Writer
{
var result = new Dictionary<NameToken, IToken>();
foreach (var pair in CustomMetadata)
{
if (pair.Key == null || pair.Value == null)
{
continue;
}
result[NameToken.Create(pair.Key)] = new StringToken(pair.Value);
}
if (Title != null)
{
result[NameToken.Title] = new StringToken(Title);