Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6188399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:13:28+00:00 2026-05-24T02:13:28+00:00

Is there any way with iTextSharp to retrieve the action contained in a button

  • 0

Is there any way with iTextSharp to retrieve the action contained in a button field contained in a pdf?

I want to know what action that button field will do when clicked on (on MouseUp).

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:13:30+00:00Added an answer on May 24, 2026 at 2:13 am

    Button information is stored as Annotations within the PDF. I wrote some code recently here that enumerated hyperlinks within a PDF (also annotations) and I’ll re-purpose it here for you.

    The action of a button can be a bunch of different things, from JavaScript to menu items to playing a movie and more. The code below handles JavaScript, Named Actions and Destination Actions, I’ll leave the others up to you. Named Actions are application-specific and I don’t know if Adobe has a list of what they all are. See my post above for how to resolved a Destination Action (InDirect Reference).

        Dim WorkingFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim WorkingFile As String = Path.Combine(WorkingFolder, "Services.pdf")
    
        ''//Setup some variables to be used later
        Dim R As PdfReader
        Dim PageCount As Integer
        Dim PageDictionary As PdfDictionary
        Dim Annots As PdfArray
        Dim ActionObject, NamedAction As PdfObject
        Dim DestinationAction As PdfArray
        Dim ActionOjbectID As PdfObject
        Dim ActionDictionary As PdfDictionary
    
        ''//Open our reader
        R = New PdfReader(WorkingFile)
        ''//Get the page cont
        PageCount = R.NumberOfPages
    
        ''//Loop through each page
        For I = 1 To PageCount
            ''//Get the current page
            PageDictionary = R.GetPageN(I)
    
            ''//Get all of the annotations for the current page
            Annots = PageDictionary.GetAsArray(PdfName.ANNOTS)
    
            ''//Make sure we have something
            If (Annots Is Nothing) OrElse (Annots.Length = 0) Then Continue For
    
            ''//Loop through each annotation
            For Each A In Annots.ArrayList
    
                ''//Convert the itext-specific object as a generic PDF object
                Dim AnnotationDictionary = DirectCast(PdfReader.GetPdfObject(A), PdfDictionary)
    
                ''//Make sure this annotation is a button
                If Not AnnotationDictionary.Get(PdfName.FT).Equals(PdfName.BTN) Then Continue For
    
                ''//Make sure this annotation has an ACTION
                If AnnotationDictionary.Get(PdfName.A) Is Nothing Then Continue For
    
                ActionObject = AnnotationDictionary.Get(PdfName.A)
    
                If ActionObject.IsIndirect Then
                    ActionOjbectID = PdfReader.GetPdfObject(AnnotationDictionary.Get(PdfName.A))
                    If ActionOjbectID.IsDictionary Then
                        ActionDictionary = DirectCast(ActionOjbectID, PdfDictionary)
                        If ActionDictionary.Get(PdfName.JS) IsNot Nothing Then
                            Trace.WriteLine("JavaScript Action  : " & ActionDictionary.GetAsString(PdfName.JS).ToUnicodeString())
                        ElseIf ActionDictionary.Get(PdfName.N) IsNot Nothing Then
                            NamedAction = ActionDictionary.Get(PdfName.N)
                            Trace.WriteLine("Named Action       : " & NamedAction.ToString())
                        ElseIf ActionDictionary.Get(PdfName.D) IsNot Nothing Then
                            DestinationAction = ActionDictionary.GetAsArray(PdfName.D)
                            Trace.WriteLine("Destination Action : " & DestinationAction.ToString())
                        Else
                            ''//Add a bunch more 
                            Trace.WriteLine("Some other action  : ")
                            For Each K In ActionDictionary.Keys
                                Trace.WriteLine("                   : " & K.ToString())
                            Next
                        End If
                    Else
                        ''//Not a dictionary, do something else here, should never reach this
                    End If
                Else
                    ''//Non InDirect reference, should never reach this
                End If
            Next
        Next
    

    I should note that this pulls the “default action” for a button but its possible to have multiple actions on a button for the various states. To get those, instead of looking at PdfName.A you need to look at PdfName.AA which will give you an InDirectReference that you’ll need to resolve.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way, to change the field's *min_length* argument inside form constructor? That
Is there any way that I can export dia diagram into html (I know
Is there any way to have something that looks just like a file on
Is there any way to move that scroll indicator to the right by some
Is there any way of having mercurial automatically create hgrc , so that I
Is there any way you can get CreatedBy field for SPListItem Folder . I
There any way to let an application know if there is any specific change
Is there any way to get value of private static field from known class
Is there any way to trigger a function that's called when the user types
Is there any way to hover over an element that's already hidden. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.