usmanazizgroupdocs
4/17/2017 - 9:07 AM

Utilities-AddWatermarkToAllDocumentsInFolder.vb

' For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-.NET
Dim inputFolder = SourceFolderPath
Dim outputFolder = SourceFolderPath + "/output"

Dim files = Directory.GetFiles(inputFolder)

Dim font = New Font("Arial", 8, FontStyle.Bold)
Dim watermark = New TextWatermark("CONFIDENTIAL", font)
watermark.HorizontalAlignment = HorizontalAlignment.Center
watermark.VerticalAlignment = VerticalAlignment.Center
watermark.RotateAngle = -45
watermark.SizingType = SizingType.ScaleToParentDimensions
watermark.ScaleFactor = 0.8
watermark.Opacity = 0.5
watermark.ForegroundColor = Color.Red

For Each file As Object In files
    Try
        Using doc = Document.Load(file)
            doc.AddWatermark(watermark)
            doc.Save(Path.Combine(outputFolder, Path.GetFileName(file)))
        End Using
    Catch generatedExceptionName As UnsupportedFileTypeException
        Console.WriteLine("File format is not supported. File = {0}", Path.GetFileName(file))
    End Try
Next