We are really delighted to announce the release of version 18.3 of GroupDocs.Watermark for .NET. The latest version supports editing of the objects that can be considered as the watermark in PDF documents. Furthermore, the feature of replacing text and image for the found watermarks is also added for all the supported formats. Following are some highlighted features of version 18.3.
Editing Watermark Objects in PDF Documents
Replacing Text for Particular Objects
You can replace text for the particular XObjects, artifacts and the annotations in a PDF document. Furthermore, replacing text with formatting is also supported. Following sections demonstrate this feature with code samples.
Replacing Text
using (PdfDocument doc = Document.Load(@"D:\xobjects.pdf"))
{
// Replace text for XObjects
foreach (PdfXObject xObject in doc.Pages[0].XObjects)
{
if (xObject.Text.Contains("Test"))
{
xObject.Text = "Passed";
}
}
// Replace text for artifacts
foreach (PdfArtifact artifact in doc.Pages[0].Artifacts)
{
if (artifact.Text.Contains("Test"))
{
artifact.Text = "Passed";
}
}
// Replace text for annotations
foreach (PdfAnnotation annotation in doc.Pages[0].Annotations)
{
if (annotation.Text.Contains("Test"))
{
annotation.Text = "Passed";
}
}
doc.Save(@"D:\output.pdf");
}
Replacing Text with Formatting
using (PdfDocument doc = Document.Load(@"D:\xobjects.pdf"))
{
// Replace text for XObjects
foreach (PdfXObject xObject in doc.Pages[0].XObjects)
{
if (xObject.Text.Contains("Test"))
{
xObject.FormattedTextFragments.Clear();
xObject.FormattedTextFragments.Add("Passed", new Font("Calibri", 19, FontStyle.Bold), Color.Red, Color.Aqua);
}
}
// Replace text for artifacts
foreach (PdfArtifact artifact in doc.Pages[0].Artifacts)
{
if (artifact.Text.Contains("Test"))
{
artifact.FormattedTextFragments.Clear();
artifact.FormattedTextFragments.Add("Passed", new Font("Calibri", 19, FontStyle.Bold), Color.Red, Color.Aqua);
}
}
// Replace text for annotations
foreach (PdfAnnotation annotation in doc.Pages[0].Annotations)
{
if (annotation.Text.Contains("Test"))
{
annotation.FormattedTextFragments.Clear();
annotation.FormattedTextFragments.Add("Passed", new Font("Calibri", 19, FontStyle.Bold), Color.Red, Color.Aqua);
}
}
doc.Save(@"D:\output.pdf");
}
Replacing Image for Particular ObjectsThe version 18.3 also supports replacing image for the particular XObjects, artifacts and the annotations as shown in the following code sample.
using (PdfDocument doc = Document.Load(@"D:\xobjects.pdf"))
{
// Replace image for XObjects
foreach (PdfXObject xObject in doc.Pages[0].XObjects)
{
if (xObject.Image != null)
{
xObject.Image = new PdfWatermarkableImage(File.ReadAllBytes(@"D:\test.png"));
}
}
// Replace image for artifacts
foreach (PdfArtifact artifact in doc.Pages[0].Artifacts)
{
if (artifact.Image != null)
{
artifact.Image = new PdfWatermarkableImage(File.ReadAllBytes(@"D:\test.png"));
}
}
// Replace image for annotations
foreach (PdfAnnotation annotation in doc.Pages[0].Annotations)
{
if (annotation.Image != null)
{
annotation.Image = new PdfWatermarkableImage(File.ReadAllBytes(@"D:\test.png"));
}
}
doc.Save(@"D:\output.pdf");
}
Replacing Text and Image for Found Watermarks
The latest version allows replacing text and image for the found possible watermarks that we get in a search result. Following sections demonstrate how to replace text and image for the found watermarks.
Replacing Text
using (Document doc = Document.Load(@"D:\input.pptx"))
{
TextSearchCriteria searchCriteria = new TextSearchCriteria("test", false);
PossibleWatermarkCollection watermarks = doc.FindWatermarks(searchCriteria);
foreach (PossibleWatermark watermark in watermarks)
{
try
{
watermark.Text = "passed";
}
catch (Exception e)
{
// Found entity may not support text editing
// Passed argument can have inappropriate value
// Process such cases here
}
}
doc.Save(@"D:\output.pptx");
}
Replacing Image
byte[] imageData = File.ReadAllBytes(@"D:\new_logo.png");
using (Document doc = Document.Load(@"D:\input.pdf"))
{
SearchCriteria searchCriteria = new ImageDctHashSearchCriteria(@"D:\logo.bmp");
PossibleWatermarkCollection watermarks = doc.FindWatermarks(searchCriteria);
foreach (PossibleWatermark watermark in watermarks)
{
try
{
watermark.ImageData = imageData;
}
catch (Exception e)
{
// Found entity may not support image replacing
// Passed image can have inappropriate format
// Process such cases here
}
}
doc.Save(@"D:\output.pdf");
}
For more details on this feature, please visit this documentation article.
Available Channels and Resources
Here are a few channels and resources for you to download, learn, try and get technical support on GroupDocs.Watermark:
- Download - MSI Package as well as Zipped DLLs
- NuGet - NuGet Installation
- Documentation - API Documentation
- Examples - Code Examples
- Video Tutorials – YouTube Video Tutorials
- Product Support Forum - Technical Support Forum for GroupDocs.Watermark
Feedback
As always, we would love to hear your queries and suggestions at our forum.