Results 1 to 3 of 3

Thread: Save As PDF

  1. #1
    Join Date
    Oct 2013
    Posts
    20

    Unanswered: Save As PDF

    I have been working on this code to long and need some help. The code opens and stores fields into a pdf document. Works great just what I need. Except I need to save as and return path into field in access. Any help would keep hair on my head.

    Private Sub cmdPDF_Click()

    Dim acroApp As Object
    Dim acroDoc As Object
    Dim pdfDoc As Object
    Dim jso As Object
    Dim PDSaveIncremental As Variant
    Dim strFile As String

    'Fillable PDF filename and location
    strFile = CurrentProject.Path & "\" & "theDBguy.pdf"

    'Check for the PDF
    If Dir(strFile) = "" Then
    MsgBox "This demo requires the PDF form (theDBguy.pdf).", vbInformation, "Missing PDF"

    Else

    'Create Acrobat object
    Set acroApp = CreateObject("AcroExch.App")
    Set acroDoc = CreateObject("AcroExch.AVDoc")

    'Open PDF form
    If acroDoc.Open(strFile, "") Then
    Set pdfDoc = acroDoc.GetPDDoc()

    'Added by theDBguy
    '8/25/2013
    'Form fields
    Set jso = pdfDoc.getJSObject
    jso.getfield("fname").Value = Me.txtFName.Value
    jso.getfield("lname").Value = Me.txtLName.Value
    jso.getfield("notes").Value = Me.txtNotes.Value

    'Save changes to the PDF document
    pdfDoc.Save PDSaveIncremental, strFile

    'Close the PDF; the True parameter prevents the Save As dialog from showing
    acroDoc.Close (True)

    'View the PDF file
    ShellEx strFile

    End If

    Set acroApp = Nothing
    Set acroDoc = Nothing
    Set pdfDoc = Nothing

    End If

    End Sub

  2. #2
    Join Date
    Oct 2013
    Posts
    20
    Finally the answer was so easy. One line of code. I still have hair on my head.

    'Fillable PDF filename and location
    strFile = CurrentProject.Path & "\" & "theDBguy.pdf"

    'Check for the PDF
    If Dir(strFile) = "" Then
    MsgBox "This demo requires the PDF form (theDBguy.pdf).", vbInformation, "Missing PDF"

    Else

    'Create Acrobat object
    Set acroApp = CreateObject("AcroExch.App")
    Set acroDoc = CreateObject("AcroExch.AVDoc")

    'Open PDF form
    If acroDoc.Open(strFile, "") Then
    Set pdfDoc = acroDoc.GetPDDoc()

    'Added by theDBguy
    '8/25/2013
    'Form fields
    Set jso = pdfDoc.getJSObject
    jso.getfield("fname").Value = Me.txtFName.Value
    jso.getfield("lname").Value = Me.txtLName.Value
    jso.getfield("notes").Value = Me.txtNotes.Value

    'Save changes to the PDF document

    jso.app.execMenuItem "SaveAs"
    'Close the PDF; the True parameter prevents the Save As dialog from showing
    acroDoc.Close (True)

    'View the PDF file


    End If

  3. #3
    Join Date
    Oct 2013
    Posts
    20
    Here is what I have been working on for too long. What this does is execute the creation of a pdf form fill from within access filling fields from fields in access. Then saves the pdf as a predefined name from a field in access so I can view the pdf from a hyperlink within my access. Thanks DBGuy for the great start.


    Private Sub cmdPDF_Click()

    Dim acroApp As Object
    Dim acroDoc As Object
    Dim pdfDoc As Object
    Dim jso As Object
    Dim PDSaveIncremental As Variant
    Dim strFile As String
    Dim File_Name As String
    Dim strFile2 As String

    'Fillable PDF filename and location
    strFile = CurrentProject.path & "\" & "BuildingTemplate.pdf"
    strFile2 = CurrentProject.path & "\" & (Me.File_Name)

    'Check for the PDF
    If Dir(strFile) = "" Then
    MsgBox "This demo requires the PDF form BuldingTemplate.pdf.", vbInformation, "Missing PDF"

    Else

    'Create Acrobat object
    Set acroApp = CreateObject("AcroExch.App")
    Set acroDoc = CreateObject("AcroExch.AVDoc")

    'Open PDF form
    If acroDoc.Open(strFile, "") Then
    Set pdfDoc = acroDoc.GetPDDoc()

    'Added by theDBguy
    '8/25/2013
    'Form fields
    Set jso = pdfDoc.getJSObject
    jso.getfield("Location").Value = Me.Title.Value
    jso.getfield("Permit_Number").Value = Me.Permit_Number.Value

    'Save changes to the PDF document

    jso.SaveAs (strFile2)

    'Close the PDF; the True parameter prevents the Save As dialog from showing
    acroDoc.Close (False)

    'View the PDF file


    End If

    Set acroApp = Nothing
    Set acroDoc = Nothing
    Set pdfDoc = Nothing

    End If

    Kenneth J Alexander
    Municipal Works
    Sellersburg IN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •