web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Entering text into a s...
Power Automate
Unanswered

Entering text into a specific field for a pdf.

(0) ShareShare
ReportReport
Posted on by 61

Hello, 

 

I want to enter a text into a specific field for a pdf. The pdf name is not constant, I was trying to use UI automation and populate text field option along with selectors to enter text into the pdf. 

 

 

I have the same question (0)
  • kinuasa Profile Picture
    797 Most Valuable Professional on at

    I recommend that considering the use of third-party application like PDFtk instead of Power Automate for desktop.

     

    * Filling out PDF Forms with PDFtk

    https://note.com/kinuasa/n/nf807a967316c

  • Sh99 Profile Picture
    61 on at

    Is there any other way of filling out pdf forms with PAD? with Ui automation or any other command?

  • Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    Hi @Sh99 

     

    I would recommend to use .Net Scripts. Please refer the below link

    Solved: add text and image to existing pdf in power automa... - Power Platform Community (microsoft.com)

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Sh99 Profile Picture
    61 on at

    Hi Deenuji, I referred the solution, can you please provide the screenshot of the entire .NET script used?

  • Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    @Sh99 

     

    Already full PAD source code in mentioned in the same link. Please refer. 

    You can just copy and paste the below code into your PAD.

    Deenuji_0-1714579270914.png

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Sh99 Profile Picture
    61 on at

    I have to add data for two specific fields in my pdf.  How do i modify this script to add that?

     

  • Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    @Sh99 

     

    Please use the below code one more time and change your variable and text insert position.

     

    // Example: Add text

    content.BeginText();
    content.SetFontAndSize(BaseFont.CreateFont(), 12);
    content.SetTextMatrix(100, 50); // Set position
    content.ShowText(text);
    content.EndText();

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • kinuasa Profile Picture
    797 Most Valuable Professional on at

    @Sh99 wrote:

    Is there any other way of filling out pdf forms with PAD? with Ui automation or any other command?

     


    As far as I know, UI automation or mouse/keyboard operations often don't work well. Therefore, I recommended the use of third party applications.

    (I believe Mr @Deenuji  is suggesting code using iTextSharp for the same reason.)

  • kinuasa Profile Picture
    797 Most Valuable Professional on at

    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

    FillingOutPdfFormsWithPdfSharp_01.png

    FillingOutPdfFormsWithPdfSharp_02.png

    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

    FillingOutPdfFormsWithPdfSharp_03.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 889

#2
Valantis Profile Picture

Valantis 830

#3
Haque Profile Picture

Haque 505

Last 30 days Overall leaderboard