内部および外部フィールドのコピー

CopyInnerFieldメソッドを使用すると、同じファイル内の指定されたページの同じ座標にフィールドをコピーできます。このメソッドには、コピーしたいフィールド名、新しいフィールド名、およびフィールドをコピーするページ番号が必要です。FormEditorクラスがこのメソッドを提供します。以下のコードスニペットは、同じファイル内の同じ位置にフィールドをコピーする方法を示しています。

 // For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CopyInnerField()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf();

    // Create an instance of FormEditor object
    using (var formEditor = new Aspose.Pdf.Facades.FormEditor())
    {
        // Open PDF document
        using (var document = new Aspose.Pdf.Document(dataDir + "Sample-Form-01.pdf"))
        {
            // Add page
            document.Pages.Add();

            // Bind PDF document
            formEditor.BindPdf(document);

            // Copy the field "Last Name" from the first page to "Last Name 2" on the second page
            formEditor.CopyInnerField("Last Name", "Last Name 2", 2);

            // Save PDF document
            formEditor.Save(dataDir + "Sample-Form-01-mod.pdf");
        }
    }
}

既存のPDFファイルに外部フィールドをコピーする

CopyOuterFieldメソッドを使用すると、外部PDFファイルからフォームフィールドをコピーし、指定されたページ番号の同じ位置に入力PDFファイルに追加できます。このメソッドには、フィールドをコピーする必要があるPDFファイル、フィールド名、およびフィールドをコピーするページ番号が必要です。このメソッドはFormEditorクラスによって提供されます。以下のコードスニペットは、外部PDFファイルからフィールドをコピーする方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CopyOuterField()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf();

    // Create an instance of FormEditor 
    using (var formEditor = new Aspose.Pdf.Facades.FormEditor())
    {
        // Create empty document
        using (var document = new Aspose.Pdf.Document())
        {
            // Add page
            document.Pages.Add();

            // Bind PDF document
            formEditor.BindPdf(document);

            // Copy the outer field "First Name" from the original document to the new document
            formEditor.CopyOuterField(dataDir + "Sample-Form-01.pdf", "First Name", 1);

            // Copy the outer field "Last Name" from the original document to the new document
            formEditor.CopyOuterField(dataDir + "Sample-Form-01.pdf", "Last Name", 1);

            // Save PDF document
            formEditor.Save(dataDir + "Sample-Form-02-mod.pdf");
        }
    }
}