Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/UglyToad.PdfPig/Content/OptionalContentGroupElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ internal OptionalContentGroupElement(MarkedContentElement markedContentElement,
switch (Type)
{
case "OCG": // Optional content group dictionary
// Name - Required
// Name - Per spec this is required, but in practice some PDFs store layer names
// at the document catalog level in OCProperties rather than in marked content Properties.
// To avoid crashes, we make this optional and fall back to null or the tag name.

if (markedContentElement.Properties.TryGet(NameToken.Name, pdfTokenScanner, out NameToken? name))
{
Name = name.Data;
Expand All @@ -74,7 +77,9 @@ internal OptionalContentGroupElement(MarkedContentElement markedContentElement,
}
else
{
throw new ArgumentException($"Cannot parse optional content's {nameof(Name)} from {nameof(markedContentElement.Properties)}. This is a required field.", nameof(markedContentElement.Properties));
// Name not found in Properties - use tag as fallback or leave as null
// This handles PDFs where layer names are stored at document catalog level
Name = markedContentElement.Tag;
}

// Intent - Optional
Expand Down
Loading