Getting started

keyboard_arrow_down
Running samplesTry demo in your projectDownloading PDFTronIntegrating PDFTron via GradleManually integrating PDFTronUpgradingAdding PDFTron license keyUsing ProGuardTroubleshooting integration

Fundamentals

keyboard_arrow_down
Document lockingSaving PDF documentsUnderstanding coordinates

Basics

keyboard_arrow_down
Using an ActivityUsing a FragmentUsing PDFViewCtrlViewer configConverting and viewing other document typesConverting HTML to PDF

Viewer

keyboard_arrow_down
PDFViewCtrl color modesPDFViewCtrl page view modePDFViewCtrl page presentation modeGenerating thumbnails in PDF

Features

keyboard_arrow_down
Day/Night themesUndo and redoText searchAnnotation syncingRotating PDF pagesPDFViewCtrl read onlyUsing PDFViewCtrl with minimum memory

Tools

keyboard_arrow_down
Tools overviewSetting Up ToolManagerChanging and disabling toolsIntercepting annotation handlingToolManager eventsDefault annotation propertiesTool subclasses

Annotations

keyboard_arrow_down
Deleting annotationsAnnotation styleShow/hide annotations

UI components

keyboard_arrow_down
Quick menuAnnotation toolbarAnnotation style dialogThumbnail sliderAnnotations listOutline listUser bookmarks listBookmarks dialogPage thumbnails dialogAdd page dialogRotate pages dialogView mode dialogCrop page dialogReflow

Advanced

keyboard_arrow_down
Adding a custom view to a PDF pageCustom toolCustomizing quick menuCustomizing annotation style dialog

FAQ

keyboard_arrow_down
Running project in Android StudioSystem RequirementsPDFTron full vs. standardLocalizationIcon cheat sheetRunning sample with sourceReducing size of APKEnable multidexOut of memory when rotating device multiple timesDetachCurrentThread warning

PDF Processing API

keyboard_arrow_down
What is PDFNet?Opening a documentSerializing (saving) a documentWorking with pagesWorking with Page ContentWorking with BookmarksWorking with Interactive Forms (AcroForms)PDF SecurityLow-level PDF APIError handling
Customizing quick menukeyboard_arrow_down

Customize quick menu

In this document
chevron_rightCreation quick menu
chevron_rightEditing quick menu
chevron_rightCreate a quick menu
chevron_rightShow the quick menu
chevron_rightEvents
chevron_rightStyles
chevron_rightBackground
chevron_rightDivider

It is possible to override the default QuickMenu as well as to create one of your own.

linkOverride existing quick menu

There are two types of quick menu: the creation quick menu that shows upon long press on blank space or text, and the editing quick menu that shows up upon selecting an existing annotation.

To override an existing quick menu resource, first identify which one you are interested in changing:

linkCreation quick menu

Menu resourceToolTriggered event
R.panPanLong press on blank space
R.text_selectTextSelectLong press on text

linkEditing quick menu

Menu resourceToolTriggered event
R.annot_simple_shapeAnnotEditSingle tap on Square , Circle , Line , Polygon , Polyline , Text
R.annot_free_textAnnotEditSingle tap on FreeText
R.annot_linkAnnotEditSingle tap on Link
R.annot_signatureAnnotEditSingle tap on signature (type: Annot.e_Stamp and custom field: Signature.SIGNATUREANNOTATIONID )
R.annot_stamperAnnotEditSingle tap on Stamp (type: Annot.e_Stamp and custom field: Stamper.STAMPERANNOTATIONID )
R.annot_file_attachmentAnnotEditSingle tap on FileAttachment
R.annot_free_handAnnotEditSingle tap on Ink
R.annot_generalAnnotEditSingle tap on all other annotation types
R.annot_edit_text_markupAnnotEditTextMarkupSingle tap on TextMarkup annotations
R.typeAnnotEditTextMarkupClick quick menu item with id R.id.type
R.sig_field_imageDigitalSignatureSingle tap on digital image signature
R.annot_edit_thicknessDigitalSignatureClick quick menu item with id R.id.thickness
R.sig_field_pathsDigitalSignatureSingle tap on digital signature, or click on items in quick menu R.menu.annot_edit_thickness
R.sigSignatureIf a custom signature already exsits, show quick menu when creating a signature or when single tapped on a signature field

