How to use Power Shell in this case?

Hello everyone,

I am using “Power Shell” in order to fill the fields in an editable PDF. The script works properly (it can be found on this forum) but when I try to pass as variables the paths, an error is shown:

[System.Reflection.Assembly]::LoadFrom($path1) | Out-Null
$PDFDoc = New-Object iTextSharp.text.pdf.PdfReader -ArgumentList $path2
$PDFDoc_ = New-Object iTextSharp.text.pdf.PdfStamper($PDFDoc,[System.IO.File]::Create($path3))

image

image

I really do not know why…
Any ideas? Thanks a bunch!

Need help please.
Rishi1
sanjay21051990

Hi @EngAnalyst,
Please have a look here :slight_smile:
Maybe it will help you:

Thank you very much @Pablito
I already read such a thread but I am not able to sort it out… The sentence that seems to be mistaken is the second one:

$PDFDoc = New-Object iTextSharp.text.pdf.PdfReader -ArgumentList $path2

But I do not know why… I am really confused.

Thanks a lot again.

I think $path2 needs to be declared before you can use it as a parameter.

All the parameters (also path1, path3…)?

Btw happy birthday @Pablito !

Thanks :slight_smile:

Yes. Normally all used variables needs to be declared prior to use them in code. The only exception is when you are using variables like this:

$variable = Get-Something -Parameter | Sort-Object blablabla

In this case you can use variable even inside the whole code as you are assigning parameters to it in the same moment where you are declaring it.

Thanks Pablito.

Finally I sorted it out. Have a nice day.