Customize the Menu of Text Eiting
When entering the editing mode, the PDF document will also enter the corresponding interaction status according to different operations. In different interaction status, a context menu like PopWindow will be popped up, and the context menu will call back to different interfaces and includes different operation classes. The following are the different interaction status:
- EditTextArea
When selecting a text block or an image.
- EditSelectText
When editing the content in the text block and long-pressing to select the text.
- EditText
When editing the content in the text block and clicking where the cursor is.
ComPDFKit provides a base class of menu. You can extend the base class of menu and respond to different operations according to your rules.
The following code shows you how to extend the base menu class.
DemoContextMenuHelper contextMenuHelper = new DemoContextMenuHelper(readerView, this);
readerView.setContextMenuShowListener(contextMenuHelper);
When selecting a text block, you can override the method getEditTextAreaContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.operateEditTextArea(CPDFPageView.EditTextAreaFuncType.EDIT)
The keyboard pops up and the cursor is displayed, then users can edit the text content.
- CPDFPageView.operateEditTextArea(CPDFPageView.EditTextAreaFuncType.DELETE)
Delete the selected text block.
- CPDFPageView.operateEditTextArea(CPDFPageView.EditTextAreaFuncType.COPY)
Copy the selected text block with style to the clipboard.
- CPDFPageView.operateEditTextArea(CPDFPageView.EditTextAreaFuncType.COPY_WITHOUT_STYLE)
Copy the selected text block without style to the clipboard.
- CPDFPageView.operateEditTextSelect(CPDFPageView.EditTextSelectFuncType.ATTR)
Set properties of selected text in a text block, including font size, italic, bold, color, alignment, and transparency. When editing the content in the text block and selecting a text, you can override the method getEditSelectTextContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.operateEditTextSelect(CPDFPageView.EditTextSelectFuncType.DELETE)
Delete the selected text.
- CPDFPageView.operateEditTextSelect(CPDFPageView.EditTextAreaFuncType.CUT)
Cut the selected text.
- CPDFPageView.operateEditTextSelect(CPDFPageView.EditTextAreaFuncType.COPY
Copy the selected text. When editing the content in the text block and clicking where the cursor is, you can override the method getEditTextContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.operateEditText(CPDFPageView.EditTextFuncType.SELECT
Select the word text where the cursor is located. Enter the EditSelectText
status after using this method.
- CPDFPageView.operateEditText(CPDFPageView.EditTextFuncType.SELECT_ALL
Select all text in the text block. Enter the EditSelectText
status after using this method.
- CPDFPageView.operateEditText(CPDFPageView.EditTextFuncType.PASTE
Paste the contents of the clipboard to the behind of the cursor. When selecting the image, you can override the method getEditImageAreaContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.DELETE
Delete the selected image.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ENTER_CROP
Start cropping the selected image.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ROTATE
Rotate the selected image block.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.HORIZENTAL_MIRROR
Mirror the selected image horizontally.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.VERTICLE_MIRROR
Mirror the selected image vertically.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.REPLACE
Replace the selected image with another image.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXTRACT_IMAGE
Extract the selected image and save it as a file.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.TRANCPARENCY
Modify transparency of the selected image. When clicking the image which has started cropping, you can override the method getCropImageAreaContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.CROP
Crop the selected image.
- CPDFPageView.operateEditImageArea(CPDFPageView.EditImageFuncType.EXIT_CROP, null
Ends cropping the image. When pressing and holding a blank space on the page, you can override the method getEditLongPressContentView()
to pop up the context menu and implement the following operations:
- CPDFPageView.addEditTextAres(final PointF point)
Add a text block at the point position.
- CPDFPageView.addEditImageAres(final PointF point, String path)
Add an image at the point position.
- CPDFPageView.pasteEditTextArea(final PointF point, int width, int height)
Paste the text block on the clipboard at the point position.