This tutorial illustrates how to access DjVu metadata.
Step 1: Initialization
To use DjVu SDK, you firstly include several headers.
using namespace Celartem;
using namespace Celartem::DjVu;
Step 2: Loading a DjVu file
Load a DjVu file using Document::create method.
- Warning
- Without setting appropriate license script, decoding function (DjVuDecode feature) will stop working after 2 weeks from the its built time. See License System for more information.
Step 3: Accessing Document Level Metadata
DjVu has metadata both on the document level and on the page level. Each document can have its metadata and each page also can have its own page level metadata.
So anyway, on the step, we try to access the document level metadata:
AutoPtr<PropertySet> propSet = doc->getSharedAnnotation()->properties;
String title = propSet->get("Title");
AutoPtr<PropertySetIterator> it = propSet->enumProperties();
while(it->next())
{
printf("%s=%s\n", it->getKey().c_str(), it->getValue().c_str());
}
propSet->set("Title", "New Title");
propSet->remove("Author");
doc->updateChunks();
doc->getChunk()->disconnectFromOriginalSources();
doc->save("metadata_test.djvu");
doc->save("other.djvu")
Step 4: Accessing Page Level Metadata
For the page level metadata, the process is almost same but we just load the metadata from Page method:
AutoPtr<Page> page = doc->getPages()[0];
AutoPtr<PropertySet> pagePropSet = page->getAnnotation()->properties;
Normally, for a DjVu file, we prefer the document level metadata but you can also add metadata for each page if you want to do that.