File image extaction full example.
#include "tools.h"
void print_extract_help() {
printf("Usage: extract -s [source file]");
}
unsigned long long object_number_converted = 0;
unsigned int generation_number_converted = 0;
int return_value = 0;
char output_filename[256] = { 0 };
if (!contains_type || !contains_subtype) {
goto err;
}
RETURN_ERROR_IF_NOT_SUCCESS(
DictionaryObject_Find(stream_dictionary, NameConstant_Subtype, &subtype_object));
goto err;
}
RETURN_ERROR_IF_NOT_SUCCESS(
NameObject_Equals(type_name, NameConstant_XObject, &is_type_xobject));
RETURN_ERROR_IF_NOT_SUCCESS(
NameObject_Equals(subtype_name, NameConstant_Image, &is_subtype_image));
if (!is_type_xobject || !is_subtype_image) {
goto err;
}
object_number_converted = object_number;
generation_number_converted = generation_number;
return_value = snprintf(output_filename, sizeof(output_filename), "%llu.%u.jpeg", object_number_converted, generation_number_converted);
if (return_value < 0) {
printf("Could not create destination filename");
return VANILLAPDF_TOOLS_ERROR_FAILURE;
}
if (contains_width && contains_height && contains_colorspace) {
RETURN_ERROR_IF_NOT_SUCCESS(
DictionaryObject_Find(stream_dictionary, NameConstant_Width, &width_object));
RETURN_ERROR_IF_NOT_SUCCESS(
DictionaryObject_Find(stream_dictionary, NameConstant_Height, &height_object));
RETURN_ERROR_IF_NOT_SUCCESS(
DictionaryObject_Find(stream_dictionary, NameConstant_ColorSpace, &colorspace_object));
}
}
}
err:
if (type_object != NULL) {
type_object = NULL;
}
if (subtype_object != NULL) {
subtype_object = NULL;
}
if (type_name != NULL) {
type_name = NULL;
}
if (subtype_name != NULL) {
subtype_name = NULL;
}
if (stream_dictionary != NULL) {
stream_dictionary = NULL;
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
RETURN_ERROR_IF_NOT_SUCCESS(process_stream(stream, object_number, generation_number));
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
RETURN_ERROR_IF_NOT_SUCCESS(process_object(obj, object_number, generation_number));
}
RETURN_ERROR_IF_NOT_SUCCESS(process_object(obj, object_number, generation_number));
}
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
RETURN_ERROR_IF_NOT_SUCCESS(process_xref(xref));
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
unsigned long long page_number_converted = page_number;
for (i = 0; i < contents_size; ++i) {
int return_value = 0;
unsigned long long i_converted = i;
char output_filename[256] = {0};
continue;
}
continue;
}
return_value = snprintf(output_filename, sizeof(output_filename), "%llu.%llu", page_number_converted, i_converted);
if (return_value < 0) {
printf("Could not create destination filename");
return VANILLAPDF_TOOLS_ERROR_FAILURE;
}
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
int process_extract(int argc, char *argv[]) {
const char *filename = NULL;
int arg_counter = 0;
for (arg_counter = 0; arg_counter < argc; ++arg_counter) {
if (strcmp(argv[arg_counter], "-s") == 0 && (arg_counter + 1 < argc)) {
filename = argv[arg_counter + 1];
arg_counter++;
} else {
print_extract_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
}
if (filename == NULL) {
print_extract_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
RETURN_ERROR_IF_NOT_SUCCESS(
File_Open(filename, &file));
RETURN_ERROR_IF_NOT_SUCCESS(process_file(file));
for (i = 0; i < page_count; ++i) {
RETURN_ERROR_IF_NOT_SUCCESS(process_page_contents(page_contents, i + 1));
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}
XrefEntryType
Required for conversion to derived types.
Definition: c_xref.h:94
@ XrefEntryType_Compressed
Represents compressed entry within cross-reference section.
Definition: c_xref.h:125
@ XrefEntryType_Used
Represents used entry within cross-reference section.
Definition: c_xref.h:119
Represents memory stored data.
error_type CALLING_CONVENTION Buffer_Release(BufferHandle *handle)
Decrement the internal reference counter.
The root of a document's object hierarchy.
error_type CALLING_CONVENTION Catalog_Release(CatalogHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION Catalog_GetPages(CatalogHandle *handle, PageTreeHandle **result)
The root of the document's page tree (see 7.7.3, "Page Tree").
Base class for all content objects and operations.
error_type CALLING_CONVENTION ContentInstruction_Release(ContentInstructionHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION ContentInstruction_GetInstructionType(ContentInstructionHandle *handle, ContentInstructionType *result)
Get derived type of current object.
A sequence of content instructions grouped within a single object.
error_type CALLING_CONVENTION ContentObject_ToInlineImage(ContentObjectHandle *handle, ContentObjectInlineImageHandle **result)
Reinterpret current object as ContentObjectInlineImageHandle.
error_type CALLING_CONVENTION ContentObject_GetObjectType(ContentObjectHandle *handle, ContentObjectType *result)
Get derived type of current object.
error_type CALLING_CONVENTION ContentObject_FromInstruction(ContentInstructionHandle *handle, ContentObjectHandle **result)
Convert ContentInstructionHandle to ContentObjectHandle.
error_type CALLING_CONVENTION ContentObject_Release(ContentObjectHandle *handle)
Decrement the internal reference counter.
As an alternative to the image XObjects described in section 8.9.5 - Image Dictionaries,...
error_type CALLING_CONVENTION ContentObjectInlineImage_Release(ContentObjectInlineImageHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION ContentObjectInlineImage_GetDictionary(ContentObjectInlineImageHandle *handle, DictionaryObjectHandle **result)
Get meta-data dictionary for inline image.
error_type CALLING_CONVENTION ContentObjectInlineImage_GetData(ContentObjectInlineImageHandle *handle, BufferHandle **result)
Get raw image data.
The DCTDecode filter decodes grayscale or colour image data that has been encoded in the JPEG baselin...
error_type CALLING_CONVENTION DCTDecodeFilter_Create(DCTDecodeFilterHandle **result)
Creates a new filter instance.
error_type CALLING_CONVENTION DCTDecodeFilter_EncodeParams(DCTDecodeFilterHandle *handle, BufferHandle *data, DictionaryObjectHandle *parameters, BufferHandle **result)
Encodes source data and returns encoded result data.
error_type CALLING_CONVENTION DCTDecodeFilter_Release(DCTDecodeFilterHandle *handle)
Decrement the internal reference counter.
A dictionary object is an associative table containing pairs of objects.
error_type CALLING_CONVENTION DictionaryObject_Contains(DictionaryObjectHandle *handle, const NameObjectHandle *key, boolean_type *result)
Determine if collection contains key.
error_type CALLING_CONVENTION DictionaryObject_Find(DictionaryObjectHandle *handle, const NameObjectHandle *key, ObjectHandle **result)
Find mapped value for key key.
error_type CALLING_CONVENTION DictionaryObject_InsertConst(DictionaryObjectHandle *handle, const NameObjectHandle *key, ObjectHandle *value, boolean_type overwrite)
Insert new key-value pair into collection.
error_type CALLING_CONVENTION DictionaryObject_Release(DictionaryObjectHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION DictionaryObject_Create(DictionaryObjectHandle **result)
Creates a new dictionary instance.
Represents high-level file access handle.
error_type CALLING_CONVENTION Document_GetCatalog(DocumentHandle *handle, CatalogHandle **result)
Get document's catalog property.
error_type CALLING_CONVENTION Document_OpenFile(FileHandle *holder, DocumentHandle **result)
Opens a document using already existing file handle.
error_type CALLING_CONVENTION Document_Release(DocumentHandle *handle)
Decrement the internal reference counter.
Represents low-level file access handle.
error_type CALLING_CONVENTION File_XrefChain(FileHandle *handle, XrefChainHandle **result)
Get chain of xref tables for iteration.
error_type CALLING_CONVENTION File_Release(FileHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION File_Open(string_type filename, FileHandle **result)
Opens a file for reading.
error_type CALLING_CONVENTION File_Initialize(FileHandle *handle)
Perform basic intialization.
A name object is an atomic symbol uniquely defined by a sequence of characters.
error_type CALLING_CONVENTION NameObject_Equals(const NameObjectHandle *handle, const NameObjectHandle *other, boolean_type *result)
Compares two name objects.
error_type CALLING_CONVENTION NameObject_Release(NameObjectHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION NameObject_FromObject(ObjectHandle *handle, NameObjectHandle **result)
Convert ObjectHandle to NameObjectHandle.
Base class for syntactic tokens.
error_type CALLING_CONVENTION Object_GetObjectType(ObjectHandle *handle, ObjectType *result)
Get derived type of current object.
error_type CALLING_CONVENTION Object_Release(ObjectHandle *handle)
Decrement the internal reference counter.
Output stream can write sequences of characters and represent other kinds of data.
error_type CALLING_CONVENTION OutputStream_Release(OutputStreamHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION OutputStream_Flush(OutputStreamHandle *handle)
Flushes all pending data from the stream to it's destination.
error_type CALLING_CONVENTION OutputStream_WriteBuffer(OutputStreamHandle *handle, BufferHandle *data)
Appends buffer data to current output stream instance.
error_type CALLING_CONVENTION OutputStream_CreateFromFile(string_type filename, OutputStreamHandle **result)
Creates a new file at filename location and opens it for writing.
A content stream is a PDF stream object whose data consists of a sequence of instructions describing ...
error_type CALLING_CONVENTION PageContents_Release(PageContentsHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION PageContents_GetInstructionAt(PageContentsHandle *handle, size_type at, ContentInstructionHandle **result)
Get instruction at location at.
error_type CALLING_CONVENTION PageContents_GetInstructionsSize(PageContentsHandle *handle, size_type *result)
Return size of a collection.
The leaves of the page tree are page objects, each of which is a dictionary specifying the attributes...
error_type CALLING_CONVENTION PageObject_Release(PageObjectHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION PageObject_GetContents(PageObjectHandle *handle, PageContentsHandle **result)
A content stream (see 7.8.2, "Content Streams") that shall describe the contents of this page....
The pages of a document are accessed through a structure known as the page tree, which defines the or...
error_type CALLING_CONVENTION PageTree_Release(PageTreeHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION PageTree_GetPageCount(PageTreeHandle *handle, size_type *result)
Get total number of pages in current document.
error_type CALLING_CONVENTION PageTree_GetPage(PageTreeHandle *handle, size_type at, PageObjectHandle **result)
Get page at index at.
Stream object represents compressed data inside document.
error_type CALLING_CONVENTION StreamObject_GetBodyRaw(StreamObjectHandle *handle, BufferHandle **result)
Get uncompressed stream body.
error_type CALLING_CONVENTION StreamObject_GetBody(StreamObjectHandle *handle, BufferHandle **result)
Get decompressed stream content.
error_type CALLING_CONVENTION StreamObject_GetHeader(StreamObjectHandle *handle, DictionaryObjectHandle **result)
Return streams header dictionary.
error_type CALLING_CONVENTION StreamObject_FromObject(ObjectHandle *handle, StreamObjectHandle **result)
Convert ObjectHandle to StreamObjectHandle.
error_type CALLING_CONVENTION StreamObject_Release(StreamObjectHandle *handle)
Decrement the internal reference counter.
An ordered collection of all XrefHandle within the PDF file.
error_type CALLING_CONVENTION XrefChain_GetIterator(XrefChainHandle *handle, XrefChainIteratorHandle **result)
Get cross-reference section iterator.
error_type CALLING_CONVENTION XrefChain_Release(XrefChainHandle *handle)
Decrement the internal reference counter.
A pointer to XrefHandle within XrefChainHandle collection.
error_type CALLING_CONVENTION XrefChainIterator_IsValid(XrefChainIteratorHandle *handle, boolean_type *result)
Determine if the current iterator position is valid.
error_type CALLING_CONVENTION XrefChainIterator_Next(XrefChainIteratorHandle *handle)
Advance iterator to the next position.
error_type CALLING_CONVENTION XrefChainIterator_Release(XrefChainIteratorHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION XrefChainIterator_GetValue(XrefChainIteratorHandle *handle, XrefHandle **result)
Get cross-reference section from current iterator position.
Represents compressed entry within cross-reference section.
error_type CALLING_CONVENTION XrefCompressedEntry_FromEntry(XrefEntryHandle *handle, XrefCompressedEntryHandle **result)
Convert XrefEntryHandle to XrefUsedEntryHandle.
error_type CALLING_CONVENTION XrefCompressedEntry_Release(XrefCompressedEntryHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION XrefCompressedEntry_GetReference(XrefCompressedEntryHandle *handle, ObjectHandle **result)
Get reference to the object represented by this entry.
Cross-reference entry represents item within XrefHandle.
error_type CALLING_CONVENTION XrefEntry_GetObjectNumber(XrefEntryHandle *handle, biguint_type *result)
Get entry object number.
error_type CALLING_CONVENTION XrefEntry_GetType(XrefEntryHandle *handle, XrefEntryType *result)
Get entry type.
error_type CALLING_CONVENTION XrefEntry_GetGenerationNumber(XrefEntryHandle *handle, ushort_type *result)
Get entry generation number.
error_type CALLING_CONVENTION XrefEntry_Release(XrefEntryHandle *handle)
Decrement the internal reference counter.
The cross-reference table contains information that permits random access to indirect objects within ...
error_type CALLING_CONVENTION Xref_GetIterator(XrefHandle *handle, XrefIteratorHandle **result)
Get cross-reference entry iterator.
error_type CALLING_CONVENTION Xref_Release(XrefHandle *handle)
Decrement the internal reference counter.
A pointer to XrefEntryHandle within XrefHandle collection.
error_type CALLING_CONVENTION XrefIterator_GetValue(XrefIteratorHandle *handle, XrefEntryHandle **result)
Get cross-reference entry from current iterator position.
error_type CALLING_CONVENTION XrefIterator_IsValid(XrefIteratorHandle *handle, boolean_type *result)
Check if the current iterator position is valid.
error_type CALLING_CONVENTION XrefIterator_Next(XrefIteratorHandle *handle)
Advance iterator to the next position.
error_type CALLING_CONVENTION XrefIterator_Release(XrefIteratorHandle *handle)
Decrement the internal reference counter.
Represents used entry within cross-reference section.
error_type CALLING_CONVENTION XrefUsedEntry_Release(XrefUsedEntryHandle *handle)
Decrement the internal reference counter.
error_type CALLING_CONVENTION XrefUsedEntry_FromEntry(XrefEntryHandle *handle, XrefUsedEntryHandle **result)
Convert XrefEntryHandle to XrefUsedEntryHandle.
error_type CALLING_CONVENTION XrefUsedEntry_GetReference(XrefUsedEntryHandle *handle, ObjectHandle **result)
Get reference to the object represented by this entry.
const boolean_type VANILLAPDF_RV_TRUE
Represents the boolean true value.
const boolean_type VANILLAPDF_RV_FALSE
Represents the boolean false value.
ContentObjectType
Derived types of ContentObjectHandle.
Definition: c_content_object.h:49
ContentInstructionType
Available content instruction types.
Definition: c_content_instruction.h:43
@ ContentObjectType_InlineImage
As an alternative to the image XObjects described in section 8.9.5 - Image Dictionaries,...
Definition: c_content_object.h:61
@ ContentInstructionType_Object
A sequence of content instructions grouped within a single object.
Definition: c_content_instruction.h:56
const error_type VANILLAPDF_ERROR_SUCCESS
Indicates that the operation completed successfully.
const NameObjectHandle * NameConstant_Type
Usually represents a dictionary type entry.
ObjectType
Derived types of ObjectHandle.
Definition: c_object.h:29
@ ObjectType_Stream
Stream object represents compressed data inside document.
Definition: c_object.h:82
@ ObjectType_Integer
Integer objects represent mathematical integers.
Definition: c_object.h:64
@ ObjectType_Name
A name object is an atomic symbol uniquely defined by a sequence of characters.
Definition: c_object.h:70
uint32_t error_type
This is return value type of all API functions.
Definition: c_types.h:25
uint64_t biguint_type
64-bit unsigned integer type
Definition: c_types.h:77
uint16_t ushort_type
16-bit unsigned integer
Definition: c_types.h:46
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