I want to add image watermark to PDF through WatermarkArtifact. When the image width is relatively large, the watermark will not be fully displayed on the page and i can’t resize the image watermark.
var doc = new Aspose.Pdf.Document();
doc.Pages.Add();
//add Watermark
var artifact = new WatermarkArtifact();
artifact.SetImage(@"C:\Users\54390\Desktop\watermark-logo.png");
artifact.Position = new Aspose.Pdf.Point(0, 0);
doc.Pages[1].Artifacts.Add(artifact);
doc.Save(@"C:\Users\54390\Desktop\output.pdf");
Logo file
watermark-logo.jpg (67.6 KB)
Output file
output.pdf (226.7 KB)
I try to use Magick.NET to resize the image, but the watermark image is very blurred after shrinking.
using (var imageFactory = new MagickImage(@"C:\Users\54390\Desktop\watermark-logo.png"))
{
var doc = new Aspose.Pdf.Document();
doc.Pages.Add();
var artifact = new WatermarkArtifact();
using (var imageStream = new System.IO.MemoryStream())
{
//Resize Image
imageFactory.Resize(new Percentage(24));
imageFactory.Write(imageStream);
imageStream.Position = 0;
artifact.SetImage(imageStream);
artifact.Position = new Aspose.Pdf.Point(0, 0);
doc.Pages[1].Artifacts.Add(artifact);
doc.Save(@"C:\Users\54390\Desktop\output.pdf");
}
}
If I inserted this picture on the page, the definition is very high.
20230422181613.png (79.2 KB)
How can I insert a picture watermark with specified width and height and keep the clarity?