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));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_GetType(type_object, &type_object_type));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_GetType(subtype_object, &subtype_object_type));
goto err;
}
RETURN_ERROR_IF_NOT_SUCCESS(
Object_ToName(type_object, &type_name));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_ToName(subtype_object, &subtype_name));
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));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_GetType(width_object, &width_object_type));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_GetType(height_object, &height_object_type));
RETURN_ERROR_IF_NOT_SUCCESS(
Object_GetType(colorspace_object, &colorspace_object_type));
}
}
}
err:
if (type_object != NULL) {
type_object = NULL;
}
if (subtype_object != NULL) {
subtype_object = 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(
Xref_Iterator(xref, &xref_iterator));
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;
if (argc < 2) {
print_extract_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (0 != strcmp(argv[0], "-s")) {
print_extract_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
filename = argv[1];
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_contents(page_contents, i + 1));
}
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}