Html to pdf by pdfcreator


When I try to generate a pdf from word document by below vbscript, it success and no need to select the printer. However, when I try to generate a pdf from a html file, the OS will always prompt for select the printer.

Is there any method such that the OS will not prompt for select the printer and generate from html file to pdf directly ?

Dim strExt, intStatus, strDestFileName, strInputFileName, strReason

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objShell = CreateObject(“Shell.Application”)
Set PDFCreatorQueue = CreateObject(“PDFCreator.JobQueue”)
Set PDFCreator = CreateObject(“PDFCreator.PDFCreatorObj”)

strInputFileName = “d:\test\abc.html”
strDestFileName = “d:\test\def.pdf”


’ ** Sub Routine to render file as PDF
Sub PDFProcess
Dim objFolder, job, intStatPDFCreator, intPageCount

intPageCount = 1  

Loggit "PDF Destination Name: " & strDestFileName 
Loggit "Initializing PDFCreator queue..."
intStatPDFCreator = PDFCreatorQueue.Initialize()
Loggit "PDFCreator Object Status: " & intStatPDFCreator 

If intStatPDFCreator = 0 Then 
		If Not objFSO.FileExists(strInputFileName) Then
			Loggit "PDFCreator: Can't find the file: " & strInputFileName
			Loggit "Printing Page: " & strInputFileName 
			PDFCreator.PrintFile strInputFileName
			WScript.Sleep 1000
			Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
		End If
	Loggit "Waiting for the job to arrive at the queue..."
	if Not(PDFCreatorQueue.WaitForJobs(intPageCount, 100)) Then 
		strReason = "The print job did not reach the queue within " & 10 & " seconds" 
		Loggit strReason 
		intStatus = 0
		Loggit "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue" 
		Loggit "Getting job instance and merging"
		while(PDFCreatorQueue.Count > 0)
			Set job = PDFCreatorQueue.NextJob
				Loggit "Staging PDF File: " & strDestFileName 
				WScript.sleep 5000
			If Not(job.IsFinished Or job.IsSuccessful) Then
				strReason = "Could not convert the file: " & strDestFileName
					Loggit strReason 
				intStatus = 0
				Loggit "Job finished successfully" 
			End If 
	End If 
		Loggit "Releasing the object"
	strReason =  "Failed to create PDFCreator COM instance."
		Loggit strReason 
	intStatus = 0
End If

End Sub

’ ** Sub Routine for Logging to Text File
Sub Loggit(msg)
Dim stream
Set stream = objFSO.OpenTextFile(“d:\Test\test.log” , 8, True)
stream.writeline Date & " " & Time & ": " & msg
WScript.Echo Date & " " & Time & ": " & msg
End Sub


this depends on which shell verbs are registered for the file type in your system. If there is only a “print” but no “print to” entry for html and temporarily switching the PDFCreator printer to default is set to “ask”, the dialog should get shown by the system. Try using the PrintFileSwitchingPrinters method instead. If this doesn’t help, an alternative solution might be using a different method to print the html file to the PDFCreator printer, e.g. by utilising a browser which allows command line printing to a specific printer.

Best regards,