GroupDocsGists
10/19/2017 - 11:08 AM

Documents-RasterizePDFDocumentWithPageNumber.vb

' For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-.NET
Using doc As PdfDocument = Document.Load(Of PdfDocument)(Utilities.MapSourceFilePath(FilePath))
    ' Initialize image or text watermark
    Dim watermark As New TextWatermark("Do not copy", New Font("Arial", 8))
    watermark.HorizontalAlignment = HorizontalAlignment.Center
    watermark.VerticalAlignment = VerticalAlignment.Center
    watermark.RotateAngle = 45
    watermark.SizingType = SizingType.ScaleToParentDimensions
    watermark.ScaleFactor = 1
    watermark.Opacity = 0.5

    ' Add watermark of any type first
    doc.Pages(0).AddWatermark(watermark)

    ' Rasterize the first page
    doc.Pages(0).Rasterize(100, 100, PdfImageConversionFormat.Png)

    ' Content of the first page is replaced with raster image
    doc.Save()
End Using