From 06fc1f325834272dd75fc24fe3f44ac8b0724538 Mon Sep 17 00:00:00 2001 From: Evangelos Rigas Date: Tue, 10 Jul 2018 23:08:26 +0100 Subject: [PATCH] Add support for PDF subtype property (glib backend) Reads GTS_PDFA1Version and GTS_PDFXVersion from the PDF Information Dictionary. If is not `NULL` the string contains the PDF/A or PDF/X version. --- glib/poppler-document.cc | 42 ++++++++++++++++++++++++++++++++++++++++ glib/poppler-document.h | 1 + poppler/PDFDoc.cc | 16 +++++++++++++++ poppler/PDFDoc.h | 1 + 4 files changed, 60 insertions(+) diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index b343eb90..9c920fee 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -58,6 +58,7 @@ enum { PROP_FORMAT, PROP_FORMAT_MAJOR, PROP_FORMAT_MINOR, + PROP_FORMAT_SUBTYPE, PROP_AUTHOR, PROP_SUBJECT, PROP_KEYWORDS, @@ -1352,6 +1353,30 @@ poppler_document_get_permissions (PopplerDocument *document) return (PopplerPermissions)flag; } +/** + * poppler_document_get_format_subtype: + * @document: A #PopplerDocument + * + * Returns the PDF format subtype of the document + * e.g. PDF/A, PDF/X + * + * Return value: a new allocated string containing the PDF + * format subtype of @document, or %NULL + * + * Since: 0.65 + **/ +gchar * +poppler_document_get_format_subtype (PopplerDocument *document) +{ + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + GooString *goo_subtype = document->doc->getDocInfoSubtype(); + gchar *utf8 = _poppler_goo_string_to_utf8(goo_subtype); + delete goo_subtype; + + return utf8; +} + /** * poppler_document_get_metadata: * @document: A #PopplerDocument @@ -1446,6 +1471,9 @@ poppler_document_get_property (GObject *object, case PROP_PERMISSIONS: g_value_set_flags (value, poppler_document_get_permissions (document)); break; + case PROP_FORMAT_SUBTYPE: + g_value_take_string (value, poppler_document_get_format_subtype (document)); + break; case PROP_METADATA: g_value_take_string (value, poppler_document_get_metadata (document)); break; @@ -1724,6 +1752,20 @@ poppler_document_class_init (PopplerDocumentClass *klass) "Embedded XML metadata", nullptr, G_PARAM_READABLE)); + + + /** + * PopplerDocument:format-subtype: + * + * Document PDF subtype and version , or %NULL + */ + g_object_class_install_property (G_OBJECT_CLASS (klass), + PROP_FORMAT_SUBTYPE, + g_param_spec_string ("format-subtype", + "PDF Format Subtype", + "PDF Format Subtype", + nullptr, + G_PARAM_READABLE)); } static void diff --git a/glib/poppler-document.h b/glib/poppler-document.h index a7fcea1d..103fd250 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -230,6 +230,7 @@ gboolean poppler_document_is_linearized (PopplerDocument *doc PopplerPageLayout poppler_document_get_page_layout (PopplerDocument *document); PopplerPageMode poppler_document_get_page_mode (PopplerDocument *document); PopplerPermissions poppler_document_get_permissions (PopplerDocument *document); +gchar *poppler_document_get_format_subtype (PopplerDocument *document); gchar *poppler_document_get_metadata (PopplerDocument *document); /* Attachments */ diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index 631f9a70..ece2b424 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -683,6 +683,22 @@ GooString *PDFDoc::getDocInfoStringEntry(const char *key) { return result; } +GooString *PDFDoc::getDocInfoSubtype() { + GooString *fmt; + + fmt = getDocInfoStringEntry("GTS_PDFA1Version"); + // If PDF subtype is PDF/A return version + if (fmt != nullptr) { + return fmt; + } + + delete fmt; + // Try if PDF subtype is PDF/X and return + return getDocInfoStringEntry("GTS_PDFXVersion"); +} + + + static GBool get_id (const GooString *encodedidstring, GooString *id) { const char *encodedid = encodedidstring->getCString(); diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h index 1678d167..d6f6ae82 100644 --- a/poppler/PDFDoc.h +++ b/poppler/PDFDoc.h @@ -272,6 +272,7 @@ public: GooString *getDocInfoProducer() { return getDocInfoStringEntry("Producer"); } GooString *getDocInfoCreatDate() { return getDocInfoStringEntry("CreationDate"); } GooString *getDocInfoModDate() { return getDocInfoStringEntry("ModDate"); } + GooString *getDocInfoSubtype(); // Return the PDF version specified by the file. int getPDFMajorVersion() { return pdfMajorVersion; } -- 2.18.0