FormEditor 클래스의 기능 탐색

구현 세부정보

개발자는 Aspose.Pdf.Facades 네임스페이스를 사용하여 PDF 문서에 새로운 양식 및 양식 필드를 추가할 뿐만 아니라 기존 필드를 편집할 수 있습니다. 이 기사의 범위는 양식 편집과 관련된 Aspose.PDF for .NET의 기능으로 제한됩니다.

FormEditor 클래스는 개발자가 양식 필드를 편집할 수 있도록 하는 대부분의 메서드와 속성을 포함하고 있습니다. 새로운 필드를 추가할 뿐만 아니라 기존 필드를 제거하고, 한 필드를 다른 위치로 이동하고, 필드 이름이나 속성을 변경하는 등의 작업을 수행할 수 있습니다. 이 클래스에서 제공하는 기능 목록은 매우 포괄적이며, 이 클래스를 사용하여 양식 필드로 작업하는 것은 매우 쉽습니다.

이러한 메서드는 두 가지 주요 범주로 나눌 수 있으며, 하나는 필드를 조작하는 데 사용되고, 다른 하나는 이러한 필드의 새로운 속성을 설정하는 데 사용됩니다. 첫 번째 범주에 포함될 수 있는 메서드는 AddField, AddListItem, RemoveListItem, CopyInnerField, CopyOuterField, DelListItem, MoveField, RemoveField 및 RenameField 등이 있습니다. 두 번째 범주에는 SetFieldAlignment, SetFieldAppearance, SetFieldAttribute, SetFieldLimit, SetFieldScript 메서드가 포함될 수 있습니다. 다음 코드 스니펫은 FormEditor 클래스의 일부 메서드가 작동하는 모습을 보여줍니다.

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

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "inFile.pdf"))
    {
        // Create instance of FormEditor
        using (var editor = new Aspose.Pdf.Facades.FormEditor(document))
        {
            // Add field in the PDF file
            editor.AddField(Aspose.Pdf.Facades.FieldType.Text, "field1", 1, 300, 500, 350, 525);

            // Add List field in PDF file
            editor.AddField(Aspose.Pdf.Facades.FieldType.ListBox, "field2", 1, 300, 200, 350, 225);

            // Add list items
            editor.AddListItem("field2", "item 1");
            editor.AddListItem("field2", "item 2");

            // Add submit button
            editor.AddSubmitBtn("submitbutton", 1, "Submit Form", "http:// Testwebsite.com/testpage", 200, 200, 250, 225);

            // Delete list item
                editor.DelListItem("field2", "item 1");

            // Move field to new position
            editor.MoveField("field1", 10, 10, 50, 50);

            // Remove existing field from the PDF
            editor.RemoveField("field1");

            // Rename an existing field
            editor.RenameField("field1", "newfieldname");

            // Reset all visual attributes to empty value
            editor.ResetFacade();

            // Set the alignment style of a text field
            editor.SetFieldAlignment("field1", Aspose.Pdf.Facades.FormFieldFacade.AlignLeft);

            // Set appearance of the field
            editor.SetFieldAppearance("field1", Aspose.Pdf.Annotations.AnnotationFlags.NoRotate);

            // Set field attributes i.e. ReadOnly, Required
            editor.SetFieldAttribute("field1", Aspose.Pdf.Facades.PropertyFlag.ReadOnly);

            // Set field limit
            editor.SetFieldLimit("field1", 25);

            // Save modifications in the output file
            editor.Save(dataDir + "FormEditorFeatures2_out.pdf");                    
        }
    }
}