linkReplace menu resource

Now, say you only want to show free text and signature tools in the first row when Pan tool long press event is triggered, you can override R.menu.pan in your own project as follows:

In res/menu/pan.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/free_text"
        android:title="@string/annot_free_text"
        android:icon="@drawable/annotation_free_text" />
    <item android:id="@+id/floating_sig"
        android:icon="@drawable/annotation_signature"
        android:title="@string/tools_signature" />
</menu>
Add @+id/free_text and @+id/floating_sig ids to the quick menu item so Pan tool can recognize them when quick menu item is clicked.

Then, when long pressing on a blank space, you will see:

linkCreate a quick menu

You can use QuickMenu in a custom tool as well as in your application logic directly. In the end of this section, you will be able to create your own quick menu.

linkAdd a quick menu resource

First, add a quick menu resource xml file in res/menu folder. For example, let's create a custom.xml.

By default, all menu items are placed in the first row, if you want to specifies where the menu item is, you can simply put the menu items inside a group with the following group id.

link@id/first_row_group

First row group id: all menu items inside this group will be displayed in the first row of the quick menu.

link@id/second_row_group

Second row group id: all menu items inside this group will be displayed in the second row of the quick menu.

link@id/overflow_row_group

Overflow list group id: all menu items inside this group will be displayed in the overflow menu list of the quick menu.

Add the following to custom.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@id/first_row_group">
        <item android:id="@+id/rectangle"
            android:title="@string/tools_rectangle"
            android:icon="@drawable/annotation_square" />
    </group>
    <group android:id="@id/second_row_group">
        <item android:id="@+id/line"
            android:title="@string/annot_line"
            android:icon="@drawable/annotation_line"/>
        <item android:id="@+id/free_text"
            android:title="@string/annot_free_text"
            android:icon="@drawable/annotation_free_text"/>
    </group>
    <group android:id="@id/overflow_row_group">
        <item android:id="@+id/floating_sig"
            android:title="@string/tools_signature"/>
        <item android:id="@+id/link"
            android:title="@string/annot_link"/>
    </group>
</menu>

Sometimes, you may want to display another quick menu as a sub menu of a quick menu item. You can add a sub menu under that quick menu item in menu resource. For example, in order to add an Oval menu item as a sub menu of Rectangle menu item, change custom.xml to:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:id="@id/first_row_group">
        <item android:id="@+id/rectangle"
            android:title="@string/tools_rectangle"
            android:icon="@drawable/annotation_square" >
            <menu>
                <group android:id="@id/first_row_group">
                    <item android:id="@+id/oval"
                        android:title="@string/annot_circle"/>
                </group>
            </menu>
        </item>
    </group>
    <group android:id="@id/second_row_group">
        <item android:id="@+id/line"
            android:title="@string/annot_line"
            android:icon="@drawable/annotation_line"/>
        <item android:id="@+id/free_text"
            android:title="@string/annot_free_text"
            android:icon="@drawable/annotation_free_text"/>
    </group>
    <group android:id="@id/overflow_row_group">
        <item android:id="@+id/floating_sig"
            android:title="@string/tools_signature"/>
        <item android:id="@+id/link"
            android:title="@string/annot_link"/>
    </group>
</menu>

linkShow the quick menu

After adding the quick menu resource, you can create a QuickMenu as follows:

QuickMenu quickMenu = new QuickMenu(mPdfViewCtrl);
quickMenu.initMenuEntries(R.menu.custom);

Alternatively, if you want to change menu items before the quick menu initializes them, you can call QuickMenu.inflate(@MenuRes int) to prevent menu item auto initialization. After making your adjustments to the items, you can call QuickMenu.initMenuEntries() to apply your changes.

QuickMenu quickMenu = new QuickMenu(mPdfViewCtrl);
quickMenu.inflate(R.menu.custom);
QuickMenuItem quickMenuItem = (QuickMenuItem) quickMenu.getMenu().findItem(R.id.rectangle);
if (quickMenuItem != null) {
    quickMenuItem.setIcon(R.drawable.my_custom_icon);
    quickMenuItem.setTitle(R.string.my_custom_title);
}
quickMenu.initMenuEntries();

