-
-
Save yakubin/63a7c94d9fee345a33fb to your computer and use it in GitHub Desktop.
Two programs to test poppler document property getters & setters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <gio/gio.h> | |
#include <poppler.h> | |
#include <stdio.h> | |
void smartprint_str(const char *label, const char *value) { | |
printf("%s: ", label); | |
if (value == NULL) { | |
printf("none\n"); | |
} else { | |
printf("%s\n", value); | |
} | |
} | |
void smartprint_time(const char *label, time_t value) { | |
printf("%s: ", label); | |
if (value == -1) { | |
printf("none\n"); | |
} else { | |
printf("%s", asctime(gmtime(&value))); | |
} | |
} | |
int main(int argc, char * argv[]) { | |
assert(argc == 2); | |
GFile *file = g_file_new_for_path(argv[1]); | |
GError *err = NULL; | |
PopplerDocument *doc = poppler_document_new_from_gfile(file, NULL, NULL, &err); | |
if (doc == NULL) { | |
fprintf(stderr, "%s\n", err->message); | |
return 1; | |
} | |
char *title = poppler_document_get_title(doc); | |
char *author = poppler_document_get_author(doc); | |
char *subject = poppler_document_get_subject(doc); | |
char *keywords = poppler_document_get_keywords(doc); | |
char *creator = poppler_document_get_creator(doc); | |
char *producer = poppler_document_get_producer(doc); | |
time_t creation_date = poppler_document_get_creation_date(doc); | |
time_t modification_date = poppler_document_get_modification_date(doc); | |
smartprint_str("Title", title); | |
smartprint_str("Author", author); | |
smartprint_str("Subject", subject); | |
smartprint_str("Keywords", keywords); | |
smartprint_str("Creator", creator); | |
smartprint_str("Producer", producer); | |
smartprint_time("CreationDate", creation_date); | |
smartprint_time("ModDate", modification_date); | |
g_free(title); | |
g_free(author); | |
g_free(subject); | |
g_free(keywords); | |
g_free(creator); | |
g_free(producer); | |
g_object_unref(doc); | |
g_object_unref(file); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <gio/gio.h> | |
#include <poppler.h> | |
#include <stdio.h> | |
int main(int argc, char * argv[]) { | |
assert(argc == 2); | |
GFile *file = g_file_new_for_path(argv[1]); | |
GError *err = NULL; | |
PopplerDocument *doc = poppler_document_new_from_gfile(file, NULL, NULL, &err); | |
if (doc == NULL) { | |
goto fail; | |
} | |
poppler_document_set_title(doc, "New title"); | |
poppler_document_set_author(doc, "New author"); | |
poppler_document_set_subject(doc, "New subject"); | |
poppler_document_set_keywords(doc, "New keywords"); | |
poppler_document_set_creator(doc, "New creator"); | |
poppler_document_set_producer(doc, "New producer"); | |
static const time_t new_time = 692496000; // 1991-12-12 | |
poppler_document_set_creation_date(doc, new_time); | |
poppler_document_set_modification_date(doc, new_time); | |
char *filename = g_strconcat(argv[1], ".new", NULL); | |
char *uri = g_filename_to_uri(filename, NULL, NULL); | |
gboolean success = poppler_document_save(doc, uri, &err); | |
if (!success) { | |
goto fail; | |
} | |
g_free(uri); | |
g_free(filename); | |
g_object_unref(doc); | |
g_object_unref(file); | |
return 0; | |
fail: | |
fprintf(stderr, "%s\n", err->message); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment