-
Notifications
You must be signed in to change notification settings - Fork 208
Keep /A element when reading PdfOutline #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This change updates PdfSharp’s outline and annotation parsing to preserve the /A (Action) dictionary even when a /Dest is also present. Previously, PdfSharp would discard the /A entry when replacing it with a /Dest, which resulted in the loss of important behaviors such as JavaScript execution or chained /Next actions. In many PDFs — especially those created with Adobe Acrobat or CAD tools — outlines and annotations include compound actions like: ```pdf Kopiuj Edytuj /A << /S /GoTo /D [...] /Next << /S /JavaScript /JS (...) >> >> ``` Discarding the action breaks interactive features such as: - Highlighting fields (e.g. flashing red rectangles) - Dynamic form behaviors - Any action-driven JavaScript logic Benefits: - Preserves full PDF behavior and interactivity - Aligns with the PDF spec, which allows both /A and /Dest - Enables advanced use cases like viewer development, script analysis, or validation This change is backward-compatible and improves PdfSharp’s ability to work with professionally authored interactive PDFs.
|
Hi! Thanks for the information. Can you provide PDF files for testing, please? The PDF spec 1.7 writes about the "/A" parameter: "Optional; PDF 1.1; not permitted if a Dest entry is present". But PDF files in the wild do not always care about the specs. |
|
Hello, I can't really provide this PDF as it contains copyrighted data, but I can show the exact thing from it that I mention in this PR: As you can see there is both /Next and /D in this /Action, and current implementation converts this /Action into /Dest element, and it is not possible to retrieve the /Next value after the conversion. In this case I need to read the /JS value of where is this Outline pointing to, as the parent is only pointing to /Fit. |
|
I can also provide the code snippet of how I access the data, so it is clearer what is the aim of the changes: if (!outline.Elements.TryGetValue("/A", out PdfItem actionRef) ||
pdf.PdfActions.FirstOrDefault(a => a.Reference == actionRef) is not { } action ||
(action. JavaScript ?? action.Next?.JavaScript) is not { } js)
{
preciseBounds = false;
return null;
}The document.Internals
.GetAllObjects()
.OfType<PdfDictionary>()
.Where(d => d.Elements.TryGetString("/Type", out string type) && type == "/Action")
.Select(d => new PdfAction(d))
.ToArray()And public class PdfAction : PdfDictionary
{
public string Type
{
get { return Elements.TryGetString("/S", out string value) ? value : null; }
}
public PdfPage DestinationPage
{
get
{
return Elements.TryGetValue("/D", out PdfItem item) &&
item is PdfArray destArr &&
destArr.OfType<PdfReference>().Select(r => r.Value).FirstOrDefault() is PdfPage page
? page
: null;
}
}
public string JavaScript
{
get { return Elements.TryGetString("/JS", out string value) ? value : null; }
}
public PdfAction Next
{
get
{
return Elements.TryGetValue("/Next", out PdfItem next) && next is PdfReference nextRef
? nextRef.Value as PdfAction
: null;
}
}
public PdfAction(PdfDictionary dict) : base(dict)
{
}
} |
|
Hi! |
This change updates PdfSharp’s outline and annotation parsing to preserve the /A (Action) dictionary even when a /Dest is also present. Previously, PdfSharp would discard the /A entry when replacing it with a /Dest, which resulted in the loss of important behaviors such as JavaScript execution or chained /Next actions.
In many PDFs — especially those created with Adobe Acrobat or CAD tools — outlines and annotations include compound actions like:
Discarding the action breaks interactive features such as:
Highlighting fields (e.g. flashing red rectangles)
Dynamic form behaviors
Any action-driven JavaScript logic
Benefits:
Preserves full PDF behavior and interactivity
Aligns with the PDF spec, which allows both /A and /Dest
Enables advanced use cases like viewer development, script analysis, or validation
This change is backward-compatible and improves PdfSharp’s ability to work with professionally authored interactive PDFs.