PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
In addition to configuring predefined buttons, ComPDFKit_Tools also supports:
Note: Once you use
customToolbarLeftItems,customToolbarRightItems, orcustomMoreMenuItems, the correspondingtoolbarLeftItems,toolbarRightItems, oravailableMenusconfigurations will no longer take effect.
Use customMoreMenuItems to modify the icons and text of existing buttons in the More menu:
{
"toolbarConfig": {
"customMoreMenuItems": [
{
"action": "viewSettings",
"icon": "ic_test_settings",
"title": "Settings"
},
{
"action": "save",
"icon": "ic_test_save",
"title": "Save Document"
}
]
}
}| Field | Description |
|---|---|
action | The id of the predefined action (e.g., viewSettings, save, share, etc.) |
icon | Icon resource name, must be placed in res/drawable directory |
title | Menu display text (only effective in customMoreMenuItems) |
Supported action predefined values are the same as availableMenus: viewSettings, documentEditor, documentInfo, save, watermark, security, flattened, share, openDocument, snip.
Set action to "custom" and specify a unique identifier:
{
"toolbarConfig": {
"customToolbarLeftItems": [
{
"action": "custom",
"identifier": "custom_download_action",
"icon": "ic_test_download",
"title": "Download"
}
],
"customToolbarRightItems": [],
"customMoreMenuItems": []
}
}| Field | Description |
|---|---|
action | Must be "custom" for custom buttons |
identifier | Unique identifier used to distinguish different custom buttons in callbacks |
icon | Icon resource name, must be placed in res/drawable directory |
title | Button text (customToolbarLeftItems / customToolbarRightItems only show icons) |
Listen for custom button click events via CPDFCustomEventCallbackHelper:
CPDFDocumentFragment documentFragment = CPDFDocumentFragment.newInstance(
uri, "password", configuration);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container_view, documentFragment, "documentFragment")
.commit();
// Add callback
CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback(extraMap -> {
String customEventType = extraMap.get(
CPDFCustomEventField.CUSTOM_EVENT_TYPE).toString();
if (CPDFCustomEventType.TOOLBAR_ITEM_TAPPED.equals(customEventType)) {
String action = extraMap.get("identifier").toString();
switch (action) {
case "custom_download_action":
CPDFViewCtrl pdfView = documentFragment.pdfView;
pdfView.savePDF(false, true, (filePath, pdfUri) -> {
CToastUtil.showToast(getApplicationContext(), "Saved successfully");
}, e -> { });
break;
}
}
});
// Remove callback when page is destroyed
@Override
protected void onDestroy() {
super.onDestroy();
CPDFCustomEventCallbackHelper.getInstance().removeCustomEventCallback(this);
}val documentFragment = CPDFDocumentFragment.newInstance(
uri, "password", configuration)
supportFragmentManager
.beginTransaction()
.replace(R.id.fragment_container_view, documentFragment, "documentFragment")
.commit()
CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback { extraMap ->
val customEventType = extraMap[CPDFCustomEventField.CUSTOM_EVENT_TYPE].toString()
if (CPDFCustomEventType.TOOLBAR_ITEM_TAPPED == customEventType) {
val action = extraMap["identifier"].toString()
when (action) {
"custom_download_action" -> {
documentFragment.pdfView.savePDF(false, true, { filePath, pdfUri ->
CToastUtil.showToast(applicationContext, "Saved successfully")
}, { })
}
}
}
}
override fun onDestroy() {
super.onDestroy()
CPDFCustomEventCallbackHelper.getInstance().removeCustomEventCallback(this)
}
The following example shows customizing left buttons, right buttons, and More menu simultaneously:
{
"toolbarConfig": {
"customToolbarLeftItems": [
{
"action": "custom",
"identifier": "custom_back",
"icon": "ic_custom_back",
"title": "Back"
}
],
"customToolbarRightItems": [
{
"action": "search",
"icon": "ic_custom_search",
"title": "Search"
},
{
"action": "custom",
"identifier": "custom_share",
"icon": "ic_custom_share",
"title": "Share"
}
],
"customMoreMenuItems": [
{
"action": "save",
"icon": "ic_custom_save",
"title": "Save"
},
{
"action": "custom",
"identifier": "custom_print",
"icon": "ic_custom_print",
"title": "Print"
}
]
}
}