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}");
}
}