Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET 允许使用 Artifacts 向您的 PDF 文档添加水印。请查看本文以解决您的任务。
以下代码片段还可以与 Aspose.PDF.Drawing 库一起使用。
使用 Adobe Acrobat 创建的水印称为工件(如 PDF 规范中的 14.8.2.2 真实内容和工件所述)。为了处理工件,Aspose.PDF 有两个类:Artifact 和 ArtifactCollection。
为了获取特定页面上的所有工件,Page 类具有 Artifacts 属性。此主题解释了如何在 PDF 文件中处理工件。
Artifact 类包含以下属性:
以下代码片段演示了如何使用 C# 获取 PDF 文件第一页上的每个水印。
// 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.