Public Class Form1
    Inherits System.Windows.Forms.Form


    Private Declare Function ApCreate Lib "imagetopdf.dll" (ByVal lpFileName As String) As Integer
    Private Declare Function ApOpen Lib "imagetopdf.dll" (ByVal lpFileName As String) As Integer
    Private Declare Sub ApClose Lib "imagetopdf.dll" (ByVal id As Integer)
    Private Declare Function ApAddImage Lib "imagetopdf.dll" (ByVal id As Integer, ByVal lpFileName As String) As Integer
    Private Declare Function ApAddImageData Lib "imagetopdf.dll" (ByVal id As Integer, ByVal MemData() As Byte, ByVal width As Integer, ByVal height As Integer, ByVal color As Integer) As Integer
    Private Declare Function ApAddTextEx Lib "imagetopdf.dll" (ByVal id As Integer, ByVal x As Integer, ByVal y As Integer, ByVal str As String, ByVal color As Integer) As Integer
    Private Declare Function ApAddText Lib "imagetopdf.dll" (ByVal id As Integer, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal str As String, ByVal color As Integer, ByVal bkcolor As Integer, ByVal lformat As Integer) As Integer
    Private Declare Function ApAddTxt Lib "imagetopdf.dll" (ByVal id As Integer, ByVal lpFileName As String, ByVal color As Integer, ByVal PageWidth As Integer, ByVal PageHeight As Integer, ByVal AutoNewLine As Integer, ByVal AutoWidthAdjust As Integer, ByVal LeftMargin As Integer, ByVal RightMargin As Integer, ByVal TopMargin As Integer, ByVal BottomMargin As Integer, ByVal TabSize As Integer) As Integer
    Private Declare Function ApAddLine Lib "imagetopdf.dll" (ByVal id As Integer, ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal side_width As Integer, ByVal side_color As Integer) As Integer
    Private Declare Function ApAddRect Lib "imagetopdf.dll" (ByVal id As Integer, ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal side_width As Integer, ByVal side_color As Integer, ByVal flagFill As Integer, ByVal fill_color As Integer) As Integer
    Private Declare Function ApAddInfo Lib "imagetopdf.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) As Integer
    Private Declare Function ApSetFunction Lib "imagetopdf.dll" (ByVal id As Integer, ByVal func_code As Integer, ByVal Para1 As Integer, ByVal Para2 As Integer, ByVal szPara3 As String, ByVal szPara4 As String) As Integer
    Private Declare Function ApGetFunction Lib "imagetopdf.dll" (ByVal id As Integer, ByVal func_code As Integer, ByVal Para1 As Integer, ByVal Para2 As Integer, ByVal szPara3 As String, ByVal szPara4 As String) As Integer


    'defined for ApSetFunction
    Const Ap_Set_MultiPage = 101
    Const Ap_Set_ImagePosAndSize = 104
    Const Ap_Set_Encrypt = 105
    Const Ap_Set_Font = 106
    Const Ap_Set_NewOrClosePage = 109
    Const Ap_Set_BookMark = 110
    Const Ap_Set_ViewerPreferences = 121
    Const Ap_Set_Orientation = 122
    Const Ap_Set_Recompress = 123
    Const Ap_Set_Skewcorrect = 126
    Const Ap_Set_JpegQuality = 128

    'defined for ApGetFunction
    Const Ap_Get_ImagePageCount = 201
    Const Ap_Get_ImageSizeW = 202
    Const Ap_Get_ImageSizeH = 203
    Const Ap_Get_ImageDpiX = 204
    Const Ap_Get_ImageDpiY = 205
    Const Ap_Get_PdfPageCount = 206
    Const Ap_Get_PdfCurrentPageSize = 209
    Const Ap_Get_StringWidth = 250
    Const Ap_Get_StringHeight = 251
    Const Ap_Get_Recomporess = 210
    Const Ap_Get_ImageBits = 211

    'defined for ApAddText
    Const Ap_DT_LEFT = &H0
    Const Ap_DT_CENTER = &H1
    Const Ap_DT_RIGHT = &H2
    Const Ap_DT_WORDBREAK = &H10
    Const Ap_DT_CALCRECT = &H400

    'defined permission
    Const permission_Print = 1
    Const permission_Copy = 2
    Const permission_Modify = 4


    Private Sub AddImageData(ByVal id As Integer)
        Dim ret, i, j As Integer
        Dim tmp1, tmp2 As Integer
        Dim red, green, blue, color As Byte

        Dim MemImageWidth As Integer = 640
        Dim MemImageHeight As Integer = 640

        Dim MemImage(MemImageWidth * MemImageHeight * 3) As Byte


        color = 24  'can be equal 1 , 8 or 24

        For i = 0 To MemImageHeight - 1
            For j = 0 To MemImageWidth - 1
                tmp1 = i And 8
                tmp2 = j And 8
                If tmp1 Xor tmp2 Then
                    red = 255
                    green = blue = 0
                Else
                    red = 0
                    green = blue = 255
                End If

                MemImage(i * MemImageWidth * 3 + j * 3 + 0) = red
                MemImage(i * MemImageWidth * 3 + j * 3 + 1) = green
                MemImage(i * MemImageWidth * 3 + j * 3 + 2) = blue
            Next
        Next

        'create page
        ret = ApSetFunction(id, Ap_Set_NewOrClosePage, MemImageWidth, MemImageHeight, Nothing, Nothing)

        ret = ApAddImageData(id, MemImage, MemImageWidth, MemImageHeight, color)


        'close page
        ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 0, 0, Nothing, Nothing)

    End Sub




    'split image file
    Private Sub One2Multiple(ByVal pPdf As String, ByVal pImage As String)
        Dim szPDFFile As String
        Dim ret, id, pageCount, beginPage As Integer

        'get multipage image page count
        pageCount = ApGetFunction(0, Ap_Get_ImagePageCount, 0, 0, pImage, Nothing)

        For beginPage = 1 To pageCount

            szPDFFile = pPdf + Str(beginPage) + ".pdf"
            id = ApCreate(szPDFFile)
            If id > 0 Then
                ret = ApSetFunction(id, Ap_Set_MultiPage, beginPage, 1, Nothing, Nothing)
                ret = ApAddImage(id, pImage)
                ApClose(id)
            End If
        Next beginPage

    End Sub

    Private Sub One2One(ByVal pPdf As String, ByVal pImage As String)

        Dim ret, id As Integer

        id = ApCreate(pPdf)
        If id > 0 Then
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub

    'merge image file
    Private Sub Multiple2One(ByVal pPdf As String, ByVal pImage() As String, ByVal length As Integer)
        Dim ret, id, i As Integer

        id = ApCreate(pPdf)
        If id > 0 Then
            For i = 0 To length - 1

                ret = ApAddImage(id, pImage(i))

            Next i
            ApClose(id)
        End If

    End Sub


    Private Sub AppendPDF(ByVal pPdf As String, ByVal pImage() As String, ByVal length As Integer)
        Dim ret, id, i As Integer

        For i = 0 To length - 1
            id = ApOpen(pPdf)
            If id <= 0 Then
                id = ApCreate(pPdf)
            End If
            ret = ApAddImage(id, pImage(i))

            ApClose(id)
        Next i
    End Sub


    Private Sub Skewcorrect(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id As Integer

        id = ApCreate(pPdf)
        If id > 0 Then

            ret = ApAddImage(id, pImage)
            'set skewcorrect
            ret = ApSetFunction(id, Ap_Set_Skewcorrect, 1, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)

            ApClose(id)
        End If
    End Sub



    Private Sub RecompressTruecolorFile(ByVal pPdf As String, ByVal pImage As String)
        Dim szPDFFile As String
        Dim ret, id As Integer

        'recompress lzw
        szPDFFile = pPdf + "_lzw.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 3, 0, "lzw", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress zip
        szPDFFile = pPdf + "_zip.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 3, 0, "zip", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress packbits
        szPDFFile = pPdf + "_packbits.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 3, 0, "packbits", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress jpeg,quality=100
        szPDFFile = pPdf + "_jpeg_100.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 3, 0, "jpeg", Nothing)
            ret = ApSetFunction(id, Ap_Set_JpegQuality, 100, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress jpeg,quality=50
        szPDFFile = pPdf + "_jpeg_50.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 3, 0, "jpeg", Nothing)
            ret = ApSetFunction(id, Ap_Set_JpegQuality, 50, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub

    Private Sub RecompressGrayFile(ByVal pPdf As String, ByVal pImage As String)
        Dim szPDFFile As String
        Dim ret, id As Integer

        'recompress lzw
        szPDFFile = pPdf + "_lzw.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 2, 0, "lzw", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress zip
        szPDFFile = pPdf + "_zip.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 2, 0, "zip", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress packbits
        szPDFFile = pPdf + "_packbits.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 2, 0, "packbits", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        'recompress jpeg, default quality=75
        szPDFFile = pPdf + "_jpeg.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 2, 0, "jpeg", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub

    Private Sub RecompressBlackWhiteFile(ByVal pPdf As String, ByVal pImage As String)
        Dim szPDFFile As String
        Dim ret, id As Integer

        szPDFFile = pPdf + "_lzw.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 1, 0, "lzw", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        szPDFFile = pPdf + "_zip.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 1, 0, "zip", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        szPDFFile = pPdf + "_g3.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 1, 0, "g3", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        szPDFFile = pPdf + "_g4.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Recompress, 1, 0, "g4", Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub

    Private Sub Recompress(ByVal pPdf As String, ByVal pImage As String)
        Dim bits As Integer

        bits = ApGetFunction(0, Ap_Get_ImageBits, 0, 0, pImage, Nothing)
        If (bits = 1) Then
            RecompressBlackWhiteFile(pPdf, pImage)
        Else
            If (bits = 8) Then
                RecompressGrayFile(pPdf, pImage)
            Else
                If (bits = 24) Then
                    RecompressTruecolorFile(pPdf, pImage)
                End If
            End If
        End If

    End Sub


    Private Sub PageSize(ByVal pPdf As String, ByVal pImage As String)

        Dim ret, id As Integer
        Dim ImageWidth, ImageHeight, ImageWidth2, ImageHeight2, PageWidth, PageHeight As Integer
        Dim xdpi, ydpi As Integer
        Dim fZoom, zw, zh As Double

        id = ApCreate(pPdf)
        If (id > 0) Then
            'Get image width and height
            ImageWidth = ApGetFunction(id, Ap_Get_ImageSizeW, 0, 0, pImage, Nothing)
            ImageHeight = ApGetFunction(id, Ap_Get_ImageSizeH, 0, 0, pImage, Nothing)

            'Get image dpi (Resolution)
            xdpi = ApGetFunction(id, Ap_Get_ImageDpiX, 0, 0, pImage, Nothing)
            ydpi = ApGetFunction(id, Ap_Get_ImageDpiY, 0, 0, pImage, Nothing)

            'keep image dpi (resolution)
            If (xdpi > 0 And ydpi > 0) Then
                ImageWidth2 = (ImageWidth * (72.0# / xdpi))
                ImageHeight2 = (ImageHeight * (72.0# / ydpi))
            End If
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, ImageWidth2, ImageHeight2, Nothing, Nothing)
            ret = ApAddImage(id, pImage)

            'page size with image size
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, ImageWidth, ImageHeight, Nothing, Nothing)
            ret = ApAddImage(id, pImage)

            'A4
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 2, 2, Nothing, Nothing)
            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, 0, 0, Str(ImageWidth), Str(ImageHeight))
            ret = ApAddImage(id, pImage)

            'custom page size and fit width/height
            PageWidth = 768
            PageHeight = 1024
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, PageWidth, PageHeight, Nothing, Nothing)
            zw = PageWidth / ImageWidth
            zh = PageHeight / ImageHeight
            fZoom = IIf(zw < zh, zw, zh)
            ImageWidth = (ImageWidth * fZoom)
            ImageHeight = (ImageHeight * fZoom)
            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, (PageWidth - ImageWidth) / 2, (PageHeight - ImageHeight) / 2, Str(ImageWidth), Str(ImageHeight))
            ret = ApAddImage(id, pImage)

            ApClose(id)

        End If


    End Sub

    Private Sub PageLayout(ByVal pPdf As String, ByVal pImage() As String, ByVal length As Integer)
        Dim ret, id, i, nPos, nPages, index As Integer
        Dim ImageWidth, ImageHeight, PageWidth, PageHeight As Integer

        nPos = 1
        PageWidth = 768
        PageHeight = 1024

        id = ApCreate(pPdf)
        If (id > 0) Then

            For i = 0 To length - 1

                'get pages
                nPages = ApGetFunction(id, Ap_Get_ImagePageCount, 0, 0, pImage(i), Nothing)

                For index = 1 To nPages

                    Select Case nPos Mod 4
                        Case 1
                            'new page
                            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, PageWidth, PageHeight, Nothing, Nothing)
                            'set image posion
                            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, 0, 0, Str(PageWidth / 2), Str(PageHeight / 2))
                            ret = ApSetFunction(id, Ap_Set_MultiPage, index, 1, Nothing, Nothing)
                            ret = ApAddImage(id, pImage(i))
                        Case 2
                            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, PageWidth / 2, 0, Str(PageWidth / 2), Str(PageHeight / 2))
                            ret = ApSetFunction(id, Ap_Set_MultiPage, index, 1, Nothing, Nothing)
                            ret = ApAddImage(id, pImage(i))
                        Case 3
                            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, 0, PageHeight / 2, Str(PageWidth / 2), Str(PageHeight / 2))
                            ret = ApSetFunction(id, Ap_Set_MultiPage, index, 1, Nothing, Nothing)
                            ret = ApAddImage(id, pImage(i))
                        Case 0
                            ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, PageWidth / 2, PageHeight / 2, Str(PageWidth / 2), Str(PageHeight / 2))
                            ret = ApSetFunction(id, Ap_Set_MultiPage, index, 1, Nothing, Nothing)
                            ret = ApAddImage(id, pImage(i))
                            'close page
                            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 0, 0, Nothing, Nothing)

                    End Select

                    nPos = nPos + 1

                Next index
            Next i
            ApClose(id)

        End If
    End Sub


    Private Sub PageOrientation(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id, i, nOrientation As Integer
        Dim szPDFFile As String

        nOrientation = 90
        szPDFFile = pPdf + "_90.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Orientation, nOrientation, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        nOrientation = 180
        szPDFFile = pPdf + "_180.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Orientation, nOrientation, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

        nOrientation = 270
        szPDFFile = pPdf + "_270.pdf"
        id = ApCreate(szPDFFile)
        If (id > 0) Then
            ret = ApSetFunction(id, Ap_Set_Orientation, nOrientation, 0, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If
    End Sub


    Private Sub Watermark(ByVal pPdf As String, ByVal pImage() As String, ByVal length As Integer)
        Dim ret, id, i, nPos, nPages, index As Integer
        Dim ImageWidth, ImageHeight As Integer
        Dim nPosX, nPosY As Integer

        id = ApCreate(pPdf)
        If (id > 0) Then
            For i = 0 To length - 1
                nPages = ApGetFunction(id, Ap_Get_ImagePageCount, 0, 0, pImage(i), Nothing)
                For index = 1 To nPages

                    'get image width and height
                    ImageWidth = ApGetFunction(id, Ap_Get_ImageSizeW, 0, 0, pImage(i), Str(index))
                    ImageHeight = ApGetFunction(id, Ap_Get_ImageSizeH, 0, 0, pImage(i), Str(index))
                    'new page
                    ret = ApSetFunction(id, Ap_Set_NewOrClosePage, ImageWidth, ImageHeight, Nothing, Nothing)
                    'set image pos
                    ret = ApSetFunction(id, Ap_Set_ImagePosAndSize, 0, 0, Str(ImageWidth), Str(ImageHeight))

                    ret = ApSetFunction(id, Ap_Set_MultiPage, index, 1, Nothing, Nothing)
                    ret = ApAddImage(id, pImage(i))

                    'set system font and size
                    ret = ApSetFunction(id, Ap_Set_Font, 1, 32, "Arial", Nothing)
                    'add text
                    nPosX = 10
                    nPosY = ImageHeight / 2
                    ret = ApAddTextEx(id, nPosX, nPosY, "(c)Copyright XXXXXXXXXX", RGB(255, 0, 0))

                    'close page
                    ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 0, 0, Nothing, Nothing)

                Next index
            Next i
            ApClose(id)

        End If

    End Sub


    Private Sub PDFsecurity(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id As Integer

        id = ApCreate(pPdf)
        If id > 0 Then
            'set password and permission
            ret = ApSetFunction(id, Ap_Set_Encrypt, 128, permission_Print + permission_Copy + permission_Modify, "owner", "user")
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If


    End Sub





    Private Sub PDFInfo(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id As Integer

        id = ApCreate(pPdf)
        If id > 0 Then
            ret = ApAddInfo(id, "Title", "Subject", "Author", "Keywords", "Creator")
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub



    Private Sub Bookmark(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id, beginPage, pageCount As Integer
        Dim szBookmark As String

        id = ApCreate(pPdf)
        If id > 0 Then

            'get multi page image page count
            pageCount = ApGetFunction(id, Ap_Get_ImagePageCount, 0, 0, pImage, Nothing)
            For beginPage = 1 To pageCount
                'add bookmark
                szBookmark = "bookmark " + Str(beginPage)
                ret = ApSetFunction(id, Ap_Set_BookMark, 0, 0, szBookmark, Nothing)
                'Add page
                ret = ApSetFunction(id, Ap_Set_MultiPage, beginPage, 1, Nothing, Nothing)
                ret = ApAddImage(id, pImage)
            Next beginPage

            ApClose(id)

        End If

    End Sub


    Private Sub ViewerPreferences(ByVal pPdf As String, ByVal pImage As String)
        Dim ret, id As Integer

        id = ApCreate(pPdf)
        If id > 0 Then
            ret = ApSetFunction(id, Ap_Set_ViewerPreferences, 4 + 4096, 2, Nothing, Nothing)
            ret = ApAddImage(id, pImage)
            ApClose(id)
        End If

    End Sub


    Private Sub TextAndGraphics(ByVal pPdf As String)
        Dim ret, id, width, height As Integer
        Dim szString As String

        szString = "this is a text! this is a text! this is a text! this is a text!"

        id = ApCreate(pPdf)
        If id > 0 Then
            'create a page for a3
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 1, 1, Nothing, Nothing)
            'set system font and size
            ret = ApSetFunction(id, Ap_Set_Font, 1, 32, "Arial", Nothing)
            'add text
            ret = ApAddTextEx(id, 300, 300, "this is a text!", RGB(0, 255, 255))

            'set system font and size
            ret = ApSetFunction(id, Ap_Set_Font, 1, 32, "Helvetica", Nothing)
            'add text
            ret = ApAddTextEx(id, 300, 400, "this is a text!", RGB(0, 255, 255))

            'set adobe font and size
            ret = ApSetFunction(id, Ap_Set_Font, 203, 32, Nothing, Nothing)
            'add text with rectangle
            width = 400
            height = 200
            ret = ApAddText(id, 100, 50, width, height, szString, RGB(0, 0, 255), RGB(255, 0, 255), Ap_DT_WORDBREAK + Ap_DT_CENTER)

            'set system font and size
            ret = ApSetFunction(id, Ap_Set_Font, 1, 32, "Verdana", Nothing)
            'add text
            ret = ApAddTextEx(id, 300, 500, "this is a text!", RGB(0, 255, 255))

            'create a page for b5
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 4, 4, Nothing, Nothing)
            'add graphic
            ret = ApAddLine(id, 10, 10, 100, 200, 5, RGB(0, 0, 255))
            ret = ApAddRect(id, 20, 210, 300, 400, 3, RGB(0, 255, 0), 1, RGB(255, 0, 255))
            'close page
            ret = ApSetFunction(id, Ap_Set_NewOrClosePage, 0, 0, Nothing, Nothing)

            'add a txt file
            ret = ApSetFunction(id, Ap_Set_Font, 200, 16, Nothing, Nothing)
            ret = ApAddTxt(id, "test.txt", 0, 0, 0, 1, 1, 64, 64, 64, 64, 4)

            'add memory image
            AddImageData(id)

            ApClose(id)

        End If
    End Sub









#Region " Windows form "

    Public Sub New()
        MyBase.New()


        InitializeComponent()



    End Sub


    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub


    Private components As System.ComponentModel.IContainer
    Friend WithEvents Button1 As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(72, 104)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(144, 48)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Click it"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "For VB.Net"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim szMultiPage As String
        Dim szBlackWhite As String
        Dim szGray As String
        Dim szTrueColor As String
        Dim szSkewcorrect As String
        Dim szJpg As String
        Dim szBmp As String
        Dim szGif As String
        Dim szEmf As String
        Dim szWmf As String
        Dim szDcx As String
        Dim szPcx As String
        Dim szPsd As String
        Dim szInput(20) As String
        Dim path As String

        szMultiPage = "MultiPage.tif"
        szBlackWhite = "BlackWhite.tif"
        szGray = "Gray.tif"
        szTrueColor = "TrueColor.tif"
        szSkewcorrect = "Skewcorrect.tif"
        szJpg = "test.jpg"
        szBmp = "test.bmp"
        szGif = "test.gif"
        szEmf = "test.emf"
        szWmf = "test.wmf"
        szDcx = "test.dcx"
        szPcx = "test.pcx"
        szPsd = "test.psd"

        szInput(0) = szMultiPage
        szInput(1) = szBlackWhite
        szInput(2) = szGray
        szInput(3) = szTrueColor
        szInput(4) = szJpg
        szInput(5) = szBmp
        szInput(6) = szGif
        szInput(7) = szEmf
        szInput(8) = szWmf
        szInput(9) = szDcx
        szInput(10) = szPcx
        szInput(11) = szPsd

        One2Multiple("One2Multiple1", szMultiPage)
        One2Multiple("One2Multiple2", szDcx)

        One2One("One2One1.pdf", szMultiPage)
        One2One("One2One2.pdf", szDcx)

        Multiple2One("Multiple2One.pdf", szInput, 12)

        AppendPDF("Append.pdf", szInput, 2)

        're-compress image files to PDFs
        Recompress("BlackWhite", szBlackWhite)
        Recompress("Gray", szGray)
        Recompress("TrueColor", szTrueColor)

        Skewcorrect("Skewcorrect.pdf", szSkewcorrect)

        PageSize("PageSize.pdf", szTrueColor)

        PageLayout("PageLayout.pdf", szInput, 12)

        PageOrientation("PageOrientation", szMultiPage)

        Watermark("Watermark.pdf", szInput, 12)

        PDFsecurity("Security.pdf", szTrueColor)

        PDFInfo("Information.pdf", szTrueColor)

        Bookmark("Bookmark.pdf", szMultiPage)

        ViewerPreferences("ViewerPreferences.pdf", szTrueColor)

        TextAndGraphics("TextAndGraphics.pdf")

    End Sub
End Class
