Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Potongan kode berikut juga bekerja dengan pustaka Aspose.PDF.Drawing.
Untuk mendapatkan nilai dari semua bidang dalam dokumen PDF, Anda perlu menavigasi melalui semua bidang formulir dan kemudian mendapatkan nilai menggunakan properti Value. Dapatkan setiap bidang dari koleksi Form, dalam tipe bidang dasar yang disebut Field dan akses properti Value-nya.
Potongan kode C# berikut menunjukkan cara mendapatkan nilai dari semua bidang dari dokumen PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetValuesFromFields()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValuesFromAllFields.pdf"))
{
// Get values from all fields
foreach (Aspose.Pdf.Forms.Field formField in document.Form)
{
Console.WriteLine("Field Name : {0} ", formField.PartialName);
Console.WriteLine("Value : {0} ", formField.Value);
}
}
}
Properti Value dari bidang formulir memungkinkan Anda untuk mendapatkan nilai dari bidang tertentu. Untuk mendapatkan nilai, ambil bidang formulir dari koleksi Form objek Document. Contoh C# ini memilih TextBoxField dan mengambil nilainya menggunakan properti Value.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetValueFromField()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValueFromField.pdf"))
{
// Get a field
if (document.Form["textbox1"] is Aspose.Pdf.Forms.TextBoxField textBoxField)
{
// Get field value
Console.WriteLine("PartialName : {0} ", textBoxField.PartialName);
Console.WriteLine("Value : {0} ", textBoxField.Value);
}
}
}
Untuk mendapatkan URL tombol kirim, gunakan baris kode berikut.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetSubmitFormActionUrl()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetValueFromField.pdf"))
{
// Get the SubmitFormAction from the form field
if (document.Form[1].OnActivated is Aspose.Pdf.Annotations.SubmitFormAction act)
{
// Output the URL of the SubmitFormAction
Console.WriteLine(act.Url.Name);
}
}
}
Terkadang, Anda mungkin tahu di mana dalam dokumen sebuah bidang formulir berada, tetapi tidak tahu namanya. Misalnya, jika yang Anda miliki hanyalah skema dari formulir yang dicetak. Dengan Aspose.PDF for .NET, ini bukan masalah. Anda dapat mengetahui bidang mana yang ada di wilayah tertentu dari file PDF. Untuk mendapatkan bidang formulir dari wilayah tertentu file PDF:
Potongan kode C# berikut menunjukkan cara mendapatkan bidang formulir di wilayah persegi panjang tertentu dari file PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetFieldsFromRegion()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetFieldsFromRegion.pdf"))
{
// Create rectangle object to get fields in that area
var rectangle = new Aspose.Pdf.Rectangle(35, 30, 500, 500);
// Get the PDF form
var form = document.Form;
// Get fields in the rectangular area
var fields = form.GetFieldsInRect(rectangle);
// Display Field names and values
foreach (var field in fields)
{
// Display image placement properties for all placements
Console.Out.WriteLine("Field Name: " + field.FullName + "-" + "Field Value: " + field.Value);
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.