Print html files through bat files in xp?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kumar_kondapalli
Posts: 32
Joined: 08 Jul 2011 03:38

Print html files through bat files in xp?

#1 Post by kumar_kondapalli » 09 Jul 2011 06:54

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Print html files through bat files in xp?

#2 Post by aGerman » 09 Jul 2011 07:40

kumar_kondapalli wrote:it works only in NT

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

Regards
aGerman

kumar_kondapalli
Posts: 32
Joined: 08 Jul 2011 03:38

Re: Print html files through bat files in xp?

#3 Post by kumar_kondapalli » 09 Jul 2011 07:44

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Print html files through bat files in xp?

#4 Post by aGerman » 09 Jul 2011 07:51

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

Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

Re: Print html files through bat files in xp?

#5 Post by Acy Forsythe » 09 Jul 2011 21:14

Are you getting an error message when you run it in XP?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Print html files through bat files in xp?

#6 Post by aGerman » 10 Jul 2011 04:15

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

kumar_kondapalli
Posts: 32
Joined: 08 Jul 2011 03:38

Re: Print html files through bat files in xp?

#7 Post by kumar_kondapalli » 11 Jul 2011 01:14

Hey thanks a lot guys .. It works perfectly in xp as well.

German code worked fine :-)

Post Reply