Export to PDF using Bookmarks

Sergey Sherstnev

July 07, 2022

When you export a complex drawing to a PDF file or create a PDF file based on the content of several drawings, you may want to use bookmarks to organize the navigation in the resulting PDF document.

The PDF export module creates a bookmark for every exported layout. When the user clicks a bookmark, the corresponding page of the PDF document becomes active.

By default, bookmarks are named according to the names of layouts. But the names of bookmarks created for the corresponding layouts can be customized by calling the setLayoutNames() method of the PDFExportParams class. The names of bookmarks in the output PDF document are added after the layout names.

It is important to remember that the size of the array that contains the names must be the same size as the array of layouts that are exported to a PDF document.

If you export only the active layout (i.e., when a layout may not be set), the array of layout names must consist of only one element.

The following code fragment is an example of setting layout names in an application:

PDFExportParams params;

//Setting other export parameters

OdStringArray layoutNames = params.layouts();

for(OdUInt32 i = 0; i < layoutNames.size(); i++)
{
   layoutNames[i] = L"Page " + odDToStr(i + 1, 'G', 6) +  ": " + layoutNames[i];
}
params.setLayoutNames(layoutNames);

See Export Layouts and Set Page Parameters for PDF for additional information about exporting layouts.

You can also export named views from the original drawing as PDF views and bookmarks.

A named view is a custom view that provides a point from which to view a particular part of a drawing (as in the picture below).

 

A named view is a custom view that provides a point of viewing a particular part of the drawing

 

Some named views can be exported to PDF as bookmarks too. For example:

 

The resulting PDF document is illustrated

 

Only named views that are parallel to the plane of the exported layout can be exported to PDF. For example, if a layout that shows the top of a model is exported, named views that show the drawing from other directions (right, bottom, etc.) are not exported. Even if the angle between the named view and the plane of the exported layout is a little more than zero, the view is not exported.

NOTE: Named views cannot be renamed and are always exported to a PDF document with their original names from the drawing.

To export layouts and named views as bookmarks, use the enableBookmarks() method of the PDFExportParams class.

PDFExportParams params;
params.enableBookmarks(true);

To find out whether bookmarks are enabled, call the bookmarksEnabled() method of the PDFExportParams class.

If there are no bookmarks in the exported multi-page PDF document, another way to navigate it is using thumbnails. When the array with layout names is correctly set to the PDFExportParams. object, it is applied to thumbnail names as well. Even if bookmarks are disabled (by calling the enableBookmarks() method with false), the array of layout names is used for the names of thumbnails in the resulting PDF document.

To get more information please refer to ODA Documentation.