How can I read the available options of a drop-down in a PDF Form using ColdFusion? – Education Career Blog

I have a PDF with an embedded form. This form has inputs and drop-downs. I want to read the data out of the form, so that I can create my own HTML form from it. This works fine for the most part – I can get the field names and labels – however, I have no way of reading the available options in a drop-down field in the form. Is there any way to do this using ColdFusion?

Here’s what I have working so far:

<cfpdfform
    action="read"
    source="myPDF.pdf"
    result="pdfFormFields" />

,

One way is using a bit of iText. (IIRC, cfpdfform does include this extra information in CF9)

<cfscript>
   // substitute with correct path and form field element
   yourPDF     = "c:\register_form1.pdf";
   comboboxName = "person.language";

   // read in the pdf file and get the form field metadata
   reader         = createObject("java", "com.lowagie.text.pdf.PdfReader").init( yourPDF );
   AcroFields     = createObject("java", "com.lowagie.text.pdf.AcroFields");
   formData       = reader.getAcroFields();
   // ONLY for comboboxes (ie drop down lists)
   prop            = {};
   prop.options    = formData.getListOptionExport( comboboxName );
   prop.values     = formData.getListOptionDisplay( comboboxName );
 </cfscript>

<cfdump var="#prop#">

Leave a Comment