Aspose.Pdf.Form- filling out form says field does not exist even though it does

I’m using the latest Aspose Total installation (09/16/2011, 6.2.0). I notice that the form functionality previously in Aspose.Pdf.Kit has been removed and merged into Aspose.Pdf.Form. I am trying to update my code to reflect these changes.


I’m having an issue with the new lib not detecting the form fields, though. I’m using the same pdf form and the same case sensitivity of the field names as in my previous code version, yet in this newer version it simply cannot find any of the fields. The Form.Count property says there are 35 fields available, so it sees something.

Any ideas? I’ll paste my code below.

        /// 
/// Fill out a PDF Form file and save it.
///

private void FillOutForm(String template, String output)
{
// open the pdf form, fill it out, save it
Document form = new Document(template);
        (form.Form["Acquisition_Date"] as TextBoxField).Value = evidenceItem.acquisitionDate.ToShortDateString();
        (form.Form["Eng_Name"] as TextBoxField).Value = evidenceItem.engagement_id.ToString();
        (form.Form["Source"] as TextBoxField).Value = evidenceItem.source_fullname;
        (form.Form["Custodian_Name"] as TextBoxField).Value = evidenceItem.custodian_name;
        (form.Form["Team_Member_Name"] as TextBoxField).Value = evidenceItem.team_member_name;
        (form.Form["Inventory_Number"] as TextBoxField).Value = evidenceItem.inventoryNumber.ToString();
        (form.Form["Preservation_Location"] as TextBoxField).Value = evidenceItem.preservationLocation;
        (form.Form["Inventory_Class"] as TextBoxField).Value = evidenceItem.inventory_class_name;
        (form.Form["Source_Mediaev"] as TextBoxField).Value = evidenceItem.sourceMediaEV;
        (form.Form["Serial_Numberev"] as TextBoxField).Value = evidenceItem.serialNumberEV;
        (form.Form["Remarks"] as TextBoxField).Value = evidenceItem.remarks;
        (form.Form["Type"] as TextBoxField).Value = evidenceItem.mediaType;
        (form.Form["Make"] as TextBoxField).Value = evidenceItem.make;
        (form.Form["Model"] as TextBoxField).Value = evidenceItem.model;
        (form.Form["Serial_Number"] as TextBoxField).Value = evidenceItem.serialNumber;
        (form.Form["System_Time_Verification"] as TextBoxField).Value = evidenceItem.systemTimeVerification;
        (form.Form["Hard_Drive_Type"] as TextBoxField).Value = evidenceItem.hardDriveType;
        (form.Form["Hard_Drive_Make"] as TextBoxField).Value = evidenceItem.hardDriveMake;
        (form.Form["Hard_Drive_Model"] as TextBoxField).Value = evidenceItem.hardDriveModel;
        (form.Form["Hard_Drive_Serial_Number"] as TextBoxField).Value = evidenceItem.hardDriveSerialNumber;
        (form.Form["Capacity"] as TextBoxField).Value = evidenceItem.capacity.ToString();
        (form.Form["Capacity_Unit"] as TextBoxField).Value = evidenceItem.capacityUnit;
        (form.Form["Acquisition_Tool"] as TextBoxField).Value = evidenceItem.acquisitionTool;
        (form.Form["Acquisition_Tool_Version"] as TextBoxField).Value = evidenceItem.acquisitionToolVersion;
        (form.Form["Booted_System_OS"] as TextBoxField).Value = evidenceItem.bootedSystemOS;
        (form.Form["Write_Block_Protected"] as TextBoxField).Value = evidenceItem.writeBlockProtected;
        (form.Form["Audit_Log_Name"] as TextBoxField).Value = evidenceItem.auditLogName;
        (form.Form["md5_hash"] as TextBoxField).Value = evidenceItem.md5Hash;
        (form.Form["Image_Authentication"] as TextBoxField).Value = evidenceItem.imageAuthentication;
        (form.Form["Image_File_Name"] as TextBoxField).Value = evidenceItem.imageFileName;
        (form.Form["Errors_Encountered"] as TextBoxField).Value = (evidenceItem.errorsEncountered == 1).ToString();
        (form.Form["Installed_Kpmg_Controllers"] as TextBoxField).Value = (evidenceItem.installedKpmgController == 1).ToString();
        (form.Form["Direct_Connection"] as TextBoxField).Value = (evidenceItem.directConnection == 1).ToString();
        (form.Form["Image_Verified"] as TextBoxField).Value = (evidenceItem.imageVerified == 1).ToString();
        (form.Form["Administrator"] as TextBoxField).Value = evidenceItem.administrator;
        (form.Form["Backup_Software_Used"] as TextBoxField).Value = evidenceItem.backupSoftwareUsed;
        (form.Form["Backup_Software_Version"] as TextBoxField).Value = evidenceItem.backupSoftwareVersion;
        (form.Form["E_Mail_Application"] as TextBoxField).Value = evidenceItem.emailApplication;
        (form.Form["E_Mail_Application_Version"] as TextBoxField).Value = evidenceItem.emailApplicationVersion;
        (form.Form["File_Name"] as TextBoxField).Value = evidenceItem.fileName;
        (form.Form["File_Size"] as TextBoxField).Value = evidenceItem.file_size;
        (form.Form["File_Size_Unit"] as TextBoxField).Value = evidenceItem.fileSizeUnit;
        (form.Form["OS"] as TextBoxField).Value = evidenceItem.OS;
        (form.Form["OS_Version"] as TextBoxField).Value = evidenceItem.OSVersion;
        (form.Form["Physical_Location"] as TextBoxField).Value = evidenceItem.physicalLocation;
        (form.Form["Record_Count"] as TextBoxField).Value = evidenceItem.recordCount.ToString();
        (form.Form["Server_Host_Name"] as TextBoxField).Value = evidenceItem.serverHostName;
        (form.Form["Service_Provider"] as TextBoxField).Value = evidenceItem.serviceProdiver;
        (form.Form["Sim_Sard_Size"] as TextBoxField).Value = evidenceItem.simCardSize;
        (form.Form["Receipt_Method"] as TextBoxField).Value = evidenceItem.receiptMethod;
        (form.Form["Delivered_To"] as TextBoxField).Value = evidenceItem.deliveredTo;
        (form.Form["Delivered_Date"] as TextBoxField).Value = evidenceItem.deliveredDate;
        (form.Form["Delivered_By"] as TextBoxField).Value = evidenceItem.deliveredBy;
        (form.Form["Delivery_Method"] as TextBoxField).Value = evidenceItem.deliveryMethod;
        (form.Form["TrackingNumber"] as TextBoxField).Value = evidenceItem.trackingNumber;

        // save the output file
        form.Save(output);
    }</pre></div>

