WinForms / WPF ビューアで PDF ページのコンテンツを編集します。

ブログ カテゴリ: PDF.NET

2022/01/20

VintaSoft Imaging .NET SDK には、WinForms/WPF ビューアで PDF ドキュメントを編集するための広範な機能があります。


PDF ドキュメントの視覚的な編集機能が実証されていますデモ アプリケーション VintaSoft PDF Editor Demo (WinForms) および VintaSoft WPF PDF Editor Demo (WPF)。

この記事では、WinForms/WPF ビューアで PDF ドキュメントのコンテンツを視覚的に編集するための機能の概要を説明します。



WinForms/WPF ビューアで PDF ページの内容を編集します


WinForms コントロール ImageViewer を使用すると、WinForms アプリケーションで PDF ドキュメントのページを表示できます。ImageViewer コントロールでは、ビューアで PDF ページの内容を編集するためのビジュアル ツール PdfContentEditorTool を使用できます。
WPF コントロール WpfImageViewer を使用すると、WPF アプリケーションで PDF ドキュメントのページを表示できます。WpfImageViewer コントロールでは、ビューアで PDF ページの内容を編集するためのビジュアル ツール WpfPdfContentEditorTool を使用できます。

以下は、WinForms アプリケーションで PDF ページ コンテンツを表示および編集するための ImageViewerPdfContentEditorTool を作成するコードです。
// 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));
    }
}



WinForms/WPF ビューアで PDF ページの内容を編集するための一般的な機能

SDK は PDF ページの内容を次のグラフィック図形に分割できます:
PdfContentEditorTool / WpfPdfContentEditorTool を使用すると、ビューアで PDF ページのグラフィックを表示および編集できます。

PdfContentEditorTool / WpfPdfContentEditorTool では次のことが可能です:
以下は PdfEditorDemo アプリケーションのスクリーンショットです。これは PdfEditorDemo のビジュアル PDF コンテンツ エディターのメイン ビューを表しています (各数字は上記のリストに対応しています)。




WinForms/WPF ビューアーで PDF ページのリッチ テキストを編集します

SDK は、WinForms/WPF ビューアーのリッチ テキスト エディターを表す OfficeDocumentVisualEditor クラスを提供します。
PdfContentEditorTool / WpfPdfContentEditorTool は、リッチテキストエディタ(OfficeDocumentVisualEditor)を使用して、「テキストコンテンツ」タイプのオブジェクトを編集します。ビューアの PDF ページに「グループ」(ContentStreamGraphicsFigureTextGroup) が表示されます。

選択したテキスト オブジェクトの編集プロセスは、いくつかの方法で開始できます。
リッチ テキスト エディター (OfficeDocumentVisualEditor) では次のことが可能です:
以下は PdfEditorDemo アプリケーションのスクリーンショットです。リッチテキストの編集中にテキストと段落のプロパティが表示されます。



以下は PdfEditorDemo アプリケーションのスクリーンショットです。編集されたテキストブロックが表示されます。




WinForms/WPF ビューアで PDF ページのベクターグラフィックを編集

PdfContentEditorTool / WpfPdfContentEditorTool を使用すると、WinForms/WPF ビューアーの PDF ページでマウスを使用してベクター グラフィックを変換、コピー、変更できます。

以下はPdfEditorDemo アプリケーションのスクリーンショット。PDF ページでベクター グラフィックの図を選択して変換する方法を示します。



PdfContentEditorTool.SetContentGraphicsProperties メソッドを使用すると、グラフィック図のグラフィック状態を設定できます。

これは PdfEditorDemo アプリケーションのスクリーンショットで、PDF ページで図のグループ化を解除し、ベクター グラフィックの図のグラフィック状態プロパティを変更する方法を示します。




WinForms/WPF ビューアーで PDF ページ上の画像またはフォームを置き換えます。

WinForms/WPF ビューアーの PDF ページにある既存の画像またはフォームは、PdfContentEditorTool.ReplaceResource メソッドを使用して置き換えることができます。

これは PdfEditorDemo アプリケーションのスクリーンショットで、PDF ページで選択した画像の画像リソースに関する情報を含むダイアログを示します。


これは PdfEditorDemo アプリケーションのスクリーンショットで、画像ファイルから新しい画像リソースを作成し、それを PDF ページで選択した画像の画像リソースとして使用する方法を示します。


これは PdfEditorDemo アプリケーションのスクリーンショットで、PDF ページに変更された画像を表示します。




WinForms/WPF ビューアで PDF ページの図のクリッピング領域を作成、変更、削除します

PdfContentEditorTool.AddFigureClip メソッドを使用して、PDF ページ上の任意の図に新しいクリッピング領域を追加できます。

以下は PdfEditorDemo アプリケーションのスクリーンショットです。これは、PDF ページ上の画像の楕円形のクリッピング領域を設定する方法を示しています:



PDF ページ上の任意の図の既存のクリッピング領域は、マウスを使用して選択、変換、または削除できます。

以下は、PDF ページ上の画像クリッピング領域の変換を示す PdfEditorDemo アプリケーションのスクリーンショットです。




WinForms/WPF ビューアーで PDF ページにグラフィックを追加

PdfContentEditorTool を使用すると、次のグラフィック図を PDF ページに追加できます。
PdfContentEditorTool.AddFigure メソッドを使用すると、グラフィック図を PDF ページに追加できます。

PdfContentEditorTool.StartBuildFigure メソッドを使用すると、マウスを使用して PDF ページへのグラフィック図の構築を開始できます。

以下は PdfEditorDemo アプリケーションのスクリーンショットです。これは PDF ページにグラフィックを追加する方法を示しています。




WinForms/WPF ビューアで PDF ページにグラフを追加する

SDK は、PDF ページに DOCX ページを描画できる OfficeDocumentFigure クラスを提供します。
PDF エディター デモでは、グラフを含む DOCX ページを PDF ページに追加する方法 (PdfContentEditorTool.AddFigurePdfContentEditorTool.StartBuildFigure を使用して PDF ページに OfficeDocumentFigure を追加/構築) を示します。方法)。

以下は PdfEditorDemo アプリケーションのスクリーンショットです。これは PDF ページに追加するグラフを選択する方法を示しています。



また、PDF エディター デモでは、グラフ データを変更し、ビューアで PDF ページでグラフの変更を表示する方法も示しています。

以下は、PDF ページでチャートを選択し、チャートのプロパティを編集する方法を示す PdfEditorDemo アプリケーションのスクリーンショットです。




WinForms/WPF ビューアで PDF ページの内容を編集するための要件

WinForms/WPF ビューアで PDF ページのコンテンツを編集する場合は、次の VintaSoft 製品が必要です。