Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Чтобы добавить поле формы в существующий PDF файл, вам нужно использовать метод AddField класса FormEditor. Этот метод требует от вас указать тип поля, которое вы хотите добавить, вместе с именем и местоположением поля. Вам нужно создать объект класса FormEditor, использовать метод AddField для добавления нового поля в PDF. Также вы можете указать ограничение на количество символов в вашем поле с помощью SetFieldLimit и, наконец, использовать метод Save для сохранения обновленного PDF файла. Следующий фрагмент кода показывает, как добавить поле формы в существующий PDF файл.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddField()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a text field named "Country" to the first page of the PDF
// Specify the coordinates of the field (left, bottom, right, top)
editor.AddField(Aspose.Pdf.Facades.FieldType.Text, "Country", 1, 232.56f, 496.75f, 352.28f, 514.03f);
// Set a character limit for the "Country" field to 20 characters
editor.SetFieldLimit("Country", 20);
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
Метод AddSubmitBtn позволяет вам установить URL кнопки отправки в PDF файле. Это URL, по которому данные отправляются, когда кнопка отправки нажата. В нашем примере кода мы указываем URL, имя нашего поля, номер страницы, на которую мы хотим добавить, и координаты размещения кнопки. Метод AddSubmitBtn требует имя поля кнопки отправки и URL. Этот метод предоставляется классом FormEditor. Следующий фрагмент кода показывает, как установить URL кнопки отправки.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddSubmitBtn()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a submit button named "Submit" to the first page of the PDF
// Specify the button text ("Submit"), the URL to which the form data will be submitted,
// and the coordinates of the button (left, bottom, right, top)
editor.AddSubmitBtn("Submit", 1, "Submit", "http://localhost:3000", 232.56f, 466.75f, 352.28f, 484.03f);
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
Метод AddFieldScript позволяет вам добавить JavaScript к кнопке в PDF файле. Этот метод требует имя кнопки и JavaScript. Этот метод предоставляется классом FormEditor. Следующий фрагмент кода показывает, как установить JavaScript для кнопки.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddFieldScript()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a JavaScript action to the field named "Last Name"
// The script displays an alert box with the message "Only one last name"
editor.AddFieldScript("Last Name", "app.alert(\"Only one last name\",3);");
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.