Then, you can set an anchor rectangle which the quick menu should show up by calling QuickMenu.setAnchorRect(RectF), then QuickMenu.show().

RectF anchor = new RectF(left, top, right, bottom);
QuickMenu quickMenu = new QuickMenu(mPdfViewCtrl);
quickMenu.initMenuEntries(R.menu.custom);
quickMenu.setAnchorRect(anchor);
quickMenu.show();

With a given anchor rectangle view, the quick menu will automatically adjust its position and will be shown either to the top of the anchor view or to the bottom of the anchor view:

At this point, you should see:

Without sub menu:

With sub menu:

linkEvents

Your custom quick menu item will not go through the default quick menu events if the quick menu item id does not match any of the default ones. However, you can do:

quickMenu.setOnDismissListener(new QuickMenu.OnDismissListener() {
    @Override
    public void onDismiss() {
        // get selected quick menu item
        QuickMenuItem selectedMenuItem = quickMenu.getSelectedMenuItem();
    }
});
If your quick menu is controlled by your custom tool, you can simply override Tool.onQuickMenuClicked(QuickMenuItem) in your custom tool to listen to quick menu click event.

linkStyles

linkQuick menu item icons

In xml menu resource file, you can set menu item icon by android:icon. For setting icon style, simply set the quick menu item icon by adding android:iconTint and icon tint mode by adding android:iconTintMode in your menu resource xml file if you support API 26.

Example

<item android:id="@+id/rectangle"
    android:title="@string/tools_rectangle"
    android:icon="@drawable/annotation_square"
    android:iconTint="@color/fab_dark_blue"
    android:iconTintMode="src_in"/>

You can also set quick menu item icon programmatically before the quick menu initializes them by QuickMenuItem.setIcon(Drawable) or QuickMenuItem.setIcon(int). The icon style can be adjusted by using QuickMenuItem.setColor(int), and QuickMenuItem.setOpacity(float), which can be used to set the icon color and opacity, respectively.

Example

QuickMenu quickMenu = new QuickMenu(mPdfViewCtrl);
    quickMenu.inflate(R.menu.annot_simple_shape);
    QuickMenuItem noteItem = (QuickMenuItem) quickMenu.getMenu().findItem(R.id.note);
    if (noteItem != null) {
        noteItem.setIcon(R.drawable.annotation_sticky_note);
        noteItem.setIconColor(mContext.getResources().getColor(R.color.red));
        noteItem.setIconOpacity(0.87);
    }
    quickMenu.initMenuEntries();

linkQuick menu buttons style

Quick menu is using R.style.QuickMenuButton for the buttons style. You can change the style by overriding it.

If you want to change the button style after quick menu is displayed, you can find the button by calling QuickMenu.findMenuItem(QuickMenuItem). Once the button is found, how you set its style programmatically depends on whether it is an ImageButton or a Button.

Example

/**
     * Update quick menu appearance item color
     * @param color
     */
    public void updateQuickMenuStyleColor(int color) {
        if (quickMenu == null) {
            return;
        }
        // find appearance quick menu item
        QuickMenuItem menuItem = (QuickMenuItem) quickMenu.getMenu().findItem(R.id.appearance);
        if (menuItem != null) {
            menuItem.setIconColor(color);
            View button = quickMenu.findButtonByMenuItem(menuItem);
            if (button != null) {
                if (button instanceof ImageButton) {
                    ((ImageButton) button).setColorFilter(color, PorterDuff.Mode.SRC_IN);
                } else if (button instanceof Button) {
                    ((Button) button).setTextColor(color);
                }
            }
        }
    }

linkBackground

Quick menu background uses drawable/quickmenu_bg_rext.xml for API 21 and drawable/quickmenu_bg_rect_old_api for API under 21. You can change the background by overriding these drawable files.

linkDivider

There is a hairline divider between the menu first and second rows. By default, if both rows exist, the divider is VISIBLE by default. You can set this hairline divider visibility by calling:

quickMenu.setDividerVisibility(View.INVISIBLE);