Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Untuk menambahkan bidang formulir di file PDF yang ada, Anda perlu menggunakan metode AddField dari kelas FormEditor. Metode ini mengharuskan Anda untuk menentukan jenis bidang yang ingin Anda tambahkan bersama dengan nama dan lokasi bidang tersebut. Anda perlu membuat objek dari kelas FormEditor, menggunakan metode AddField untuk menambahkan bidang baru di PDF, Selain itu, Anda dapat menentukan batasan jumlah karakter di bidang Anda dengan SetFieldLimit dan akhirnya menggunakan metode Save untuk menyimpan file PDF yang diperbarui. Potongan kode berikut menunjukkan kepada Anda cara menambahkan bidang formulir di file PDF yang ada.
// 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");
}
}
Metode AddSubmitBtn memungkinkan Anda untuk mengatur URL tombol kirim di file PDF. Ini adalah URL tempat data diposting ketika tombol kirim diklik. Dalam kode contoh kami, kami menentukan URL, nama bidang kami, nomor halaman tempat kami ingin menambahkan, dan koordinat penempatan tombol. Metode AddSubmitBtn memerlukan nama bidang tombol kirim dan URL. Metode ini disediakan oleh kelas FormEditor. Potongan kode berikut menunjukkan kepada Anda cara mengatur URL tombol kirim.
// 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");
}
}
Metode AddFieldScript memungkinkan Anda untuk menambahkan JavaScript ke tombol dorong di file PDF. Metode ini memerlukan nama tombol dorong dan JavaScript. Metode ini disediakan oleh kelas FormEditor. Potongan kode berikut menunjukkan kepada Anda cara mengatur JavaScript ke tombol dorong.
// 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.