Board index » Visual Studio » Print graphic to printer via VBS

Print graphic to printer via VBS

Visual Studio16
Hello all,



I'm using the following code to print text to a network printer:



Set ofs = WScript.CreateObject("Scripting.FileSystemObject")

Set oPrinter = ofs.OpenTextFile("\\printsvr\itptr", 2)

oPrinter.WriteLine "This is a test file"

oPrinter.WriteLine "This is a second line"

oPrinter.Write Chr(12)



But I need to know if there's someway to add a line in here that'll

print a graphic as well. I'd like to create a graphic heading to print

on the top of each page printed, but going the route above I've only

been able to print text.



Thanks,



Alex


-
 

Re:Print graphic to printer via VBS

hi Alex,



This is probably not the answer you wanted, but if I was

doing this, I would use ms Word.



msWord has an automation interface, and there are several

examples of how to use it posted in these scripting ng's.

Search the archives for "word.application".



You can turn on the word recorder and go through the motions

of inserting your graphic and text into the document, and then

printing your document. When done, turn off the recorder

and examine the macro you created.



The macro will be in vba (Visual Basic for Applications), but

it will be easy enough to convert it to vbScript.



Note that if you are using the same graphic every time, it

may be worth your while to set up a word template with the

graphic already included. Some businesses which can't

afford pre-printed stationery will do that to include their

corporate logo as a letter-head.



cheers, jw

____________________________________________________________



You got questions? WE GOT ANSWERS!!! ..(but,

no guarantee the answers will be applicable to the questions)



Alex wrote:

Quote
Hello all,



I'm using the following code to print text to a network printer:



Set ofs = WScript.CreateObject("Scripting.FileSystemObject")

Set oPrinter = ofs.OpenTextFile("\\printsvr\itptr", 2)

oPrinter.WriteLine "This is a test file"

oPrinter.WriteLine "This is a second line"

oPrinter.Write Chr(12)



But I need to know if there's someway to add a line in here that'll

print a graphic as well. I'd like to create a graphic heading to print

on the top of each page printed, but going the route above I've only

been able to print text.



Thanks,



Alex



-

Re:Print graphic to printer via VBS



mr_unreliable wrote:

Quote
hi Alex,



This is probably not the answer you wanted, but if I was

doing this, I would use ms Word.



msWord has an automation interface, and there are several

examples of how to use it posted in these scripting ng's.

Search the archives for "word.application".



You can turn on the word recorder and go through the motions

of inserting your graphic and text into the document, and then

printing your document. When done, turn off the recorder

and examine the macro you created.



The macro will be in vba (Visual Basic for Applications), but

it will be easy enough to convert it to vbScript.



Note that if you are using the same graphic every time, it

may be worth your while to set up a word template with the

graphic already included. Some businesses which can't

afford pre-printed stationery will do that to include their

corporate logo as a letter-head.



cheers, jw

_________





Hi JW,



Actually I didn't want to go into too much details on my project, but

MS Word isn't an option for our application.



Basically we have a website where folks fill out a form, and depending

on what department they select that form will be printed on a printer

within the department. I have this process working, but they want to

use a graphic on the heading instead of just text.



The VBS script I'm writing will reside on one of our Win 2K3 servers

which doesn't have MS Word or any applications other then MS SQL

Server. The script simply hits the MS SQL database, queries for new

records, and prints according to department selected by user. It works

pretty good, just wanted to see if I could get a graphic added to it.



Take care,



Alex



-

Re:Print graphic to printer via VBS

Alex wrote:

Quote
mr_unreliable wrote:

>hi Alex,

>

>This is probably not the answer you wanted, but if I was

>doing this, I would use ms Word.

>

>msWord has an automation interface, and there are several

>examples of how to use it posted in these scripting ng's.

>Search the archives for "word.application".

>

>You can turn on the word recorder and go through the motions

>of inserting your graphic and text into the document, and then

>printing your document. When done, turn off the recorder

>and examine the macro you created.

>

>The macro will be in vba (Visual Basic for Applications), but

>it will be easy enough to convert it to vbScript.

>

>Note that if you are using the same graphic every time, it

>may be worth your while to set up a word template with the

>graphic already included. Some businesses which can't

>afford pre-printed stationery will do that to include their

>corporate logo as a letter-head.

>

>cheers, jw

>_________





Hi JW,



Actually I didn't want to go into too much details on my project, but

MS Word isn't an option for our application.



Basically we have a website where folks fill out a form, and depending

on what department they select that form will be printed on a printer

within the department. I have this process working, but they want to

use a graphic on the heading instead of just text.



The VBS script I'm writing will reside on one of our Win 2K3 servers

which doesn't have MS Word or any applications other then MS SQL

Server. The script simply hits the MS SQL database, queries for new

records, and prints according to department selected by user. It works

pretty good, just wanted to see if I could get a graphic added to it.



Take care,



Alex



It might be possible to use graphics magic to do this (freeware).

Google for it and you will find it can do loads of stuff and has a com

interface. If you try and manage, please let us know!





AJ



--

www.deployview.com

www.nerds-central.com

www.project-network.com

-