Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NETは、フォームフィールドを生成し、フォームフィールドを入力するだけでなく、PDFファイルからフォームフィールドデータやフォームフィールドに関する情報を簡単に抽出できます。
以下のサンプルコードでは、PDF内のすべてのAcroFormに関する情報とフォームフィールドの値を抽出するために、PDFの各ページを反復処理する方法を示します。このサンプルコードは、事前にフォームフィールドの名前を知らないことを前提としています。
以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractFormFields()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "StudentInfoFormElectronic.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);
}
}
}
抽出したいフォームフィールドの名前がわかっている場合は、Documents.Formコレクションのインデクサを使用して、このデータを迅速に取得できます。その機能の使用方法については、この記事の下部にあるサンプルコードを参照してください。
フォームフィールドのValueプロパティを使用すると、特定のフィールドの値を取得できます。値を取得するには、DocumentオブジェクトのFormコレクションからフォームフィールドを取得します。この例では、TextBoxFieldを選択し、その値をValueプロパティを使用して取得します。
以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractFormFieldsToJson()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "StudentInfoFormElectronic.pdf"))
{
// Extract form fields and convert to JSON
var formData = document.Form.Cast<Aspose.Pdf.Forms.Field>().Select(f => new { Name = f.PartialName, f.Value });
string jsonString = System.Text.Json.JsonSerializer.Serialize(formData);
// Output the JSON string
Console.WriteLine(jsonString);
}
}
Formクラスを使用すると、ExportXmlメソッドを使用してPDFファイルからXMLファイルにデータをエクスポートできます。データをXMLにエクスポートするには、Formクラスのオブジェクトを作成し、FileStreamオブジェクトを使用してExportXmlメソッドを呼び出す必要があります。最後に、FileStreamオブジェクトを閉じてFormオブジェクトを破棄できます。以下のコードスニペットは、データをXMLファイルにエクスポートする方法を示しています。
以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExportFormDataToXml()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
// Create form
using (var form = new Aspose.Pdf.Facades.Form())
{
// Bind PDF document
form.BindPdf(dataDir + "input.pdf");
// Create XML file
using (var xmlOutputStream = new FileStream(dataDir + "input.xml", FileMode.Create))
{
// Export data
form.ExportXml(xmlOutputStream);
}
}
}
Formクラスを使用すると、ExportFdfメソッドを使用してPDFファイルからFDFファイルにデータをエクスポートできます。データをFDFにエクスポートするには、Formクラスのオブジェクトを作成し、FileStreamオブジェクトを使用してExportFdfメソッドを呼び出す必要があります。最後に、FormクラスのSaveメソッドを使用してPDFファイルを保存できます。以下のコードスニペットは、データをFDFファイルにエクスポートする方法を示しています。
以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExportDataToPdf()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
// Create form
using (var form = new Aspose.Pdf.Facades.Form())
{
// Bind PDF document
form.BindPdf(dataDir + "input.pdf");
// Create fdf file
using (var fdfOutputStream = new FileStream(dataDir + "student.fdf", FileMode.Create))
{
// Export data
form.ExportFdf(fdfOutputStream);
}
// Save PDF document
form.Save(dataDir + "ExportDataToPdf_out.pdf");
}
}
Formクラスを使用すると、ExportXfdfメソッドを使用してPDFファイルからXFDFファイルにデータをエクスポートできます。データをXFDFにエクスポートするには、Formクラスのオブジェクトを作成し、FileStreamオブジェクトを使用してExportXfdfメソッドを呼び出す必要があります。最後に、FormクラスのSaveメソッドを使用してPDFファイルを保存できます。以下のコードスニペットは、データをXFDFファイルにエクスポートする方法を示しています。
以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExportDataToXFDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdfFacades_Forms();
// Create form
using (var form = new Aspose.Pdf.Facades.Form())
{
// Bind PDF document
form.BindPdf(dataDir + "input.pdf");
// Create xfdf file
using (var xfdfOutputStream = new FileStream(dataDir + "student1.xfdf", FileMode.Create))
{
// Export data
form.ExportXfdf(xfdfOutputStream);
}
// Save PDF document
form.Save(dataDir + "ExportDataToXFDF_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.