Library tutorials & articles
Printing in VB
Printing Graphics
Outputting graphics to the printer is identical to outputting graphics to a
PictureBox. We will cover a few basic commands here, but first lets take a quick
look at the CurrentX and CurrentY properties. These
were used in the last example, and show where the current coordinates are. Visual
Basic automatically change these when it has finished the outputting. For example,
imagine you draw a line on a piece of paper - when you have finished drawing,
the pen is at the end of the line, not the start. This is the same with the
CurrentX and CurrentY properties. If you call the Line method, the line is drawn,
and then CurrentX and CurrentY are changed to point to the end of the line.
You can then change these if necessary to control where the next text or line
is printed.
|
Note
VB uses the same functions for drawing in picture boxes and outputting to the printer. If you don't want to have to visit the printer and waste paper whilst following this tutorial, simply create a new project, set the forms backcolor to white, autoredraw property to true, and remove change any Printer.Function
to Function. You will also need to comment out the Printer.EndDoc
lines. The data that was going to be printed on paper will now be 'printed'
to the form instead. |
Related articles
Related discussion
-
Key_Press() event for text box
by Aquila (1 replies)
-
Regarding Visual Basic Programme
by manjunathsl2007 (0 replies)
-
how do you hide all in VB6
by CapnJack (1 replies)
-
Problem with Input File
by novavb6 (3 replies)
-
How to produce a txt file with a table??
by novavb6 (1 replies)
How do i get vb.net to print. i've got it to make the printer work but it prints a blank page.
Thanks
Can you tell me how to set the margins and printer orientation also using this method. It should work in VB .NET 2003 I'm assuming.
I need to be able to control the printer margins and headers and footers and page orientation so that everything prints out the way I want.
Please advise me if you know a solution.
Thank you,
Baku
[Hi,
Facing problem in printing from local printer connected to WinXp from VB6. I am able to capture Printer.devicename and thru this print to network printer. But when trying to print on Local printer , No error appaers but "NO Document is printed". \
Can anyone help. Its very urgent ..PLsssssssss
VB
hi suhaas
have u added new paper...
now go to properties of your generic printer..
in printing preferences select default paper instead of letter select ur created custom paper...
now open vb6 and write code "msgbox printer.papersize"
this will give u paper no which windows has assigned...
so now when writing ur code..
instead of
printer.papersize=256
printer.width=your width
printer.height=your height
replace 256 with ur custom paper no...
and height and width will be automatically adjusted as per you custom paper created...
printer.papersize=your custome paper size no
like this u can solve it..
i hope things are clear
if more doubts feel free to ask
hi aadreja,
thanks for your reply.
I tried to do as per your reply. But this does not work with VB6. I am working on a invoice printing application where I am using Generic Text printer with VB6. Please help me if you have any solution.
Thanks in advance.
Regards,
Suhaas
for setting custom paper size in xp
u have to create form...
go to start->settings->printers
in file menu go to "server properties"
create new from with desired paper size... and give name
now u can see newly created paper while printing
email me
I Am facing problem with printer.print when i use in Win Xp. setting paper size have no effect when use it in xp but its working correctly in win 98
have seen this question in this forum but can't find the replies
hope you can help me, i am using vb6
thanks.
email me
I am attempting to print to a 'HP LazerJet 2420d' printer that has duplex capabilities but I can not get it to print the back side of the paper. I am coding in VB6 and I know the duplex on the printer works because another program that I did not write works fine. Any help? I've tried everything I can think of.
I've developed a compontent to make printing in VB easier.
Some common tasks as printing images, wrapped text, objects, etc. are coded on the component's methods.
Test it for yourself. Visit http://www.rc-dev.com
Thank you.... I understand it better now. I guess I didn't realize how many ways you can accomplish the same things in VB with different code. For instance, the code you use to connect and query a database is different than mine, but its more clear now that I see the whole thing. Thanks for the help!
I'm currently developing a DLL to make printing easy in VB. Next week I'll relese the Beta1 version of this module.
If you like to post some suggestions that you find usefull, email suggest@rc-dev.com .
Well, a recordset is a coolection of records (rows) of a db table.
So, when you open a recordset with a Sql query, it get's filled with the query results (or not filled at all if the query dosen't return any results.
But if it does get filled, you must move along the returnd rows to get their data.
example:
set rec=new adodb.recorset
set conn=new adodb.connection
conn.open "your connection string" 'do a google search ob ado connection strings if you don't know what this is.
'also check my site's code lib. I posted there a function to build connection strings easy.
rec.open "select * from myphonebook order by name,phonenr", Conn ' load query results into the recordset
do while not rec.eof 'loop through all the results
printer.print rec.fields("name") & vbTab & rec.fields("phonenr")
'print the name and phone nr. of the current row separated by a TAB
rec.movenext 'move to the next row on the recordset
loop
rec.close 'close the recordset
conn.close 'close the db connection
set rec=nothing 'destroy the object
set conn=nothing 'destroy the object
printer.enddoc 'start printing
hope it helps
Hi, I am also trying to print a table in VB.net, but I seem to have less experience than gianni because I'm having trouble understanding your directions. I have a few questions after reading your solution.
First, is the recordset the same thing as a dataset? Or, could I load the contents of the table into a dataset and print from the dataset? If I can't print from a dataset, do I load the information from the dataadapter into the recordset in the same way that I would put the information into a dataset?
Finally, I'm having trouble understanding the loop. Let me know if this is incorrect:
do while not rec.EOF <---- Lop until you reach the end of record set?
printer.print rec.fields("name") & vbTab & rec.fields("phone_nr") <---- I have no idea....
rec.Movenext <---- Does this increment some kind of index in the recordset that indicates the current
loop record?
Thank you for any help you can provide.
jglennie
Dear Sharaf / Forum Members,
I am also facing similiar problem with VB6. I am using Generic Text Printer in Windows 2000. I want to assign Custom paper size to the printer but it is not working. It works with Win98. Have you got the solution? If yes please forward me.
Thanking you in advance.
excellent thanks!
Yes. use Printer.PaintPicture method
to get more info on the Printer Object check these MSDN links:
http://msdn.microsoft.com/vbrun/greatesthits/default.aspx?pull=/library/en-us/dnexpvb/html/introducingprinterobject.asp
http://msdn.microsoft.com/vbrun/greatesthits/default.aspx?pull=/library/en-us/dnexpvb/html/chapter9printingwithvisualbasic.asp
can one add the functionality to print a logo easily when printing directly to the printer ?
I want to add a logo to till receipt slips (small thermal printer) and just wondering how it could be done
do while not rec.EOF
printer.print rec.fields("name") & vbTab & rec.fields("phone_nr")
rec.Movenext
loop
May i have the code to print the contents through the recordset? ( I already loaded the table into the recordset)
You cannot do it directly. You must load the table nito a recordset and then print the contents.
To position printing:
Printer.currentX=...
Printer.currentY=...
To print:
Printer.print "your data"
Can someone please tell me how can i print the contents of a database's table using the printer.print command?
Hello,
I just about to develop a window application to print to Printronix. I don't have the answer to you question but is hoping you can give me some insights. Where did you get the driver and documentation for Printronix Printer ? I am looking for both driver and documentation on how to utilize the DLL that comes with the driver. Please help.
Thanks
Print Preview:
webDoc.ExecWB OLECMDIDPRINTPREVIEW, OLECMDEXECOPTPROMPTUSER, Nothing, Null
Print:
webDoc.ExecWB OLECMDIDPRINT, OLECMDEXECOPTPROMPTUSER, Nothing, Null
You can use the following statement in vb to remove the headers and footers:
Print:
webBrowser.ExecWB OLECMDIDPRINT, OLECMDEXECOPTPROMPTUSER, Nothing, Null
Print Preview:
webBrowser.ExecWB OLECMDIDPRINTPREVIEW, OLECMDEXECOPTPROMPTUSER, Nothing, Null
Would like to know if u have any solution for that? Cos I am facing the same problem for winxp.
Am facing problem with printer.print when i use in Win Xp. setting paper size have no effect when use it in xp but its working correctly in win 98
I am beginner programmer, therefore I put in one problem that I discribe you following :-
I am working on one project named Bill Software in this software user need printing the form. Therefore I do progrmming that (form4.printform) but it display correctly on my printer "HP 4110" and when I make distribution CD of my project and setup my software on user computer then it work properly but its printing not became correct. My user have "Dot Matrix Printer".
Please tell me what I do?
I know that this problem is very small but I am beginner, so I face like that problem.
I also try to use MSDN help but I can't get my problem solution.
Summary :- I want to print the form on (InkJet Printer & also on Dot Matrix Printer) without using my user computer for programming. I know that I maintain that problem by using user computer for programming but Sir I have 10 order of my Bill Software. Please Help me immediately.
HI
I want to print the treeview in VB . so how can i print the it in treestructure all the nodes?
plz comment.
Regards
mahesh
The tutorial on printing is fantastic, but printing in VB seems a little archaic. Is there anyway to use the web browser control to print an html rendered document without the lovely header and footer and without asking the user to remove these? One way would be to alter the header and footer in the registry settings; however, this (as I know) will not work for sub-power users.
does someone know a way to render a word document over a specific DC?
I have problem with Print in Printronix Printer ( P5000 Series ),
i can't print more than 2 pages its containing both barcode picture and text.
I already use printer method like newpage, enddoc
and i also use Win API Print method just like startpage,endpage,startdoc, enddoc.
I also try using different printer driver like epson fx1050, printronix P5000 Series,
But Still i haven't found solution to My problem.
Is there anybody in this forum who cant help me ???
Thanx.
btw, if you're using an IE browser, see if this will batch print *.docs, & *.xls. since they can open directly in IE. Would be neat if it did - let me know.
I guess I could, but I don't think it's really of any value...I just did it b/c I had to print about 30 htm files and I didn't want do the file...print crap each time. I started working on a simple html rendering engine so that I don't have to use MS' print function ( it forces the dialogue box- but still easier than mousing through everything), but never completed it.
'**********
'After IE 4.0, the web browser object doesn't allow the bypassing of the print dialogue.
'Have to use webBrowser control until html engine can be rendered because VB Printer object prints html source not rendered.
Private Sub List1OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, _
Shift As Integer, x As Single, y As Single)
Dim i As Long
Dim a As Integer
Dim s As Integer
Dim URL As String
For i = 1 To Data.Files.Count
s = List1.ListCount
List1.AddItem Data.Files(i)
Next i
End Sub
Private Sub CmdPrintClick()
Dim doc As Object
Dim win As Object
Do While List1.ListCount <> 0
URL = List1.List(s)
WebBrowser1.navigate (URL)
MsgBox ("Ready to Print") ' Needs timer here to wait about 2 seconds for url to load before print.
Set doc = WebBrowser1.document
Set win = doc.parentWindow
win.execScript "window.print();", "JScript"
MsgBox ("Press this after you OK print dialogue")
' Need timer control (MsgBox) to pause next event because of printer dialogue loses page.
List1.RemoveItem (s)
Loop
List1.Clear
End Sub
Private Sub FrmMain_Load()
Dim objPrinter As Printer
' Not grabbing device name for some reason, but I didn't really debug it yet.
'Set objPrinter = GetDefaultPrinter()
'Label2.Caption = objPrinter.DeviceName
'Set objPrinter = Nothing
'End
List1.Clear
List1.OLEDropMode = vbOLEDropManual
End Sub
Hey Warren,
How long is the code? Could you just post it directly in this forum?
Thanks.
Instead of using a JavaScript.print function to print a web page, is there any code I can use in ASP that I can print a doc within a web.(THE URL usually print at the bottom which I don't know how to get rid of it?)
Please send the "Print code" to citiloan88@yahoo.com and I appreicate your help....
Thanks
" yeah, I made an app to batch print html documents. The problem I ran into after it was done, is that html needs to be rendered. My app could only print the source , just as if it were an rtf,txt, or doc file. I took the lazy way out and used MS' component for it; which will prompt the print dialog cause MS see's printing as a security risk. There is no legit way using the component to bypass the dialog box. I was going to try mimicking the ok, so the user doesn't have to sit there, but got too lazy. If you want the prog, I'll send you the code. "
Can anyone please e-mail this PRINT application to me at citiloan88@yahoo.com
Thanks
I am having problem with printing out a document that with paper size (Width:9.5 inch,Height:6 inch). I use "Printer.Print" to print out every line of the document. But I can't stop the printing when finish printing all the line..the paper scrol till to second page and stop at the half page of the second page. How should I control the paper setting by using VB code?
reply to my email so I know where to send it, or post it, whichever you prefer.
Thanks that will be very helpful to me if you send me the source code.
Thanks,
Nutan
yeah, I made an app to batch print html documents. The problem I ran into after it was done, is that html needs to be rendered. My app could only print the source , just as if it were an rtf,txt, or doc file. I took the lazy way out and used MS' component for it; which will prompt the print dialog cause MS see's printing as a security risk. There is no legit way using the component to bypass the dialog box. I was going to try mimicking the ok, so the user doesn't have to sit there, but got too lazy. If you want the prog, I'll send you the code.
Thank u
also I hd got a API func for that
It prints like printing via dos
AnyWay thnks for your reply
Does anyone has solution for this problem, I am also looking out for the same.
Speed is slow in case of Printer.Print on DMP
Use
OPEN "LPT1" For Output as #1
Print #1, "JainaSoft Technologies"
Print #1, "For Complete Software and INTERNET Solution"
....
close #1
it will give u the good speed on DMP
what's ur Solution?
PLease give me ya.
I need that
Stor the printer name in strPrinterName.
Dim printerObj As printer
For Each printerObj In Printers
If UCase(printerObj.DeviceName) = UCase(strPrinterName) Then
Set printer = printerObj
' do stuff here
Set printerObj = Nothing
Exit For
End If
Next
// johannes
Thanks,
I Have got the solution, there was some mistake in my code so ..., Not using apropriate driver is also the reason of it. So install the original driver always.
Regards
Gyanendra
How to speed up the [3].[/3] matrix printer while printing in vb as dos oriented printing
Does this help? Use a the WebBroswer control
In a VB app add the WebBroswer component (MS Internet Controls) WebBrowser1
To print:
1) open the file
WebBrowser1.Navigate "yourfile.html" or "yourfile.txt" or "http://www.somesite.com"
2) call the print command
WebBrowser1.ExecWB OLECMDIDPRINT, OLECMDEXECOPTDONTPROMPTUSER
My problem is I dont want the page1 that's in the upper right hand corder and the URL at the bottom of the page, as happens whenever you print from a browser. If you figure how to get rid of this, please let me know.
hello, hope my solution will help you.
do not put printer.enddoc
this will end the document if youre printing in printers such as the inkjets and laserjets,
you can change the properties of this printer by:
printer.orientation
printer.paperbin
by this your printer settings will be change, it is important to understand 1st your printers capabilities
and features. ;)
hello
please try to fix the coordinates of the printer by coding it, you can set its current x and y coordinates. Most new printers have drivers to support and automatic reconfigures the coordinates. Try also to code the papertype, paperbin.
Hope this will help you!
Good luck
I have this exact problem. If anyone has the solution could you please e-mail it to me.
macbro2@hotmail.com
Hi,
I am creating a macro in MS Word to do mailmerge and printing automation. After mailmerged, the merged document should be send to the printer. In the process of sending to printer, I like the users be able to select of what printer they want the document to be printed. Please help me on the syntax of printer options. Thanks.
I have a problem regarding printing in VB. When I use Printer.Print method followed by Printer.Enddoc method to print a line of text, the paper gets ejected after printing that line. The paper should not get ejected after printing a line and printer should wait for next line of text.
How to solve this problem?Can enyone help me?
Did anybody get any solution for this problem> Please let me know I desperatelly want to implement this.
I want to print a RTF file which will be around 10K and i want to send the entire file directly to the printer.
Select a file and send it to printer thru' VB Code.
I would aappreciate if you could help me in this matter.
myEmailID g_mandar@hotmail.com
Thanks,
Mandar
Hi
i have the same problem.
please if u solved the problem contact me.
my email is:leon@galor.com
best regards!
Leon
Hi all,
I'm having a trouble figuring out how to pass entire documents directly from my app to the printer (i.e., without opening up Word or IE Explorer). I have a list of rtf and html docs that I would like to print automatically, without forcing the user to open each document in a different app and print from there. When the user presses "Print" I would like the ability to take each of the pathnames that I have stored and send them to the printer in succession so that it gives the feeling of seamless printing of the entire list of documents. Does anyone know how I could accomplish such a task? (hopefully something similar to "printer.Paintpicture(loadpicture("name"), Top, Left, Width Height" for images???). HTML and RTF are the major doc types that I need to be able to print this way. Any help would be GREATLY appreciated!
the site link: http://easyprint.vip.myrice.com
Please tell me how can we print on Dot Matrix Printer using this code "Printer.Print", as i used it but i am not getting proper printout on Dot Matrix Printer while on Ink Jet Printer printout is proper. On Dot Matrix Printer it prints 10-12 characters of each line, it does not print complete line. So please if any one can solve it, please let me know.
Thanks & Regards
I've find out a great site for VB source code! Thanks a lot!
Is this possible? I can find no method using help or internet forums, but can't help feeling someone must know how.
Thanks,
Mick
This post helped me get thru a whole bunch of __... MSDN Library help did not have the quirk you pointed out. Please accept my sincere thanks. Alan.
I am just know learning vb, and I'm trying to figure out how to print from it. Is there any way I can create a macro that upon clicking it, it displays a report with the contents of several variables in another macro?
Please if anybodycan help me, would you email me at soy_chicalatina@yahoo.com
Thanks a lot!
Mileidy
This thread is for discussions of Printing in VB.