Skip to main content

Notifications

Community site session details

Community site session details

Session Id : UAv7ZD3kDeieSnLa78k6AR
Power Automate - Power Automate Desktop
Answered

add text and image to existing pdf in power automate desktop

Like (0) ShareShare
ReportReport
Posted on 1 Mar 2024 07:51:46 by 141

Hi,

I want to add text and image in existing pdf using power automate desktop

Tried many things but still its not working

 

tried power shell script

Set-Location C:\.nuget\packages\freespire.pdf\8.6.0\lib\net6.0\
[void] [Reflection.Assembly]::LoadFile("C:\.nuget\packages\freespire.pdf\8.6.0\lib\net6.0\Spire.Pdf.dll")


spire.pdf.pdfdocument

$pdfdocument = New-Object spire.pdf.pdfdocument
$ImagePage=New-Object spire.pdf.Graphics.PdfImage
$page=New-Object spire.pdf.PdfPageBase
$font=New-Object spire.pdf.Graphics.PdfFont
$brush=New-Object spire.pdf.Graphics.PdfSolidBrush
$pdfdocument.LoadFromFile("C:\Downloads\ESS time entry\example.pdf")
$NumberofPages=$pdfdocument.Pages.Count
$page = $pdfdocument.Pages(0)
$ImagePage=$ImagePage.PdfImage.FromFile("C:\Downloads\ESS time entry\New Bitmap Image.bmp")
$page.Canvas.DrawString("abcdef", font, brush, 15, 25)

 

but nothing works

 

can anyone please help

 

Thanks

Neeraj

  • neerajpokh Profile Picture
    141 on 11 Mar 2024 at 18:53:41
    Re: add text and image to existing pdf in power automate desktop

    Hi @Deenuji 

    get x and y coordinates on the basis of text in p... - Power Platform Community (microsoft.com)

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,105 Super User 2025 Season 1 on 11 Mar 2024 at 16:53:21
    Re: add text and image to existing pdf in power automate desktop

    @neerajpokh 
    In my perspective, I believe it's possible, but I would greatly appreciate it if you could initiate a discussion on this topic.

  • neerajpokh Profile Picture
    141 on 11 Mar 2024 at 15:06:50
    Re: add text and image to existing pdf in power automate desktop

    Hi @Deenuji

    is it possible to find particular text and get x and y coordinates for that text

     

    Like - 

    neerajpokh_0-1710169555157.png

     

    want to find x and y coordinates for that highlighted text in pdf.

    Please help

    Thanks

    Neeraj

  • neerajpokh Profile Picture
    141 on 06 Mar 2024 at 06:52:45
    Re: add text and image to existing pdf in power automate desktop

    Hi @Deenuji 

    thank you so much it works for me

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,105 Super User 2025 Season 1 on 06 Mar 2024 at 02:46:49
    Re: add text and image to existing pdf in power automate desktop

    @neerajpokh 

    Please use version 5.5.13.3

    Deenuji_0-1709693093004.png

    My recommendation is to initially try the code in a Visual Studio console application. This way, we can properly identify all the dependencies before integrating the code with PAD.

     

     

  • neerajpokh Profile Picture
    141 on 05 Mar 2024 at 18:45:25
    Re: add text and image to existing pdf in power automate desktop

    Hi @Deenuji 

    output file is also not opening

    neerajpokh_4-1709664318690.png

     

  • neerajpokh Profile Picture
    141 on 05 Mar 2024 at 18:12:31
    Re: add text and image to existing pdf in power automate desktop

    Hi @Deenuji 

    tried the same code but its not working for me

    neerajpokh_0-1709662126013.png

     

     

     

    neerajpokh_1-1709662169174.png

     

     

    throwing error

    neerajpokh_2-1709662242945.png

     

     

    neerajpokh_3-1709662337306.png

    please help

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,105 Super User 2025 Season 1 on 05 Mar 2024 at 15:36:29
    Re: add text and image to existing pdf in power automate desktop

    @neerajpokh 

     

    Thank you for bringing this question to our community forum. I truly appreciate the opportunity to delve into such an out-of-the-box topic. It was a thoroughly enjoyable experience crafting solutions for it.

    I managed to accomplish this using .NET scripts.

     

    Full flow screenshot:

    Deenuji_2-1709652582172.png

     

    Assembly reference:

    Deenuji_3-1709652688238.png

     

    .Net Script Configuration:

    Deenuji_4-1709652731206.png

    Parameters:

    Deenuji_5-1709652776536.png

     

    Results:

    Deenuji_0-1709652431947.png

    Deenuji_1-1709652503932.png

    Code:

    SET InputFilePath TO $'''C:\\Users\\Documents\\PAD_Document.pdf'''
    SET OutputFilePath TO $'''C:\\Users\\Downloads\\Output_result.pdf'''
    SET Append_Text TO $'''Hello!! This is deenu from PAD community!!'''
    SET Image_Path TO $'''C:\\Deenu\\PAD_Image.jpg'''
    Scripting.RunDotNetScript Imports: $'''iTextSharp.text
    iTextSharp.text.pdf''' Language: System.DotNetActionLanguageType.CSharp ReferenceRootPath: $'''C:\\Deenu\\Assemblies''' Script: $'''
    // Create a reader for the input PDF
    using (var reader = new PdfReader(inputPdfFilePath))
    {
    // Create a stamper for adding content to the input PDF
    using (var stamper = new PdfStamper(reader, new FileStream(outputPdfFilePath, FileMode.Create)))
    {
    // Iterate through the pages of the PDF
    for (int i = 1; i <= reader.NumberOfPages; i++)
    {
    // Get the content byte array for the current page
    PdfContentByte content = stamper.GetOverContent(i);

    // Example: Add text

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

    // Example: Add image

    Image image = Image.GetInstance(imagePath);
    image.SetAbsolutePosition(100, 100); // Set position
    content.AddImage(image);
    }
    }
    }''' @'name:inputPdfFilePath': InputFilePath @'type:inputPdfFilePath': $'''String''' @'direction:inputPdfFilePath': $'''In''' @'name:text': Append_Text @'type:text': $'''String''' @'direction:text': $'''In''' @'name:imagePath': Image_Path @'type:imagePath': $'''String''' @'direction:imagePath': $'''In''' @'name:outputPdfFilePath': OutputFilePath @'type:outputPdfFilePath': $'''String''' @'direction:outputPdfFilePath': $'''In'''

     

     

     

    ------------------------------------------------------------------------------------------------------------------------

     

    If I've resolved your query, please consider accepting it as the solution and giving it a thumbs up to help others find answers faster.

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 13 Super User 2025 Season 1

#2
KO-05050229-0 Profile Picture

KO-05050229-0 4

#2
John_Mavridis Profile Picture

John_Mavridis 4 Microsoft Employee

Overall leaderboard
Loading started
Loading complete