VintaSoft Imaging .NET SDK has extensive features for editing of PDF document in WinForms/WPF viewer:
The abilities of visual editing of PDF document are demonstrated in demo applications
VintaSoft PDF Editor Demo (WinForms) and
VintaSoft WPF PDF Editor Demo (WPF).
This article provides an overview of functionality for visual editing of PDF document content in WinForms/WPF viewer.
Edit content of PDF page in WinForms/WPF viewer
WinForms control
ImageViewer
allows to display pages of PDF document in WinForms application.
ImageViewer control can use visual tool
PdfContentEditorTool
for editing of PDF page content in viewer.
WPF control
WpfImageViewer
allows to display pages of PDF document in WPF application.
WpfImageViewer control can use visual tool
WpfPdfContentEditorTool
for editing of PDF page content in viewer.
Here is the code that creates
ImageViewer
with
PdfContentEditorTool for displaying and editing of PDF page content in WinForms application:
// The project, which uses this code, must have references to the following assemblies:
// - Vintasoft.Imaging
// - Vintasoft.Imaging.UI
// - Vintasoft.Imaging.Office.OpenXml
// - Vintasoft.Imaging.Office.OpenXml.UI
// - Vintasoft.Imaging.Pdf
// - Vintasoft.Imaging.Pdf.UI
// - Vintasoft.Imaging.Pdf.Office.UI
public partial class FormWithPdfEditorTool : System.Windows.Forms.Form
{
//...
Vintasoft.Imaging.UI.ImageViewer _imageViewer;
//...
/// <summary>
/// The PDF content editor tool.
/// </summary>
Vintasoft.Imaging.Pdf.UI.PdfContentEditorTool _contentEditorTool;
/// <summary>
/// The undo manager.
/// </summary>
Vintasoft.Imaging.Undo.UndoManager _undoManager = new Vintasoft.Imaging.Undo.UndoManager(20);
public FormWithPdfEditorTool()
{
//...
// initialize Vintasoft.Imaging.Pdf.Office.UI assembly
Vintasoft.Imaging.PdfOfficeUIAssembly.Init();
// create visual tool that allows to edit content on PDF page
_contentEditorTool = new Vintasoft.Imaging.Pdf.UI.PdfContentEditorTool();
// specify that PDF content editor tool should add and edit content on PDF page
_contentEditorTool.AppendMode = false;
// specify that PDF content editor tool should highlight content figures
_contentEditorTool.FiguresHighlight = true;
// specify that PDF content editor tool should not render figures on PDF page when current page is changed in image viewer
_contentEditorTool.RenderFiguresWhenImageIndexChanging = false;
// specify that PDF content editor tool should render figures on PDF page when PDF content editor tool is deactivating
_contentEditorTool.RenderFiguresWhenDeactivating = true;
// specify undo manager for PDF content editor tool
_contentEditorTool.UndoManager = _undoManager;
// specify that PDF content editor tool should work only with content of specified types
_contentEditorTool.InteractiveContentType =
Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.GraphicsFigureContentType.Text |
Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.GraphicsFigureContentType.Image |
Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.GraphicsFigureContentType.Form |
Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.GraphicsFigureContentType.StrokePath |
Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.GraphicsFigureContentType.FillPath;
// create visual tool that allows to edit text in text content on PDF page
Vintasoft.Imaging.Office.OpenXml.UI.VisualTools.UserInteraction.OfficeDocumentVisualEditorTextTool contentEditorTextTool =
new Vintasoft.Imaging.Office.OpenXml.UI.VisualTools.UserInteraction.OfficeDocumentVisualEditorTextTool();
// create the composite visual tool and set it as a current tool of image viewer
_imageViewer.VisualTool = new Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(contentEditorTextTool, _contentEditorTool);
}
//...
private void drawEllipseToolStripButton_Click(object sender, System.EventArgs e)
{
// start building an ellipse
_contentEditorTool.StartBuildEllipse(
new Vintasoft.Imaging.Pdf.Drawing.PdfPen(System.Drawing.Color.Red, 5),
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green));
}
}
General features for editing of PDF page content in WinForms/WPF viewer
The SDK can divide PDF page content to the following graphic figures:
- Text
- Image
- Form
- Path outline
- Path filling
- Cropping area
- Pattern (gradient) area
- Group of objects
The
PdfContentEditorTool/
WpfPdfContentEditorTool
allows to display and edit graphic figures on PDF page in viewer.
The
PdfContentEditorTool/
WpfPdfContentEditorTool
allows to:
- Enable/disable the ability to edit content of PDF page in viewer (4)
- Group editable content figures (3)
- Highlight content figures in viewer (2, 12)
- Select the type of editable figures: text, images, forms, filled path, pattern area, crop area (1)
- Get list of editable figures (14)
- Undo and Redo operations (5)
- Edit text of selected text figure (6)
- Replace or edit selected form or image (7)
- Set the figure properties: pen color and thickness, fill color, transparency, text rendering mode, etc (8)
- Transform (move, resize, rotate) selected figure in viewer (15)
- Programmatically transform (rotate, flip or free transform) the selected figure (9)
- Set a crop area for selected figure (10)
- Add new figures (text, images, graphics, charts, etc) (11)
- Delete, copy, paste a figure of any type (16)
- Select a figure located at the specified point (17)
Here is a screenshot of PdfEditorDemo application, which represents the main view of visual PDF content editor in PdfEditorDemo (each digit corresponds to the list above):
Edit rich text on PDF page in WinForms/WPF viewer
The SDK provides
OfficeDocumentVisualEditor class
that represents the rich text editor in WinForms/WPF viewer.
PdfContentEditorTool/
WpfPdfContentEditorTool
uses the rich text editor (
OfficeDocumentVisualEditor)
for editing of object of type "Text content group"
(
ContentStreamGraphicsFigureTextGroup)
on PDF page in viewer.
The editing process of selected text object can be started by a few ways:
The rich text editor (
OfficeDocumentVisualEditor) allows to:
- transform (resize, move) the text area
- change text
- change text properties: font, size, color, bold, italic, underline, superscript, subscript, horizontal scale, character spacing
- change horizontal text alignment: left, right, center, width
- change paragraph indent
- change paragraph background color
- change line spacing
- create numbered list
Here is a screenshot of PdfEditorDemo application, which demonstrates the text and paragraph properties while editing the rich text:
Here is a screenshot of PdfEditorDemo application, which demonstrates the edited text block:
Edit vector graphics on PDF page in WinForms/WPF viewer
PdfContentEditorTool/
WpfPdfContentEditorTool
allows to use mouse for transforming, copying, changing of vector graphics on PDF page in WinForms/WPF viewer.
Here is a screenshot of PdfEditorDemo application, which demonstrates how to select and transform vector graphics figure on PDF page:
The
PdfContentEditorTool.SetContentGraphicsProperties method
allows to set the graphics state of graphic figure.
Here is a screenshot of PdfEditorDemo application, which demonstrates how to ungroup figures and change graphic state properties for vector graphics figure on PDF page:
Replace image or form on PDF page in WinForms/WPF viewer
An existing image or form on PDF page in WinForms/WPF viewer can be replaced using
PdfContentEditorTool.ReplaceResource method.
Here is a screenshot of PdfEditorDemo application, which demonstrates dialog with information about image-resource of selected image on PDF page:
Here is a screenshot of PdfEditorDemo application, which demonstrates how to create new image-resource from image file and use it as image-resource for selected image on PDF page:
Here is a screenshot of PdfEditorDemo application, which displays the changed image on PDF page:
Create, change and delete the clipping area for figure on PDF page in WinForms/WPF viewer
New clipping area can be added to any figure on PDF page using
the
PdfContentEditorTool.AddFigureClip method.
Here is a screenshot of PdfEditorDemo application, which demonstrates how to set the elliptical clipping area for image on PDF page:
An existing clipping area for any figure on PDF page can be selected, transformed or deleted using mouse.
Here is a screenshot of PdfEditorDemo application, which demonstrates the transformation of image clipping area on PDF page:
Add graphics onto PDF page in WinForms/WPF viewer
The
PdfContentEditorTool allows to
add the following graphical figures onto PDF page:
- Text line
- Text box
- Formatted text
- Chart
- Markup based on DOCX document
- Page of PDF or DOCX document
- Image of any supported format
- Form or image-resource from current or another PDF document
- Rectangle
- Ellipse
- Polygon
- Polyline
- Curves
The
PdfContentEditorTool.AddFigure method
allows to add graphical figure onto PDF page.
The
PdfContentEditorTool.StartBuildFigure method
allows to start building of graphical figure onto PDF page using mouse.
Here is a screenshot of PdfEditorDemo application, which demonstrates how to add graphics onto PDF page:
Add charts onto PDF page in WinForms/WPF viewer
SDK provides
OfficeDocumentFigure class
that allows to draw DOCX page on PDF page.
PDF Editor Demo demonstrates how to add DOCX page with chart onto PDF page
(add/build
OfficeDocumentFigure onto
PDF page using
PdfContentEditorTool.AddFigure/
PdfContentEditorTool.StartBuildFigure method).
Here is a screenshot of PdfEditorDemo application, which demonstrates how to select chart for adding onto PDF page:
Also PDF Editor Demo demonstrates how to change the chart data and view the chart changes on PDF page in viewer.
Here is a screenshot of PdfEditorDemo application, which demonstrate how to select the chart on PDF page and edit the chart properties:
Requirements for editing of PDF page content in WinForms/WPF viewer
If you want to edit PDF page content in WinForms/WPF viewer, the following VintaSoft products are necessary: