There is also a way to use "PdfSharp", which is under the MIT license, from PowerShell.
* Installing PdfSharp
If you are using the command line version of NuGet, execute the following command:
nuget install PdfSharp -version 1.50.5147
* Sample of a PowerShell script
[void][Reflection.Assembly]::LoadFile("C:\System\Lib\PdfSharp.dll")
$doc = [PdfSharp.Pdf.IO.PdfReader]::Open("C:\Test\PDF\SampleField.pdf", [PdfSharp.Pdf.IO.PdfDocumentOpenMode]::Modify)
$form = $doc.AcroForm
if($form.Elements.ContainsKey("/NeedAppearances") -eq $true){
$form.Elements["/NeedAppearances"] = [PdfSharp.Pdf.PdfBoolean]::True
}else{
$form.Elements.Add("/NeedAppearances", [PdfSharp.Pdf.PdfBoolean]::True)
}
$fields = $form.Fields
$fields["Name"].Value = [PdfSharp.Pdf.PdfString]::new("foo bar")
$fields["Age"].Value = [PdfSharp.Pdf.PdfString]::new("25")
$fields["Mail"].Value = [PdfSharp.Pdf.PdfString]::new("foo@***.com")
$doc.Save("C:\Test\PDF\SampleField(2).pdf")
* Sample of a Desktop flow


SET InputFilePath TO $'''C:\\Test\\PDF\\SampleField.pdf'''
SET OutputFilePath TO $'''C:\\Test\\PDF\\SampleField(2).pdf'''
SET FieldName1 TO $'''Name'''
SET FieldValue1 TO $'''foo bar'''
SET FieldName2 TO $'''Age'''
SET FieldValue2 TO 25
SET FieldName3 TO $'''Mail'''
SET FieldValue3 TO $'''foo@***.com'''
@@copilotGeneratedAction: 'False'
Scripting.RunPowershellScript.RunPowershellScript Script: $'''[void][Reflection.Assembly]::LoadFile(\"C:\\System\\Lib\\PdfSharp.dll\")
$doc = [PdfSharp.Pdf.IO.PdfReader]::Open(\"%InputFilePath%\", [PdfSharp.Pdf.IO.PdfDocumentOpenMode]::Modify)
$form = $doc.AcroForm
if($form.Elements.ContainsKey(\"/NeedAppearances\") -eq $true){
$form.Elements[\"/NeedAppearances\"] = [PdfSharp.Pdf.PdfBoolean]::True
}else{
$form.Elements.Add(\"/NeedAppearances\", [PdfSharp.Pdf.PdfBoolean]::True)
}
$fields = $form.Fields
$fields[\"%FieldName1%\"].Value = [PdfSharp.Pdf.PdfString]::new(\"%FieldValue1%\")
$fields[\"%FieldName2%\"].Value = [PdfSharp.Pdf.PdfString]::new(\"%FieldValue2%\")
$fields[\"%FieldName3%\"].Value = [PdfSharp.Pdf.PdfString]::new(\"%FieldValue3%\")
$doc.Save(\"%OutputFilePath%\")''' ScriptOutput=> PowershellOutput
