Skip to content

Instantly share code, notes, and snippets.

@adatta02
Created October 13, 2023 15:39
Show Gist options
  • Save adatta02/0f65456414475f4eb09986e5f0ec1e21 to your computer and use it in GitHub Desktop.
Save adatta02/0f65456414475f4eb09986e5f0ec1e21 to your computer and use it in GitHub Desktop.
using System.IO;
using TallComponents.PDF;
using TallComponents.PDF.Forms.Fields;
using TallComponents.PDF.JavaScript;
Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
using (FileStream inFile = new FileStream(@"./nIVD_eSTAR_40.pdf", FileMode.Open, FileAccess.Read))
{
Document document = new Document(inFile);
document.Fields.Changed += Fields_Changed;
var fields = document.Fields;
Console.WriteLine("Before we click the button: " + fields.Count);
RadioButtonField radioField = document.Fields["root[0].ApplicationType[0].USA[0].ATRadioButton110[0]"] as RadioButtonField;
radioField.Value = "1";
radioField = document.Fields["root[0].ApplicationType[0].USA[0].ATRadioButton115[0]"] as RadioButtonField;
radioField.Value = "1";
radioField = document.Fields["root[0].ApplicationType[0].ApplicationSubType[0].ATRadioButton130[0]"] as RadioButtonField;
radioField.Value = "1";
DropDownListField dropDown = document.Fields["root[0].AdministrativeInformation[0].ApplicantInformation[0].ADDropDownList120[0]"] as DropDownListField;
dropDown.Value = "1";
TextField textField = document.Fields["root[0].AdministrativeInformation[0].ApplicantInformation[0].ADTextField130[0]"] as TextField;
textField.Value = "Bruce";
textField = document.Fields["root[0].AdministrativeInformation[0].ApplicantInformation[0].ADTextField140[0]"] as TextField;
textField.Value = "Wayne";
Console.WriteLine("After we click the button: " + document.Fields.Count);
FileStream stream = File.Open(@"./sample.pdf", FileMode.Open);
EmbeddedFile ef = new EmbeddedFile(stream, "Sample PDF");
document.EmbeddedFiles.Add(ef);
Console.WriteLine("Before:");
for (int i = 0; i < fields.Count; i++)
{
Console.WriteLine("\t" + document.Fields[i].FullName);
}
Console.WriteLine("After:");
for (int i = 0; i < document.Fields.Count; i++)
{
Console.WriteLine("\t" + document.Fields[i].FullName);
}
using (FileStream outFile = new FileStream(@"./nIVD_eSTAR_40-filled.pdf", FileMode.Create, FileAccess.Write))
{
document.Write(outFile);
}
}
Console.WriteLine("All done!");
static void Fields_Changed(FieldCollection sender, FieldsChangedEventArgs e)
{
Console.WriteLine(e.Added.Length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment