Page 1 of 1

Print html files through bat files in xp?

Posted: 09 Jul 2011 06:54
by kumar_kondapalli
Hi Dos developers,

The below code is used to print HTML files from a batch file.

But the clause is it works only in NT, can any one modify so that it works in windows xp/windows7?

@ECHO OFF
SETLOCAL

:: Command line parsing
SET File2Print=%*
ECHO.%File2Print% | FIND "?" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
:: Strip leading space in NT 4 only
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 IF DEFINED File2Print SET File2Print=%File2Print:~1%
IF DEFINED File2Print SET File2Print=%File2Print:"=%
IF NOT DEFINED File2Print GOTO Syntax
IF NOT EXIST "%File2Print:"=%" GOTO Syntax

:: Actual print command
RUNDLL32.EXE MSHTML.DLL,PrintHTML "%File2Print%"

:: Done
GOTO End

:Syntax
ECHO.
ECHO PrintHTM.bat, Version 1.11 for Windows NT
ECHO Prints a local HTML file from the command line
ECHO.
ECHO http://www.google.com
ECHO.
ECHO Usage: %~n0 ^<html_file^>

:End
ENDLOCAL

Thanks,
San

Re: Print html files through bat files in xp?

Posted: 09 Jul 2011 07:40
by aGerman
kumar_kondapalli wrote:it works only in NT

No. It works fine on my Win7. Can't reproduce your problem.

Regards
aGerman

Re: Print html files through bat files in xp?

Posted: 09 Jul 2011 07:44
by kumar_kondapalli
UMMM but i tried in xp it does not and in my win7 as .. Can you please let me know if you have modified any code ?. Also can i get the print dailog box opened so that it gives me an option to select the printers from the drop down.






Thanks,
San

Re: Print html files through bat files in xp?

Posted: 09 Jul 2011 07:51
by aGerman
I didn't modify the code. I saved it as PrintHTM.bat. Because the help told me that it prints local HTML files I created a test.html with a basic source text:

Code: Select all

<html>
  <head>
    <title>Test</title>
  </head>
  <body>Hello World</body>
</html>

... and a callPrintHTM.bat:

Code: Select all

@echo off
call PrintHTM test.html


Regards
aGerman

Re: Print html files through bat files in xp?

Posted: 09 Jul 2011 21:14
by Acy Forsythe
Are you getting an error message when you run it in XP?

Re: Print html files through bat files in xp?

Posted: 10 Jul 2011 04:15
by aGerman
Latest only 1 line is necessary for html printing:

Code: Select all

rundll32 mshtml.dll,PrintHTML "test.html"

... where test.html is only an example, replace it with your html file.
I'm sure this will work in XP as well.

Regards
aGerman

Re: Print html files through bat files in xp?

Posted: 11 Jul 2011 01:14
by kumar_kondapalli
Hey thanks a lot guys .. It works perfectly in xp as well.

German code worked fine :-)