Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
다음 코드 스니펫은 Aspose.PDF.Drawing 라이브러리와 함께 작동합니다.
워터마크 주석은 페이지의 고정된 크기와 위치에 인쇄될 그래픽을 나타내는 데 사용됩니다. 인쇄된 페이지의 치수와 관계없이 사용됩니다.
특정 PDF 페이지 위치에 WatermarkAnnotation를 사용하여 워터마크 텍스트를 추가할 수 있습니다. 워터마크의 불투명도는 불투명도 속성을 사용하여 제어할 수 있습니다.
워터마크 주석을 추가하기 위한 다음 코드 스니펫을 확인하십시오.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddWatermarkAnnotation()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "source.pdf"))
{
// Load Page object to add Annotation
var page = document.Pages[1];
// Create Watermark Annotation
var wa = new Aspose.Pdf.Annotations.WatermarkAnnotation(page, new Aspose.Pdf.Rectangle(100, 500, 400, 600));
// Add annotation into Annotation collection of Page
page.Annotations.Add(wa);
// Create TextState for Font settings
var ts = new Aspose.Pdf.Text.TextState();
ts.ForegroundColor = Aspose.Pdf.Color.Blue;
ts.Font = Aspose.Pdf.Text.FontRepository.FindFont("Times New Roman");
ts.FontSize = 32;
// Set opacity level of Annotation Text
wa.Opacity = 0.5;
// Add Text in Annotation
wa.SetTextAndState(new string[] { "HELLO", "Line 1", "Line 2" }, ts);
// Save PDF document
document.Save(dataDir + "AddWatermarkAnnotation_out.pdf");
}
}
때때로 PDF 문서에서 동일한 이미지를 여러 번 사용해야 하는 요구 사항이 있습니다. 새 인스턴스를 추가하면 결과 PDF 문서가 증가합니다. 우리는 Aspose.PDF for .NET 17.1.0에서 XImageCollection.Add(XImage)라는 새로운 메서드를 추가했습니다. 이 메서드는 PDF 문서 크기를 최적화하는 원본 이미지와 동일한 PDF 객체에 대한 참조를 추가할 수 있게 해줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddWatermarkAnnotationWithImage()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Define the rectangle for the image
var imageRectangle = new Aspose.Pdf.Rectangle(0, 0, 30, 15);
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Open the image stream
using (var imageStream = File.Open(dataDir + "icon.png", FileMode.Open))
{
XImage image = null;
// Iterate through each page in the document
foreach (Page page in document.Pages)
{
// Create a Watermark Annotation
var annotation = new Aspose.Pdf.Annotations.WatermarkAnnotation(page, page.Rect);
XForm form = annotation.Appearance["N"];
form.BBox = page.Rect;
string name;
// Add the image to the form resources if it hasn't been added yet
if (image == null)
{
name = form.Resources.Images.Add(imageStream);
image = form.Resources.Images[name];
}
else
{
name = form.Resources.Images.Add(image);
}
// Add operators to the form contents to place the image
form.Contents.Add(new Aspose.Pdf.Operators.GSave());
form.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(new Aspose.Pdf.Matrix(imageRectangle.Width, 0, 0, imageRectangle.Height, 0, 0)));
form.Contents.Add(new Aspose.Pdf.Operators.Do(name));
form.Contents.Add(new Aspose.Pdf.Operators.GRestore());
// Add the annotation to the page
page.Annotations.Add(annotation, false);
// Adjust the image rectangle size for the next iteration
imageRectangle = new Aspose.Pdf.Rectangle(0, 0, imageRectangle.Width * 1.01, imageRectangle.Height * 1.01);
}
}
// Save PDF document
document.Save(dataDir + "AddWatermarkAnnotationWithImage_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.