Is there any other option to exe file? I tried with invoke code activity but it need itextsharp package installed in project & itextsharp is not compatible with windows projects @Anil_G @Sudharsan_Ka
This is the code
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PdfManipulate
{
class PdfImageAdder
{
static void Main(string[] args)
{
if (args.Length != 4)
{
Console.WriteLine("Usage: PdfImageAdder <inputFilePath> <outputFilePath> <imagePath> <text>");
return;
}
string inputFilePath = args[0]; // Existing file
string outputFilePath = args[1]; // New file
string imagePath = args[2]; // Image to be added
string text = args[3]; // Text to be added
using (FileStream fos = new FileStream(outputFilePath, FileMode.Create))
{
PdfReader pdfReader = new PdfReader(inputFilePath);
PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
//Image to be added in existing pdf file.
Image image = Image.GetInstance(imagePath);
image.ScaleAbsolute(70, 50); //Scale image's width and height
// Font for text
Font font = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, BaseColor.BLACK);
Font font1 = FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.BLACK);
// Date to be added in existing pdf file
DateTime date = DateTime.Now;
string formattedDate = date.ToString("dd MMM yyyy");
if(pdfReader.NumberOfPages > 3){
pdfReader.SelectPages("4-6");
}
// loop on all the PDF pages
// i is the pdfPageNumber
for (int i = 1; i <= pdfReader.NumberOfPages; i++)
{
//getOverContent() allows you to write pdfContentByte on TOP of existing pdf pdfContentByte.
//getUnderContent() allows you to write pdfContentByte on BELOW of existing pdf pdfContentByte.
PdfContentByte pdfContentByte = pdfStamper.GetOverContent(i);
if (i == 1)
{
// add image
image.SetAbsolutePosition(130, 35); //Set position for image in PDF
pdfContentByte.AddImage(image);
// add text
ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(text, font), 80, 40, 0);
// add date
ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(formattedDate, font1), 60, 60, 0);
}
else
{
// add image
image.SetAbsolutePosition(230, 35); //Set position for image in PDF
pdfContentByte.AddImage(image);
// add text
ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(text, font), 90, 36, 0);
// add date
ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(formattedDate, font1), 65, 67, 0);
}
Console.WriteLine("Image, Date and Text added in page " + i + " of " + outputFilePath);
}
pdfStamper.Close();
Console.WriteLine("Modified PDF created in >> " + outputFilePath);
}
}
}
}`