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#
viewer.PDFEditCommandHandler += Viewer_PDFEditCommandHandler;
private void Viewer_PDFEditCommandHandler(object sender, TextEditCommand e)
{
    e.Handle = true;
    e.PopupMenu = new ContextMenu();
    e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
    e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
    e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
    e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
    e.PopupMenu.Items.Add(new MenuItem() { Header = "Select All", Command = ApplicationCommands.SelectAll, CommandTarget = (UIElement)sender });
}

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);