Library tutorials & articles
Printing in VB
By James Crowley, published on 14 Jul 2001
Printer Options
Aside from graphics, there is also a number of properties that directly affect printing. I'll cover these here.
| Copies | The number of copies of your output that will be printed |
| DeviceName | The name of the printer device. |
| DriverName | The name of the driver for the printer |
| Duplex | Whether the printer is in Duplex mode or not (printing on both sides). |
| hDC | A handle to the printers device context |
| Orientation | The orientation of the paper. This can be vbPRORLandscape or vbPRORPortrait. |
| Page | Returns the current page number (read-only) |
| PaperBin | The paper bin to use when printing the document. The values for this property can be found by hitting F2 (Object Browser), selecting PrinterObjectConstants from the Classes list, and taking a look at all the constants beginning with vbPRBN |
| PaperSize | The size of the paper that is being printed on. See PrinterObjectConstants in the Object Browser, beginning with vbPRPS |
| Port | The name of the printer port (read-only) |
| PrintQuality | The quality of printing (printer resolution). See PrinterObjectConstants, beginning with vbPRPQ |
| TrackDefault | Whether to automatically move to the default printer if this is changed in Control Panel |
| Zoom | The percentage with which the output is scaled up or down. (Note that this only works on printers that support it!) |
And that's about it! Many of you may now be thinking about PrintPreview... a RichTextBox PrintPreview control will be coming soon to VB Web!
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
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
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
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
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
webDoc.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, Nothing, Null
Print:
webDoc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, Nothing, Null
Print:
webBrowser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, Nothing, Null
Print Preview:
webBrowser.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, 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.
'******************************
'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 List1_OLEDragDrop(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 CmdPrint_Click()
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
How long is the code? Could you just post it directly in this forum?
Thanks.
Please send the "Print code" to citiloan88@yahoo.com and I appreicate your help....
Thanks
Can anyone please e-mail this PRINT application to me at citiloan88@yahoo.com
Thanks
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
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
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 OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
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. ;)
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
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
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.