ImageStamp functionality not working on Linux

We have observed that the ImageStamp feature in Aspose.PDF does not work on Amazon Linux. The same code works correctly in a Windows environment. However, on Amazon Linux, the image watermark is not applied. No errors are thrown, but the output document is not watermarked with the specified image. This issue occurs only on Linux.

// Using .Net 8.0
// "Aspose.PDF" Version="25.7.0"
public static async Task Test(string[] args)
{
    await TestAddStampAsync();
}

// Using MemoryStream to read a file since the actual implementation reads from an S3 bucket
static MemoryStream GetMemoryStreamFromFile(string filePath)
{
    if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
        throw new FileNotFoundException($"File not found: {filePath}");

    byte[] fileBytes = File.ReadAllBytes(filePath);
    return new MemoryStream(fileBytes);
}

static async Task TestAddStampAsync()
{
    string outputPath = @"./Watermark.pdf";
    string dataDir = "./watermark/";
    //This file can be found here https://github.com/aspose-pdf/Aspose.PDF-for-.NET/blob/master/Examples/Data/AsposePDF/Stamps-Watermarks/test.pdf
    //ImageStamp does not work for https://github.com/aspose-pdf/Aspose.PDF-for-.NET/blob/master/Examples/Data/AsposePDF/Stamps-Watermarks/test.pdf in both Windows and Linux
    //var pdfPath = Path.Combine(dataDir, "test.pdf");
    //This file can be found here https://github.com/aspose-pdf/Aspose.PDF-for-.NET/blob/master/Examples/Data/AsposePDF/Stamps-Watermarks/input.pdf
    var pdfPath = Path.Combine(dataDir, "input.pdf");
    //This file can be found here https://github.com/aspose-pdf/Aspose.PDF-for-.NET/blob/master/Examples/Data/AsposePDF/Stamps-Watermarks/aspose-logo.jpg
    var imagePath = Path.Combine(dataDir, "aspose-logo.jpg");
    AddImageWatermarks3(pdfPath, imagePath, outputPath);
}

static void AddImageWatermarks3(string pdfPath, string imagePath, string outputPath)
{
    MemoryStream memoryStream = GetMemoryStreamFromFile(pdfPath);
    // Open PDF document
    using (var document = new Aspose.Pdf.Document(memoryStream))
    {
        Console.WriteLine($"PDF Document loaded from: {pdfPath}");
        var watermarkContent = $"Testing {DateTime.Now}";

        var textStamp = new Aspose.Pdf.TextStamp(watermarkContent);
        textStamp.TextState.FontSize = 12;
        textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Helvetica");
        textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
        textStamp.Opacity = 25 / 100.0;
        textStamp.RotateAngle = 0;
        textStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
        textStamp.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
        //This works
        document.Pages[1].AddStamp(textStamp);

        MemoryStream imageStream = GetMemoryStreamFromFile(imagePath);
        Console.WriteLine($"Image loaded from {imagePath} stream size: {imageStream.Length} bytes");
        imageStream.Position = 0;
        // Create image stamp
        Aspose.Pdf.ImageStamp imageStamp = new Aspose.Pdf.ImageStamp(imageStream);
        imageStamp.Background = true;
        imageStamp.Rotate = Aspose.Pdf.Rotation.on90;
        //The following document.Pages[1].AddStamp(imageStamp); works on windows but does not work on Amazon Linux 2023
        /**
        NAME="Amazon Linux"
        VERSION="2023"
        ID="amzn"
        ID_LIKE="fedora"
        VERSION_ID="2023"
        PLATFORM_ID="platform:al2023"
        PRETTY_NAME="Amazon Linux 2023.8.20250715"
        ANSI_COLOR="0;33"
        HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
        */
        document.Pages[1].AddStamp(imageStamp);

        // Save PDF document
        document.Save(outputPath);
        Console.WriteLine($"Watermarked document saved to: {outputPath}");
    }
}

@ClickIT

It sounds like you’re experiencing an issue with the ImageStamp feature in Aspose.PDF on Amazon Linux, while it works fine on Windows. Here’s a structured approach to diagnose and resolve the issue:

Cause: The problem may stem from differences in image format handling, file permissions, or library versions between the two environments.

Solution: Follow these steps to troubleshoot:

  1. Check Image Format: Ensure that the image format you are using (e.g., JPG, PNG) is supported and correctly handled by the library on Linux. Certain formats may behave differently across platforms.

  2. Permissions: Verify that the application has the necessary permissions to read the image file on the Linux environment. Use the ls -l command to check file permissions.

  3. Image Stream: Confirm that the image stream is correctly initialized and not empty. Log the size of the image stream before adding it as a stamp to ensure it contains data.

  4. Library Version: Ensure that you are using the same version of Aspose.PDF on both environments. If there are discrepancies, update the library on the Linux environment to match the Windows version.

  5. Debugging: Add logging to check if the AddStamp method is being called and if the image is being processed correctly. You can also try saving the document after adding the text stamp but before the image stamp to isolate the issue.

Here’s a minimal code snippet to check the image stream size:

MemoryStream imageStream = GetMemoryStreamFromFile(imagePath);
Console.WriteLine($"Image loaded from {imagePath} stream size: {imageStream.Length} bytes");
if (imageStream.Length == 0)
{
    Console.WriteLine("Image stream is empty. Check the image file.");
}

Next Steps: If these steps do not resolve the issue, please reach out to Aspose support with detailed logs and your specific environment setup for further assistance.

I hope this helps! Let me know if you have any further questions.

Thank you for the response. I have already tried all the suggestions provided above, but unfortunately, the issue persists. The AI-generated recommendations did not resolve the problem.

The ImageStamp feature continues to fail silently on Amazon Linux, while the same code works as expected on Windows. I would appreciate it if this could be reviewed by a support engineer for further investigation.

@ClickIT

Would you please make sure to use Aspose.PDF.Drawing for .NET instead of Aspose.PDF for .NET? The package is published to be used in Linux like environments as it does not require System.Drawing.Common as dependency. Please try to uninstall existing API and install Aspose.PDF.Drawing instead. In case you still notice any issues, please let us know. We will further proceed to assist you accordingly.

I can see that the Aspose.Pdf.Drawing namespace is different from the main Aspose.Pdf namespace.
The types I am currently using from Aspose.Pdf are:
Document manipulation: new Aspose.Pdf.Document(memoryStream)
Stamps: new Aspose.Pdf.TextStamp() and new Aspose.Pdf.ImageStamp()
I don’t see or am unable to find any equivalent types in the Aspose.Pdf.Drawing namespace. Could you point me to any samples where watermarking functionality (specifically TextStamp and ImageStamp) can be achieved using Aspose.Pdf.Drawing?

@ClickIT

The issue isn’t related to namespaces but rather a separate package. Aspose.PDF.Drawing for .NET is an independent API available on the NuGet Gallery. It shares the same classes and namespaces as Aspose.PDF for .NET. To switch, simply uninstall the existing Aspose.PDF package and install Aspose.PDF.Drawing instead. No code-level changes are required—your current code will function exactly as before.