• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Getting PDF annotations in ColdFusion

Guest
May 10, 2011 May 10, 2011

Copy link to clipboard

Copied

Currently, I am using coldfusion 9 and I am trying to get information about annotations from within a PDF file.  The problem is that there are two types of annotations: text and popup.  I am using iText and I can get an annotation array that has 7 objects.

<cfset reader = CreateObject("java","com.lowagie.text.pdf.PdfReader").init(expandPath("test.pdf"))>

<cfset pageDict = reader.getPageN(1)>

<cfset pdfname = createObject("java","com.lowagie.text.pdf.PdfName")>

<cfset annots = pageDict.getAsArray(pdfname.ANNOTS)>

So now I see that I have 7 annotations ( I know one is text, and the other 6 are popup). At this point I want to loop through the annotation array and get the informartion

<cfset iterator = annots.listIterator()>
<cfloop condition="iterator.hasNext()">
       <cfset annot = reader.getPdfObject(iterator.next())>
       <cfset content = reader.getPdfObject(annot.get(pdfname.CONTENTS))>
       <cfif not isNull(content)>
               <cfoutput>

               <p>
               Text Comment =#content#    <!--- This works for the text comments --->
               </p>
               </cfoutput>
       <cfelse>
               <!--- This happends to be the Popup contents, and where I get lost ---->

       </cfif>
</cfloop>

So in the part where I am trying to get the popup contents, I have tried <cfset x  = reader.getPdfObject(annot.getAsDict(pdfname.popup))>  This works, but I can't seem to extract the data.  All I need is to get either the Subject or Name from the popup innotation as they are set to a set number of possibilities in our system.  How do I extract the name or subject info drom the popup object? 

TOPICS
Advanced techniques

Views

913

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 10, 2011 May 10, 2011

Copy link to clipboard

Copied

Have you tried /Subj...?

cfset subjKey = createObject('java', 'com.lowagie.text.pdf.PdfName').init("Subj")

...

cfset subjText = annot.get(subjKey)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2011 May 11, 2011

Copy link to clipboard

Copied

Thank you!  I had been trying to get the subject off of the annot obj.  I didn't realize that the I had to init Subj.  Once I tried that I was able to do annot.get(subjKey).toString() and get the values I needed!

Thank you again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 11, 2011 May 11, 2011

Copy link to clipboard

Copied

LATEST

The PdfName class defines a bunch of constants, like PdfName.Subject. But you can use init() for custom values when needed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation