Access to PageDictionary or Document Catalog

Hi Aspose team,

we are looking into inserting additional metadata into PDF document that would be later available to extract programmatically (to for example copy part of document marked by it) other than bookmarks. Seems that there are some options built-in PDF document, but we are not sure how to access them:

  • Page dictionary
  • Document catalog editor

both allows us to insert for example SectionStart to mark some place in document on page. Could you please let us know if we can access those metadata in the code?

Thanks,
Mateusz

@acturisaspose

We need to investigate further about your requirements. Could you kindly share a sample PDF document which is your expected one. Also, please highlight the parts in the PDF structure which you want to modify or add using the API. We will further proceed to assist you accordingly.

Hi @asad.ali,

please find the example documents attached. At the moment they are just empty pdf files with features mentioned above added. My goal is to find out on what page the content of Page Dictionary or Document Catalog is. Ideally I’d like to know where exactly on the page this can be found, and when having two such objects (say SectionStart and SectionEnd wit the same value) to be able to extacr content that lives between them.

Examples.zip (5.2 KB)

Please let me know if you need any additional information.

Thanks,
Mateusz

@acturisaspose

Please check the attached screenshot which we obtained after opening one of your PDF files in notepad. catalog.png (7.2 KB) Is it the same Catalog for which you want to get the whereabouts? Also, we tried to check the Page Dictionary as well but could not find it. Could you please share how we can observe it in notepad or in any other utility?

Hi @asad.ali,

unfortunately I’m not familiar with pdf file internals, so I cannot answer based on raw file content. Page dictionary can be edited using Adobe Acrobat Reader as following:

  1. In Adobe Acrobat, user Selects the Content Option, then clicks on the pdf form to update. This expands the pdf file’s content, presenting the list of available pages.
  2. User right clicks on the first page, then in the context menu, Edit Page Dictionary option needs to be selected.
  3. In the Page Dictionary Editor, select the New Item option.
  4. On the Add Key and Value pop up add key and value. Confirm the update by clicking OK on the pop up and Page Dictionary editor.

@acturisaspose

We have logged an investigation ticket for the feature that you are looking for. The ticket ID is PDFNET-49641 and it has been associated with this forum thread. You will surely be notified as soon as it is completely investigated and resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-49641) have been fixed in Aspose.PDF for .NET 24.1.

@acturisaspose

A newly inroduced DictionaryEditor in 24.1 version of the API works the same for page and document dictionary.

There are some default keys that we can’t modify.

These keys are contained in an empty new page:

  • Contents,
  • MediaBox,
  • Parent,
  • Resources,
  • Type

These keys are contained in an empty new document:

  • Outlines,
  • Pages,
  • Version,
  • Type

Here are examples of code for DictionaryEditor.

Example 1. Add new values.

// example of key's names
string KEY_NAME = "name";
string KEY_STRING = "str";
string KEY_BOOL = "bool";
string KEY_NUMBER = "number";

var outputPath = "page_dictionary_editor.pdf";
using (var doc = new Document())
{
    var page = doc.Pages.Add();
    var dictionaryEditor = new DictionaryEditor(page);

    dictionaryEditor.Add(KEY_NAME, new CosPdfName("name data"));
    dictionaryEditor.Add(KEY_STRING, new CosPdfString("string data"));
    dictionaryEditor.Add(KEY_BOOL, new CosPdfBoolean(true));
    dictionaryEditor.Add(KEY_NUMBER, new CosPdfNumber(11.2));

    doc.Save(outputPath);
}

Example 2. Add and set values to dictionary.

using (var doc = new Document())
{
    var page = doc.Pages.Add();
    var dictionaryEditor = new DictionaryEditor(page);
    dictionaryEditor.Add(KEY_NAME, new CosPdfName("Old name"));
    // or 
    dictionaryEditor[KEY_NAME] = new CosPdfName("New name");
}

Example 3. Get value from dictionary.

using (var doc = new Document())
{
    var page = doc.Pages.Add();
    var dictionaryEditor = new DictionaryEditor(page);
    dictionaryEditor[KEY_NAME] = new CosPdfName("name");
    var value = dictionaryEditor[KEY_NAME];
    // or 
    ICosPdfPrimitive primitive;
    dictionaryEditor.TryGetValue(KEY_NAME, out primitive);
}

Example 4. Remove value from dictionary.

using (var doc = new Document())
{
    var page = doc.Pages.Add();
    var dictionaryEditor = new DictionaryEditor(page);
    dictionaryEditor.Add(KEY_NAME, new CosPdfName(EXPECTED_NAME));
    dictionaryEditor.Remove(KEY_NAME);
}