Skip to content

Commit

Permalink
allow writing custom metadata to document builder #669 (#715)
Browse files Browse the repository at this point in the history
* allow writing custom metadata to document builder #669

* skip null entries
  • Loading branch information
EliotJones authored Oct 22, 2023
1 parent c6e2de1 commit 96ba82a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,11 @@ internal AddedFont(Guid id, IndirectReferenceToken reference)
/// </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>
Expand Down Expand Up @@ -1136,6 +1141,16 @@ internal Dictionary<NameToken, IToken> ToDictionary()
{
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);
Expand Down

0 comments on commit 96ba82a

Please sign in to comment.