Hello @asad.ali ,
I’ve found a solution. This is my idea:
Firstly, I call to this method:
private static byte[] CreateStamp(byte[] stamp, string tipoEntrada, string numeroRegistro, string folio, string tomo)
{
using MemoryStream memoryStreamReaderStamp = new MemoryStream(stamp);
using Bitmap bitmap = (Bitmap)Image.FromStream(memoryStreamReaderStamp);
using Graphics graphics = Graphics.FromImage(bitmap);
using Font arialFont = new Font(“Arial”, 8);
using SolidBrush brush = new SolidBrush(Color.FromArgb(4, 4, 126).ToRgb());
graphics.DrawString($"{DateTime.Now:dd MMM yyyy}".ToUpper(), arialFont, brush, new PointF(210f, 165f));
graphics.DrawString(tipoEntrada, arialFont, brush, new PointF(265f, 205f));
graphics.DrawString(folio, arialFont, brush, new PointF(85f, 260f));
graphics.DrawString(tomo, arialFont, brush, new PointF(390f, 260f));
graphics.DrawString(numeroRegistro, arialFont, brush, new PointF(100f, 335f));
using MemoryStream stream = new MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return stream.ToArray();
}
Later, I call this method:
public static byte[] StampDocument(byte[] document, byte[] stamp, string tipoEntrada, string numeroRegistro, string folio, string tomo)
{
using MemoryStream memoryStreamToPdf = new MemoryStream();
PdfFileStamp pdfDocument = new PdfFileStamp();
using MemoryStream memoryStreamReader = new MemoryStream(document);
pdfDocument.BindPdf(memoryStreamReader);
var asd = CreateStamp(stamp, tipoEntrada, numeroRegistro, folio, tomo);
using MemoryStream memoryStreamReaderStamp = new MemoryStream(asd);
Stamp imageStamp = SetImageStamp(memoryStreamReaderStamp, pdfDocument.PageHeight, pdfDocument.PageWidth);
pdfDocument.AddStamp(imageStamp);
pdfDocument.Save(memoryStreamToPdf);
return memoryStreamToPdf.ToArray();
}
Regards,