We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert textstamp and image

Hi,

I’m trying to add an image and a textstamp into a pdf.
I’m using following code:

var pdf = new Aspose.Pdf.Document();            
var page = pdf.Pages.Add();

var image = new Image(); 
page.Paragraphs.Add(image); 
image.File = imageFile; 

var text = new TextStamp("SAMPLE")
{
    Opacity = 50.0,
    TextAlignment = HorizontalAlignment.Center,
    HorizontalAlignment = HorizontalAlignment.Center,
    VerticalAlignment = VerticalAlignment.Center,
    Background = false
};
text.TextState.ForegroundColor = Color.Black;
text.TextState.Font = FontRepository.FindFont("Arial");
text.TextState.FontSize = 14.0F;
    
page.AddStamp(text);

pdf.Save(pdfFile);

However I’m setting the text stamp to foreground, the image is displayed over the stamp and thus the stamp is invisible.

Can you help me?
I’m using Aspose.Pdf v17.9.

@Luk_De_Reu

Thank you for contacting support.

Please try Adding Image Stamp in PDF File and then add the TextStamp to achieve your requirements.

    var pdf = new Aspose.Pdf.Document();
    var page = pdf.Pages.Add();
    // Create image stamp
    ImageStamp imageStamp = new ImageStamp(imageFile);
    imageStamp.Background = true;
    imageStamp.XIndent = 100;
    imageStamp.YIndent = 200;
    imageStamp.Opacity = 0.5;
    // Add stamp to particular page
    page.AddStamp(imageStamp);
    var text = new TextStamp("SAMPLE")
    {
        Opacity = 50.0,
        TextAlignment = HorizontalAlignment.Center,
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
        Background = false
    };
    text.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
    text.TextState.Font = FontRepository.FindFont("Arial");
    text.TextState.FontSize = 14.0F;
    page.AddStamp(text);
    pdf.Save(dataDir + "Test_18.11.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.