Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET allows adding watermarks to your PDF document using Artifacts. Please check this article to resolve your task.
The following code snippet also work with Aspose.PDF.Drawing library.
A watermark created with Adobe Acrobat is called an artifact (as described in 14.8.2.2 Real Content and Artifacts of the PDF specification). In order to work with artifacts, Aspose.PDF has two classes: Artifact and ArtifactCollection.
In order to get all artifacts on a particular page, the Page class has the Artifacts property. This topic explains how to work with artifact in PDF files.
The Artifact class contains following properties:
The following code snippet shows how to get each watermark on the first page of a PDF file with C#.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddWatermarks()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "AddWatermarksInput.pdf"))
{
// Create a new watermark artifact
var artifact = new Aspose.Pdf.WatermarkArtifact();
artifact.SetTextAndState(
"WATERMARK",
new Aspose.Pdf.Text.TextState()
{
FontSize = 72,
ForegroundColor = Aspose.Pdf.Color.Blue,
Font = Aspose.Pdf.Text.FontRepository.FindFont("Courier")
});
// Set watermark properties
artifact.ArtifactHorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
artifact.ArtifactVerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
artifact.Rotation = 45;
artifact.Opacity = 0.5;
artifact.IsBackground = true;
// Add watermark artifact to the first page
document.Pages[1].Artifacts.Add(artifact);
// Save PDF document
document.Save(dataDir + "AddWatermarks_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.