Skip to content
Guides

Create, Move, and Delete Text and Images

ComPDFKit provides comprehensive methods for creating, moving, and deleting text and images.

Performing Actions Through CPDFViewer.

CPDFViewer provides basic interactive capabilities by default, allowing the user to create and delete text and images, drag and drop to move the position of images and text blocks, resize images and text blocks, etc. by using the mouse and keyboard.

Configure the Context Menu.

If you need to copy, paste, cut, or delete text or images, you can add these methods to the context menu through the PDFEditCommandHandler event of CPDFViewer.

This example shows how to configure the context menu:

C#
// Register custom menu event
toolManager.MouseRightButtonDownHandler += ToolManager_MouseRightButtonDownHandler;

private void ToolManager_MouseRightButtonDownHandler(object sender, MouseEventObject e)
{
    // Create a context menu on CPDFViewerTool and add menu items (Copy, Cut, Paste, Delete).
    ContextMenu contextMenu = new ContextMenu();
    contextMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
    contextMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
    contextMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
    contextMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });

    CPDFViewerTool tool = sender as CPDFViewerTool;
    tool.ContextMenu = contextMenu;
}

Inserting Text and Images

You can specify the ability to insert text and image blocks through the SetPDFEditCreateType method of CPDFViewer. The following code shows how to achieve this:

C#
// Insert Image
myCPDFView.SetPDFEditCreateType(CPDFEditType.EditImage);
// Insert Text
myCPDFView.SetPDFEditCreateType(CPDFEditType.EditText);
// Cancel
myCPDFView.SetPDFEditCreateType(CPDFEditType.None);