Use VeryPDF PDF AcroForms Modifier Library to get and set values to PDF forms

VeryPDF PDF AcroForms Modifier Library is a powerful tool that can be used to modify PDF AcroForms. With this library, users can get values from PDF forms, set values to PDF forms, and change the appearance of PDF forms. The library supports various fields in PDF forms, such as text fields, checkbox fields, combo box fields, list box fields, and more. In this article, we will explore some of the ways in which VeryPDF PDF AcroForms Modifier Library can be used to modify PDF AcroForms.

image

Getting Values from PDF Forms
VeryPDF PDF AcroForms Modifier Library allows users to easily retrieve the values from the fields in a PDF form. This can be done using the GetValue method. The method takes the field name as a parameter and returns the value of the field.

Setting Values to PDF Forms
VeryPDF PDF AcroForms Modifier Library also enables users to set values to the fields in a PDF form. This can be done using the SetValue method. The method takes the field name and the new value as parameters and sets the value of the field.

Changing Appearance to PDF Forms
VeryPDF PDF AcroForms Modifier Library can also be used to modify the appearance of PDF forms. This can be done using the SetAppearance method. The method takes the field name and the appearance as parameters and changes the appearance of the field.

VeryPDF PDF AcroForms Modifier Library provides a simple and effective way to modify PDF AcroForms. With its easy-to-use methods, users can get values from PDF forms, set values to PDF forms, and change the appearance of PDF forms. This library is a valuable tool for anyone who needs to work with PDF forms, whether they are filling out forms, modifying existing forms, or creating new forms.

Should you be interested in acquiring a license for our product or require assistance in developing a custom software solution based on it, please do not hesitate to reach out to us. Our team is always ready to assist you and provide you with the necessary support.

http://support.verypdf.com/

We look forward to the opportunity of working with you and providing developer assistance if required.

C++ example to get values from PDF files, set values to PDF forms and modify PDF forms,

#include <stdlib.h>
#include <string.h>
#include <stdio.h>						/* Use standard Input/Output Console API */

#include "VSLibA.h"						/* Use VeryPDF PDF Library */
#include "VSExcept.h"					/* Use Exceptions API */
#include "VSError.h"					/* Use Errors API */
#include "VSDocA.h"						/* Use PDF Document API */

#include "VSAcroInfoA.h"			  /* Use Acro Objects API */

