Highlighted

Add barcode to PDF document using VBA

New Here ,
Jun 27, 2020

Copy link to clipboard

Copied

Hi All,

 

I need to add a Barcode to pdf file using VBA in MS Word.

I have written below code but it doen't work. It shows "Barcode render error"

 

Private Function AddBarcode() As String
    Dim oAVDoc As New Acrobat.AcroAVDoc, oPDFDoc As Acrobat.AcroPDDoc
    Dim oAcro As New Acrobat.AcroApp
    Dim oJSO As Object
    Dim pdfPath as String
    Dim x as Double, y as Double
    Dim oAdd1 As Object
    
    pdfPath = ThisDocument.Path & "\Sample Form.pdf"
    If oAVDoc.Open(pdfPath, "") = True Then
        'Set the PDDoc object.
        Set oPDFDoc = oAVDoc.GetPDDoc

        'Set the JS Object - Java Script Object.
        Set oJSO = oPDFDoc.GetJSObject

        oJSO.GetField("FirstName").value = "Tejas"
        oJSO.GetField("LastName").value = "Tanna"
    
        y = 200
        x = 600
        
        Set oAdd1 = oJSO.AddField("Barcode", "barcode", oPDFDoc.GetNumPages - 1, Array(y, x, y + 195, x - 32))

        Dim outputPath$
        outputPath = ThisDocument.Path & "\Output_With_Barcode.pdf"
        
        oPDFDoc.Save 1, outputPath

        'Close the Acrobat application.
        oAVDoc.Close True
        oAcro.Exit

        'Release the objects.
        Set oJSO = Nothing
        Set oPDFDoc = Nothing
        Set oAVDoc = Nothing
        Set oAcro = Nothing
    End If
End Function

image.png

Topics

PDF forms

Views

44

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Add barcode to PDF document using VBA

New Here ,
Jun 27, 2020

Copy link to clipboard

Copied

Hi All,

 

I need to add a Barcode to pdf file using VBA in MS Word.

I have written below code but it doen't work. It shows "Barcode render error"

 

Private Function AddBarcode() As String
    Dim oAVDoc As New Acrobat.AcroAVDoc, oPDFDoc As Acrobat.AcroPDDoc
    Dim oAcro As New Acrobat.AcroApp
    Dim oJSO As Object
    Dim pdfPath as String
    Dim x as Double, y as Double
    Dim oAdd1 As Object
    
    pdfPath = ThisDocument.Path & "\Sample Form.pdf"
    If oAVDoc.Open(pdfPath, "") = True Then
        'Set the PDDoc object.
        Set oPDFDoc = oAVDoc.GetPDDoc

        'Set the JS Object - Java Script Object.
        Set oJSO = oPDFDoc.GetJSObject

        oJSO.GetField("FirstName").value = "Tejas"
        oJSO.GetField("LastName").value = "Tanna"
    
        y = 200
        x = 600
        
        Set oAdd1 = oJSO.AddField("Barcode", "barcode", oPDFDoc.GetNumPages - 1, Array(y, x, y + 195, x - 32))

        Dim outputPath$
        outputPath = ThisDocument.Path & "\Output_With_Barcode.pdf"
        
        oPDFDoc.Save 1, outputPath

        'Close the Acrobat application.
        oAVDoc.Close True
        oAcro.Exit

        'Release the objects.
        Set oJSO = Nothing
        Set oPDFDoc = Nothing
        Set oAVDoc = Nothing
        Set oAcro = Nothing
    End If
End Function

image.png

Topics

PDF forms

Views

45

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Have something to add?

Join the conversation
Resources
One Stop Solution for Acrobat
Edit a PDF