Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GroupDocs.Watermark for .NET 19.10
foreach (string filePath in Directory.GetFiles(@"C:\Documents"))
{
using (Watermarker watermarker = new Watermarker(filePath))
{
TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36));
watermark.ForegroundColor = Color.Red;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
watermark.VerticalAlignment = VerticalAlignment.Center;
watermarker.Add(watermark);
watermarker.Save();
}
}
foreach (string filePath in Directory.GetFiles(@"C:\Documents"))
{
using (Document document = Document.Load(filePath))
{
TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36))
watermark.ForegroundColor = Color.Red;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
watermark.VerticalAlignment = VerticalAlignment.Center;
document.AddWatermark(watermark);
document.Save();
}
}
using (Watermarker watermarker = new Watermarker(@"C:\document.ppt"))
{
IDocumentInfo info = watermarker.GetDocumentInfo();
Console.WriteLine("File type: {0}", info.FileType);
Console.WriteLine("Number of pages: {0}", info.PageCount);
Console.WriteLine("Document size: {0} bytes", info.Size);
}
DocumentInfo documentInfo = Document.GetInfo(@"C:\document.ppt");
Console.WriteLine(documentInfo.FileFormat);
Console.WriteLine(documentInfo.IsEncrypted);
using (Watermarker watermarker = new Watermarker(@"C:\document.pdf"))
{
PossibleWatermarkCollection watermarks = watermarker.Search();
watermarker.Remove(watermarks);
watermarker.Save(@"C:\document_without_watermarks.pdf");
}
using (Document doc = Document.Load(@"C:\document.pdf"))
{
PossibleWatermarkCollection watermarks = doc.FindWatermarks();
watermarks.Clear();
doc.Save(@"C:\document_without_watermarks.pdf");
}
using (Watermarker watermarker = new Watermarker(@"C:\document.pdf"))
{
SizeSearchCriteria widthRange = new SizeSearchCriteria(Dimension.Width, 50, 100);
RotateAngleSearchCriteria rotateAngle = new RotateAngleSearchCriteria(0, 45);
TextSearchCriteria textCriteria = new TextSearchCriteria(new Regex("^Test watermark$"));
PossibleWatermarkCollection watermarks = watermarker.Search(textCriteria.And(widthRange.Or(rotateAngle)));
Console.WriteLine("Found {0} possible watermarks.", watermarks.Count);
}
using (Document doc = Document.Load(@"C:\document.pdf"))
{
SizeSearchCriteria widthRange = new SizeSearchCriteria(Dimension.Width, 50, 100);
RotateAngleSearchCriteria rotateAngle = new RotateAngleSearchCriteria(0, 45);
TextSearchCriteria textCriteria = new TextSearchCriteria(new Regex("^Test watermark$"));
PossibleWatermarkCollection watermarks = doc.FindWatermarks(textCriteria.And(widthRange.Or(rotateAngle)));
Console.WriteLine("Found {0} possible watermarks.", watermarks.Count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.