int main( int argc, char* argv[] )		/* Get PDF filename as first parameter */
{
	PDFLibHandle	PDFLibrary;			/* PDF Library Handle */
	PDFDocHandle	Doc = NULL;			/* PDF Document Handle */

	ppUns32			Index;				  /* Acro Object Index in PDF Document */
	ppUns32			Count;				/* Count of Acro Objects in PDF Document */
	char			*FieldName;	  /* Variable Acro Field's Name */
	ppUns32			NameLen = 0;
	char			*FieldValue;  /* Variable Acro Field's Value */
	ppUns32			ValueLen = 0;
	char			SettingName[ 128 ];	  /* Constant Acro Field's Name */
	char			OutName[ 128 ];
	char			OutValue[ 128 ];
	TPDFAcroType	FieldType;

	ppInt32			OptCount = 0;
	ppInt32			OptIndex;
	char			*OptValue;
	ppUns32			OptLen	= 0;
	ppInt32			ErrorCode;			/* Check Error Code */
	char			ErrBuff[256];

	ppBool			IsUnicode = true;
	const char *TypeNames[] = { "Unknown", "PushButton", "CheckBox", "RadioButton", "EditBox", "ComboBox", "ListBox", "Signature" };
	PDFLibrary = InitPDFLibrary( NULL, NULL ); /* Initialize PDF Library */
	PDFTRY( PDFLibrary )				/* On error keep exception */

	Doc = PDFDocLoadFromFile( PDFLibrary, "C:/AcroFormAPITest.pdf"); /* Load existing PDF file */

#ifdef WINDOWS_PLATFORM
	PDFDocSetAutoLaunch( Doc, true );	/* Launch destination PDF file after work */
#endif
	Count = PDFAcroGetCount( Doc ); /* Check Count of Acro Objects in PDF Document */
	for ( Index = 0; Index < Count; Index++ ) { /* Take each Acro Objects one by one */
		FieldName = PDFAcroGetNameByIndex( Doc, Index, &IsUnicode, &NameLen	 ); /* Get Acro Object's Name */
		FieldValue = PDFAcroGetValueByIndex( Doc, Index, &ValueLen ); /* Get Acro Object's Value */
		strncpy( OutName, FieldName, NameLen );
		OutName[ NameLen ] = '\0';
		strncpy( OutValue, FieldValue, ValueLen );
		OutValue[ ValueLen ] = '\0';
		if ( FieldName || FieldValue ) {	/* If we had any not null option then ... */
			/* Print Name and Value of current Object */
			printf("Field with name '%s' have value '%s' yet.\n", OutName, ValueLen ? OutValue : "Empty" );
			FieldType = PDFAcroGetTypeByIndex( Doc, Index );
			if ( ( FieldType == PDFAcroTypeRadioButton ) || ( FieldType == PDFAcroTypeListBox ) || ( FieldType == PDFAcroTypeComboBox ) ) {
				OptCount = PDFAcroGetOptionCountByIndex( Doc, Index );
				printf( "\tFieldType is %s. Possible options are:\n", TypeNames[ ( int )FieldType ] );
				for ( OptIndex = 0; OptIndex < OptCount; OptIndex++ ) {
					OptValue = PDFAcroGetOptionValueByIndex( Doc, Index, OptIndex, &OptLen );
					strncpy( OutValue, OptValue, OptLen );
					OutValue[ OptLen ] = '\0';
					printf( "\t\t%d -- %s\n", OptIndex, OptLen ? OutValue : "Empty" );
				}
			}
		}
	}
	sprintf( SettingName, "cp" ); /* Intention to change field with name "cp" (Contact Person) */
	Index = PDFAcroGetIndexByName( Doc, SettingName, false );
	PDFAcroSetValueByIndex( Doc, Index, "Ted Thompson" ); /* Set Field "cp" Value
															   as "Ted Thompson"*/

	FieldValue = PDFAcroGetValueByIndex( Doc, Index, &ValueLen ); /* Get Field "cp" Value */
	if ( FieldValue ) { /* If Value of Contact Person Field is not NULL then ...*/
		/* Print Name and Value of Contact Person Field */
		printf("Field with name '%s' have value '%s' now.\n", SettingName, FieldValue );
	}

	sprintf( SettingName, "cn" ); /* Intention to change field with name "cn" (Company Name) */
	Index = PDFAcroGetIndexByName( Doc, SettingName, false );
	PDFAcroSetValueByIndex( Doc, Index, "Thallium Inc." ); /* Set Field "cn" Value as "Thallium Inc."*/
	FieldValue = PDFAcroGetValueByIndex( Doc, Index, &ValueLen ); /* Get Field "cn" Value */
	if ( FieldValue ) { /* If Value of Company Name Field is not NULL then ...*/
		/* Print Name and Value of Company Name Field */
		printf("Field with name '%s' have value '%s' now.\n", SettingName, FieldValue );
	}

	sprintf( SettingName, "dp" ); /* Intention to change field with name "dp" (Department) */
	Index = PDFAcroGetIndexByName( Doc, SettingName, false );
	/* Set Field "dp" Value as "202 Software Department"*/
	PDFAcroSetValueByIndex( Doc, Index, "202 Software Department" );
	FieldValue = PDFAcroGetValueByIndex( Doc, Index, &ValueLen ); /* Get Field "dp" Value */
	if ( FieldValue ) { /* If Value of Department Field is not NULL then ...*/
		/* Print Name and Value of Department Field */
		printf("Field with name '%s' have value '%s' now.\n", SettingName, FieldValue );
	}
	 /* Save destination PDF file  */
	PDFDocSaveToFile( Doc, "C:/AcroFormInfoTest.pdf" );
	PDFFINALLY( PDFLibrary ) /* Do further if haven't PDF Library Exceptions */
	if ( Doc )
		PDFDocClose ( Doc ); /* Close PDF Document and free memory */
	ErrorCode = PDFLASTERROR( PDFLibrary ); /* Check last error, if 0 then finished successfully */
	if ( ErrorCode ){
		VSGetErrorStr( ErrorCode, ErrBuff );
		printf("Error: %s\n", ErrBuff);

	}else {
		printf("Success...\n");
	}
	DonePDFLibrary( &PDFLibrary ); /* Free PDF Library */
	PDFFINALLYEND( PDFLibrary ); /* End of try...end block */
	return ErrorCode;	/* Return Error Code as program result */
}
VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!