2 Replies Latest reply on Aug 25, 2017 4:39 AM by Billy_C_1955

    html to PDF using VBS

    Billy_C_1955 Level 1

      I need a .VBS example of how to read in an html file into Acrobat DC and then save the file as a PDF.

        • 1. Re: html to PDF using VBS
          Billy_C_1955 Level 1

          Here is the code I came up with but it does not automatically save the pdf file. And the file Junk.Pdf is really junk but without it sometimes I get an error the file is already open. When it closes it does prompt me to save the file to a path of my choosing. It works but it is not anywhere close to what I want. What I want is for it to save the pdf file with the same name as the html file without me having to do anything other than run the code. Saving the PDF file in the same path as the html file would be great.


          Dim AcroApp

          Set AcroApp = CreateObject("AcroExch.App")

          Set objPDDocNew = CreateObject("AcroExch.PDDoc")


          Set objPDDoc = CreateObject("AcroExch.AVDoc")

          objPDDoc.Open "C:\Temp\Do_Loop_Example.html", ""

          objPDDocNew.Save 1, "C:\Temp\Junk.pdf"

          objPDDoc.Close 0


          • 2. Re: html to PDF using VBS
            Billy_C_1955 Level 1

            Here is the code me and another guy came up with.  It works entirely in the background so you won't see an Acrobat icon while it is converting the html file into a pdf. I hope you like it.


            Option Explicit


            Dim AcroApp
            Dim objAVDoc
            Dim objPDDoc


            Set AcroApp = CreateObject("AcroExch.App")


            Set objAVDoc = CreateObject("AcroExch.AVDoc")
            'Input file path
            objAVDoc.Open "C:\Temp\Do_Loop_Example.html", ""


            Set objPDDoc = objAVDoc.GetPDDoc
            'Output file path
            objPDDoc.Save 1, "C:\Temp\Do_Loop_Example.pdf" 'Explicit save.


            objAVDoc.Close -1 'Close without saving -- an explicit save was already invoked.


            Set objPDDoc = Nothing
            Set objAVDoc = Nothing


            Set AcroApp = Nothing