Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML to PDF .... Ideas Please !!

Status
Not open for further replies.

ToddWW

Programmer
Mar 25, 2001
1,073
US
I am currently using the following code to convert an HTML document to PDF.
Code:
theFile = "myhtml.html"
pdfFile = "myhtml.pdf"

objWord = CreateObject("Word.Application")
objWord.DisplayAlerts = .F.  
objWord.Visible = .F.
objWord.Documents.Open(theFile)
objWord.ActiveDocument.PrintOut(0,0,0,pdfFile)
objWord.Quit
objWord = .null.
I am using a 3rd party PDF printer driver that is set as the default printer. The code above works great as it completes the entire process behind the scenes. However it requires that I have MS Word installed on the machine. Since all I am in need of is converting HTML, I am looking for a way to do this without using MS Word. I can automate InternetExplorer in a similar fashion but I am not aware of a method to print using the InternetExplorer object. Isn't there an easier way to simply convert an HTML document to PDF using FoxPro code ?

Any ideas would be greatly appreciated.

Todd
 
I found a fairly simple way to do this using the code below. Most of this was taken from faq184-3503 which shows how to automate IE's Print Preview. The FAQ is worth looking at as it exposes all of the execWB constants, options, etc..

I just tweaked it a little to automate Printing for my unique need. I have stumbled upon one final problem with this and I opened that post up in VFP - Automation, Mail & 3rd Party Svcs thread1251-963292

Nonetheless, here is a pretty clean example of automating IE to print in VFP.
Code:
oBrowser=CREATEOBJECT("InternetExplorer.Application")
oBrowser.Visible = .T.

theTarget="[URL unfurl="true"]www.tek-tips.com"[/URL]
oBrowser.Navigate(theTarget)
DO WHILE oBrowser.ReadyState != 4
	&& WAIT FOR DOWNLOAD
ENDDO 
DO WHILE oBrowser.queryStatusWB(6) != 3
	&& WAIT UNTIL READY TO PRINT
ENDDO
oBrowser.ExecWB(6,2) && PRINT WITH NO PROMPT
oBrowser.Quit
I'm currently having problems with VFP quitting IE before the printing is done sending the doc to the printer driver which I am currently looking for a solution. If you have any ideas there, please see thread1251-963292

Thanks

ToddWW
 
I found another option.

is a great tool that does not require a PDF printer driver and can be used with any software that supports ActiveX. I use it now in both Active Server Pages as well as VFP 7.0 and I love it. And it's thread safe so it won't crash under IIS.

ToddWW
 
Automatic MS Office to PDF Module faq184-4349

Can be easily updated to use IE to print HTM/HTML to PS.

Brian
 
Here's a snip from my app.

Brian

Code:
DECLARE INTEGER FindWindow IN user32; 
    STRING lpClassName,; 
    STRING lpWindowName 
*
*
* snip
*
*
*
WAIT WINDOW NOWAIT "Please Standby. Converting "+PSFile
WshShell = CreateObject("WScript.Shell")
loWeb = CreateObject("InternetExplorer.Application")
	 WITH loWeb 
	 .Height = -1
     .Visible = .t.
     .Navigate(FULLPATH(InFile))

     WaitonIE()
     
     WshShell.AppActivate("Internet Explorer 6")
	 .ExecWB(6, 2, 0, 0)
	
	 lnStart=SECONDS()
	 lnCompleteWindow=0

	  DO WHILE lnCompleteWindow=0 and SECONDS()-lnStart<120 &&2 min timeout
	    lnCompleteWindow= FindWindow(0, "Print to File")
	  ENDDO
	
	 WshShell.AppActivate("Print to File")
	 WshShell.SendKeys ["%f%l&PSFile{ENTER}"]
	 .Quit 
     ENDWITH
loWeb=.null.
WshShell=.null.
WAIT clear 
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top