Add Overlay Text in Image Top-Right

Hi,

I’m trying to add an image and text overlay as a company stamp.
I’ve tried several options I’ve seen: using the Stamp, with a table,… but I’m not able to get it to work.

My idea is to place the image in the upper right corner of a document, automatically, depending on the width of the document.

I’ve tried this link, between others:

The idea is put a text below “Palos de la Frontera”.
Other text right Fº, other text right Tº, other text right EXP.

A greeting,

TextAndImageAsParagraph_out.pdf (64.7 KB)

@i.salazar

Would you please try to add image stamp in PDF document which will suit your requirements. Furthermore, you can specify X,Y coordinates OR vertical/horizontal alignment as well for the image stamp as per your requirement. In case you face any issue, please feel free to let us know.

Hi, Asad,

Thank you for coming through.
I’ve already tried that option, but it doesn’t work for me either.
In the PDF I have attached, I need to add the image, so that it is above what the PDF may have, so the BackGround = true option, does not work for me, and also add text above the image I want to add.

Greetings,

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,

@i.salazar

It is good to know that you managed to achieve your requirements. Please keep using our API and in case of any further assistance, please feel free to let us know.