Public Class Form1
    Private Declare Function MEncryptPDF Lib "pdfencrypt.dll" (ByVal id As Integer, ByVal infile As String, ByVal outfile As String, ByVal userpassword As String, ByVal ownerpassword As String,
                                                                ByVal encryptlevel As Integer, ByVal printing As Integer, ByVal copying As Integer, ByVal changing As Integer) As Integer
    Private Declare Function MBegin Lib "pdfencrypt.dll" () As Integer
    Private Declare Function MInformation Lib "pdfencrypt.dll" (ByVal id As Integer, ByVal title As String, ByVal subject As String, ByVal author As String,
                                                         ByVal keywords As String, ByVal creator As String, ByVal producer As String) As Integer

    Private Declare Function MWatermark Lib "pdfencrypt.dll" (ByVal id As Integer, ByVal text As String, ByVal fsize As Integer, ByVal fcolor As Integer,
                                                           ByVal position As Integer, ByVal angle As Integer, ByVal xoff As Integer, ByVal yoff As Integer, ByVal asbackground As Integer) As Integer

    Private Declare Function MEnd Lib "pdfencrypt.dll" (ByVal id As Integer) As Integer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim id As Integer
        Dim fsize As Integer
        Dim fcolor As Integer
        Dim position As Integer
        Dim angle As Integer
        Dim xoff As Integer
        Dim yoff As Integer
        Dim asbackground As Integer

        id = MBegin()
        If (id > 0) Then
            'Set PDF Information
            MInformation(id, "title", "subject", "author", "keywords", "creator", "producer")

            fsize = 16
            fcolor = 255 'red
            position = 2 'Top-Center
            angle = 0
            xoff = 0
            yoff = 0
            asbackground = 0
            MWatermark(id, "Watermark", fsize, fcolor, position, angle, xoff, yoff, asbackground)

            'test3 Encrypt
            MEncryptPDF(id, "test.pdf", "testEncrypt.pdf", "user", "owner", 128, 1, 0, 0)
            MEnd(id)
        End If

        MsgBox("Encrypt finished!")
    End Sub

End Class
