Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

html to PDF using VBS

Guest
Aug 18, 2017 Aug 18, 2017

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

6.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Aug 25, 2017 Aug 25, 2017

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")
AcroApp.Hide

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" 'Ex

...
Translate
Guest
Aug 24, 2017 Aug 24, 2017

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")

objPDDocNew.Create()

Set objPDDoc = CreateObject("AcroExch.AVDoc")

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

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

objPDDoc.Close 0

AcroApp.Exit

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2017 Aug 25, 2017
LATEST

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")
AcroApp.Hide

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.

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

Set objPDDoc = Nothing
Set objAVDoc = Nothing

AcroApp.Exit
Set AcroApp = Nothing

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