mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 20:07:57 +08:00
add more examples to the examples solution
This commit is contained in:
41
examples/GetFormContents.cs
Normal file
41
examples/GetFormContents.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace UglyToad.Examples
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using PdfPig;
|
||||
using PdfPig.AcroForms.Fields;
|
||||
|
||||
internal static class GetFormContents
|
||||
{
|
||||
public static void Run(string filePath)
|
||||
{
|
||||
using (var document = PdfDocument.Open(filePath))
|
||||
{
|
||||
if (!document.TryGetForm(out var form))
|
||||
{
|
||||
Console.WriteLine($"No form found in file: {filePath}.");
|
||||
return;
|
||||
}
|
||||
|
||||
var page1Fields = form.GetFieldsForPage(1);
|
||||
|
||||
foreach (var field in page1Fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case AcroTextField text:
|
||||
Console.WriteLine($"Found text field on page 1 with text: {text.Value}.");
|
||||
break;
|
||||
case AcroCheckboxesField cboxes:
|
||||
Console.WriteLine($"Found checkboxes field on page 1 with {cboxes.Children.Count} checkboxes.");
|
||||
break;
|
||||
case AcroListBoxField listbox:
|
||||
var opts = string.Join(", ", listbox.Options.Select(x => x.Name));
|
||||
Console.WriteLine($"Found listbox field on page 1 with options: {opts}.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user