Hi Ryan,

Thanks for using our products.

Can you please share the source PDF Form so that we can test the scenario at our end. We apologize for your inconvenience.

Sure thing. Here is the PDF form.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the template file.

I executed the part of your code with the template file you shared and I am unable to reproduce the issue. Following is my sample code and attached is the resultant file.

Aspose.Pdf.License license = new Aspose.Pdf.License();

license.SetLicense(@"E:\\AP Data\\Aspose.Total.lic");

// open the pdf form, fill it out, save it

Document form = new Document("E:\\AP Data\\Source_Files\\frmSubAC.pdf");

(form.Form["Acquisition_Date"] as TextBoxField).Value = "12/12/2011";

(form.Form["Eng_Name"] as TextBoxField).Value = "20192";

(form.Form["Source"] as TextBoxField).Value = "Source Name";

(form.Form["Custodian_Name"] as TextBoxField).Value = "Custodian Name";

(form.Form["Team_Member_Name"] as TextBoxField).Value = "Team Member Name";

(form.Form["Inventory_Number"] as TextBoxField).Value = "Inventory_Number";

(form.Form["Preservation_Location"] as TextBoxField).Value = "Preservation_Location";

(form.Form["Inventory_Class"] as TextBoxField).Value = "Inventory_Class";

//(form.Form["Source_Mediaev"] as TextBoxField).Value = "Source_Mediaev";

/ (form.Form["Serial_Numberev"] as TextBoxField).Value = "Serial_Numberev";

(form.Form["Remarks"] as TextBoxField).Value ="Remarks";

(form.Form["Type"] as TextBoxField).Value = "Type";

(form.Form["Make"] as TextBoxField).Value = "Make";

(form.Form["Model"] as TextBoxField).Value = "Model";

(form.Form["Serial_Number"] as TextBoxField).Value = "Serial Number";

(form.Form["System_Time_Verification"] as TextBoxField).Value = "Tiff Verify";

(form.Form["Hard_Drive_Type"] as TextBoxField).Value = "Hard Drive Type";

(form.Form["Hard_Drive_Make"] as TextBoxField).Value = "Hard Drive Make";

(form.Form["Hard_Drive_Model"] as TextBoxField).Value = "Hard Drive Model";

(form.Form["Hard_Drive_Serial_Number"] as TextBoxField).Value = "Hard Drive Serial Number";

(form.Form["Capacity"] as TextBoxField).Value = "Capacity";

(form.Form["Capacity_Unit"] as TextBoxField).Value = "Capacity Unit";

(form.Form["Acquisition_Tool"] as TextBoxField).Value = "Acquisition Tool";

(form.Form["Acquisition_Tool_Version"] as TextBoxField).Value = "Acquisition Tool Version";

(form.Form["Booted_System_OS"] as TextBoxField).Value = "Booted System OS";

(form.Form["Write_Block_Protected"] as TextBoxField).Value = "Write Block Protected";

(form.Form["Audit_Log_Name"] as TextBoxField).Value = "Audit Log Name";

(form.Form["MD5_Hash"] as TextBoxField).Value = "md5_hash";

(form.Form["Image_Authentication"] as TextBoxField).Value = "Image Authentication";

(form.Form["Image_File_Name"] as TextBoxField).Value = "Image File Name";

// save the output file

form.Save("E:\\AP Data\\Source_Files\\dest.pdf");

Please create a sample application with your complete code and post (as attached) in this thread. We will check it soon.

P.S. Please make sure to use the license file as your mentioned issue may occur due to a license restriction. If you are not using a license and you would like to test the new Aspose.Pdf for .NET, you can request a temporary license and evaluate the product. Please use the following link and select "Get a temporary license" option: http://www.aspose.com/purchase/default.aspx.

Thank You & Best Regards,

I’m just now getting back to this. I am writing up an example application, using my license file. We have the Aspose.NET Total license. I’ll reply with the example project in a few minutes.

You’re right. That code does work in a stand-alone app. Interesting. Not sure how else to debug this. It must be a licensing issue - maybe I’m loading it incorrectly. I would have expected a different kind of error, though.

Ok. I solved this mystery.


The code works fine. The issue was with where I was calling SetLicense. In our application, we use several of the Aspose libraries, including PDF and Cells. I was calling SetLicense off of the Cells class, and not the PDF class. So, the PDF functions were not working and were not giving me a meaningful error message regarding the license issue.

I propose two things:

  1. More informative exception messages if the error is caused by no license being set.
  2. A global SetLicense function that does this for all Aspose products in one call.