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
In my perspective, I believe it's possible, but I would greatly appreciate it if you could initiate a discussion on this topic.
Hi @Deenuji
is it possible to find particular text and get x and y coordinates for that text
Like -
want to find x and y coordinates for that highlighted text in pdf.
Please help
Thanks
Neeraj
Hi @Deenuji
thank you so much it works for me
Please use version 5.5.13.3
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.
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:
Assembly reference:
.Net Script Configuration:
Parameters:
Results:
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.
eetuRobo
13
Super User 2025 Season 1
KO-05050229-0
4
John_Mavridis
4
Microsoft Employee