The library exposes native C-style interface to allow interoperability with most languages. All handles are basically opaque pointers to internal structures, which are meant to be modified using the only the API and not the structures themselves.
All of the basic interface types are either opaque pointers to internal structures or simply standard value types such as integers or strings.
All interface objects are reference counted. Whenever an object is received with an output parameter, it has to be released when no longer needed.
After the file has been opened successfully, the caller is responsible for calling appropriate release function. Calling the release multiple times is an error and causes undefined behavior. We recommend resetting the handles to their initial state of NULL, to prevent any errors.
For example this macro may help in maintaining consistent state of the local variables:
With this helper macro, the cleanup becomes easier as long as it is properly initialized with NULL.
It is also safe to call this release macro several times. This code style may seem repulsive for some developers, they are free to use any kind of cleanup, as long as it serves the purpose.
There is a code sample how to obtain the last error code with the message printed to console.
char* error_message = NULL;
char* error_code_name = NULL;
RETURN_ERROR_IF_NOT_SUCCESS(Errors_GetLastError(&error));
RETURN_ERROR_IF_NOT_SUCCESS(Errors_GetLastErrorMessageLength(&error_message_length));
if (error_message_length >= SIZE_MAX) {
unsigned long long length_converted = error_message_length;
print_text("Buffer size is too big: %llu bytes\n", length_converted);
return VANILLAPDF_TEST_ERROR_FAILURE;
}
error_message = (char*) calloc(sizeof(char), error_message_length);
if (NULL == error_message) {
unsigned long long length_converted = error_message_length;
print_text("Could not allocate memory: %llu bytes\n", length_converted);
return VANILLAPDF_TEST_ERROR_FAILURE;
}
RETURN_ERROR_IF_NOT_SUCCESS(Errors_GetLastErrorMessage(error_message, error_message_length));
RETURN_ERROR_IF_NOT_SUCCESS(Errors_GetPrintableErrorTextLength(error, &error_code_name_length));
if (error_code_name_length >= SIZE_MAX) {
unsigned long long length_converted = error_code_name_length;
print_text("Buffer size is too big: %llu bytes\n", length_converted);
return VANILLAPDF_TEST_ERROR_FAILURE;
}
error_code_name = (char*) calloc(error_code_name_length, sizeof(char));
if (NULL == error_code_name) {
unsigned long long length_converted = error_code_name_length;
print_text("Could not allocate memory: %llu bytes\n", length_converted);
return VANILLAPDF_TEST_ERROR_FAILURE;
}
RETURN_ERROR_IF_NOT_SUCCESS(Errors_GetPrintableErrorText(error, error_code_name, error_code_name_length));
if (error_message_length == 0) {
print_text("Error %u (%s)\n", error, error_code_name);
} else {
print_text("Error %u (%s): %s\n", error, error_code_name, error_message);
}
free(error_message);
free(error_code_name);
return VANILLAPDF_TEST_ERROR_SUCCESS;
}
@ LoggingSeverity_Off
Logging is turned off entirely.
Definition c_logging.h:74
Represents memory stored data.
A name object is an atomic symbol uniquely defined by a sequence of characters.
const boolean_type VANILLAPDF_RV_TRUE
Represents the boolean true value.
const boolean_type VANILLAPDF_RV_FALSE
Represents the boolean false value.
const error_type VANILLAPDF_ERROR_OBJECT_MISSING
A dependent object was not found.
const error_type VANILLAPDF_ERROR_DUPLICATE_KEY
Raise when trying to insert already existing key into the dictionary.
const error_type VANILLAPDF_ERROR_PARAMETER_VALUE
An invalid parameter value to function call was passed.
const error_type VANILLAPDF_ERROR_SUCCESS
Indicates that the operation completed successfully.
const error_type VANILLAPDF_ERROR_GENERAL
An unknown error has occurred.
const error_type VANILLAPDF_ERROR_PARSE_EXCEPTION
Error during low-level file processing, the document might be damaged.
const error_type VANILLAPDF_ERROR_USER_CANCELLED
Operation was cancelled by user.
const error_type VANILLAPDF_ERROR_ZLIB_DATA
Error in compressed data.
const error_type VANILLAPDF_ERROR_CONVERSION
An invalid object type was passed to function.
const error_type VANILLAPDF_ERROR_INVALID_PASSWORD
Invalid protection password or key.
const error_type VANILLAPDF_ERROR_FILE_DISPOSED
The source file was already disposed.
const error_type VANILLAPDF_ERROR_NOT_SUPPORTED
Operation is currently not supported.
const error_type VANILLAPDF_ERROR_INVALID_LICENSE
Presented license file is not valid.
const error_type VANILLAPDF_ERROR_FILE_NOT_INITIALIZED
The source file was not yet initialized.
const NameObjectHandle * NameConstant_PrintScaling
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_St
Represents PageLabelHandle property.
const NameObjectHandle * NameConstant_PageLabels
Represents type for PageLabelsHandle.
const NameObjectHandle * NameConstant_NumCopies
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_Font
Represents type for FontHandle.
const NameObjectHandle * NameConstant_HideWindowUI
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_S
Represents PageLabelHandle property.
const NameObjectHandle * NameConstant_Duplex
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_Direction
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_Filter
Name for expressing compression filters.
const NameObjectHandle * NameConstant_CenterWindow
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_DCTDecode
Represents DCTDecode filter, see 7.4.8.
const NameObjectHandle * NameConstant_Simplex
Represents Duplex value.
const NameObjectHandle * NameConstant_Version
Represents a catalog's version property.
const NameObjectHandle * NameConstant_PageLabel
Represents type for PageLabelHandle.
const NameObjectHandle * NameConstant_NonFullScreenPageMode
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_Extensions
Represents CatalogHandle property.
const NameObjectHandle * NameConstant_DeveloperExtensions
Represents document DeveloperExtensionsHandle.
const NameObjectHandle * NameConstant_P
Represents PageLabelHandle property.
const NameObjectHandle * NameConstant_Type
Usually represents a dictionary type entry.
const NameObjectHandle * NameConstant_Page
Represents type for PageObjectHandle.
const NameObjectHandle * NameConstant_PageLayout
Represents CatalogHandle property.
const NameObjectHandle * NameConstant_DisplayDocTitle
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_PrintArea
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_Length
Usually represents length of a StreamObjectHandle.
const NameObjectHandle * NameConstant_ASCII85Decode
Represents ASCII85Decode filter, see 7.4.3.
const NameObjectHandle * NameConstant_Root
Represents CatalogHandle entry in document's dictionary.
const NameObjectHandle * NameConstant_FitWindow
Represents ViewerPreferencesHandle* property.
const NameObjectHandle * NameConstant_R2L
Represents ReadingOrder value.
const NameObjectHandle * NameConstant_BaseVersion
Represents DeveloperExtensionHandle property.
const NameObjectHandle * NameConstant_Type0
Represents type for Type0FontHandle.
const NameObjectHandle * NameConstant_PrintPageRange
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_TwoColumnRight
Represents PageLayout value.
const NameObjectHandle * NameConstant_ViewArea
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_DuplexFlipLongEdge
Represents Duplex value.
const NameObjectHandle * NameConstant_ASCIIHexDecode
Represents ASCIIHexDecode filter, see 7.4.2.
const NameObjectHandle * NameConstant_None
Represents PrintScaling value.
const NameObjectHandle * NameConstant_MediaBox
Represents PageObjectHandle property.
const NameObjectHandle * NameConstant_Pages
Represents catalog PageTreeHandle.
const NameObjectHandle * NameConstant_ToUnicode
Represents CharacterMapHandle property.
const NameObjectHandle * NameConstant_HideToolbar
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_OneColumn
Represents PageLayout value.
const NameObjectHandle * NameConstant_AppDefault
Represents PrintScaling value.
const NameObjectHandle * NameConstant_True
Represents DocumentTrappedType value.
const NameObjectHandle * NameConstant_Catalog
Represents type for CatalogHandle.
const NameObjectHandle * NameConstant_Contents
Represents page PageContentsHandle.
const NameObjectHandle * NameConstant_HideMenubar
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_TwoPageRight
Represents PageLayout value.
const NameObjectHandle * NameConstant_Link
Represents type for LinkAnnotationHandle.
const NameObjectHandle * NameConstant_False
Represents DocumentTrappedType value.
const NameObjectHandle * NameConstant_PrintClip
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_DuplexFlipShortEdge
Represents Duplex value.
const NameObjectHandle * NameConstant_FlateDecode
Represents FlateDecode filter, see 7.4.4.
const NameObjectHandle * NameConstant_PickTrayByPDFSize
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_ViewClip
Represents ViewerPreferencesHandle property.
const NameObjectHandle * NameConstant_SinglePage
Represents PageLayout value.
const NameObjectHandle * NameConstant_ExtensionLevel
Represents DeveloperExtensionHandle property.
const NameObjectHandle * NameConstant_L2R
Represents ReadingOrder value.
const NameObjectHandle * NameConstant_ViewerPreferences
Represents document ViewerPreferencesHandle.
const NameObjectHandle * NameConstant_TwoColumnLeft
Represents PageLayout value.
const NameObjectHandle * NameConstant_TwoPageLeft
Represents PageLayout value.
uint32_t error_type
This is return value type of all API functions.
Definition c_types.h:25
int32_t integer_type
32-bit signed integer
Definition c_types.h:51
int8_t boolean_type
Boolean type supported in C.
Definition c_types.h:31
uint32_t size_type
Size type defined in standard library.
Definition c_types.h:62
const char * string_type
C-Style string.
Definition c_types.h:82
PDFVersion
Range of available PDF versions.
Definition c_pdf_version.h:22
@ PDFVersion_10
PDF version 1.0.
Definition c_pdf_version.h:29
@ PDFVersion_20
PDF version 2.0.
Definition c_pdf_version.h:69
@ PDFVersion_17
PDF version 1.7.
Definition c_pdf_version.h:64
@ PDFVersion_15
PDF version 1.5.
Definition c_pdf_version.h:54
@ PDFVersion_16
PDF version 1.6.
Definition c_pdf_version.h:59
@ PDFVersion_14
PDF version 1.4.
Definition c_pdf_version.h:49
@ PDFVersion_13
PDF version 1.3.
Definition c_pdf_version.h:44
@ PDFVersion_12
PDF version 1.2.
Definition c_pdf_version.h:39
@ PDFVersion_11
PDF version 1.1.
Definition c_pdf_version.h:34
Sometimes the error code and message is not enough to solve the problem. Library also supports logging, that can be configured via Logging. Logging have multiple log levels, which control the verbosity of the output.
Following snippet enables the logging feature with the highest possible logging severity.