Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 20th, 2009, 02:54 AM
Registered User
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Thumbs up printing in custom paper size in visual basic


A few days ago I face the frustrating situation of trying to print from a VB 6 application running under Windows XP to a dot-matrix printer using a preprinted, continuos form with a custom size of 8.5 x 5.5 inches.

I spent a lot of time searching on the internet for a code, a component or a tip to solve the problem as I personally don't enjoy spending hours programming.

THe thing is that I read a lot of information about using printer.height, printer.width, printer.papersize, installing new drivers, etc until I deleted the printer.heigh and printer.width commands from my code and everything runned as expected, i didn't use the printer.papersize either, but the printer stopped exactly at the 5.5 inches and no paper was ejected no mattering I ended my code using printer.enddoc command.

What I did :

1. I created a custom paper size at Start/printers&faxes and in the main menu File/server properties, I clicked on "create new form", gave a name and typed the width and height of my custom page size, then clicked "save form" and close the window.

2. On the printers & faxes window, Right click over your printer and select printing preferences and in the dialog you will see a button called "Advance options" click on it, this will show the advance properties of your printer.

You will see a field called "Paper Size" and a combo box in which you will have to select your customized page size. Once selected click "Ok" and close everything.

I tested changing the paper size inside my printer properties, but was enough selecting my new paper size in the Advance options.

3. In my code, I was using the printer.height=7920 and printer.width=12240, I never used the printer.papersize as I read that when assigning printer.height and printer.width, printer.papersize was set to user defined by default, so no need to include it.

I just commented the printer.height=7920 and the printer.width=12240 commands to give it a try and included a msgbox printer.height just before the printer.enddoc to see if before printing the height was 7920 (5.5 inches x 1440 = 7920) as I needed and so it was, the height was taken from my custom paper size and the printer.enddoc command printed everything correctly and ejected just the paper needed to set the next form right in place.

I noticed that when leaving the printer.height and printer.width commands, this values were not used, the advanced properties pagesize i selected was not applied, and a "letter" paper size height was used as default, but when I commented these commands, the height used was the one i determined in my custom paper size.

A very simple code i used:

Function PrintCompact()

Printer.PrintQuality = vbPRPQDraft 


Printer.FontSize = 8
Printer.CurrentX = 7537 
Printer.CurrentY = 5268 
Printer.Print "Hello"

Printer.CurrentX = 5670 
Printer.CurrentY = 1417 
Printer.Print "Hello again"

Printer.FontSize = 10
Printer.CurrentX = 0 
Printer.CurrentY = 500 
Printer.Print "Hola"

Printer.FontSize = 8
Printer.CurrentX = 7537
Printer.CurrentY = 500 
Printer.Print "Bye"

'msgbox printer.height


End Function

I hope you find useful this experience I had and saves you some time and frustration.

All the best
The Following User Says Thank You to Babet For This Useful Post:
ArunKakkar (May 26th, 2010)
Old April 30th, 2010, 03:15 AM
Registered User
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up printing in custom paper size in visual basic

thanks a lot.I followed your steps and it worked.I had searched a lot in net of this ,even trying lot of codes it always gave the size of 'letter'.
Old May 26th, 2010, 01:48 AM
Registered User
Join Date: May 2010
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Smile Thanks a Lot, I am struggling since many days to short out this problem

Thanks a Lot, I am struggling since many days to short out this problem
I request you to post your this article at many other places if possible or allow me to post it on my blog http://ArunKakkar1.blogspot.com

Once Again Thanks a lot
Old November 29th, 2013, 03:06 AM
Registered User
Join Date: Nov 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I have tried what you said. I cannot find the 'paper size' combobox in advanced properties. I tried printing preferences, there is a paper size combobox but, i cannot find the form size i just created. There's only a4,a5 etc. How can I include the newly created size??

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Paper Size (custom also) to default Printer gaurikhot .NET Framework 2.0 2 December 6th, 2008 01:50 AM
printing in custom paper size in visual basic imagetvr Pro VB 6 2 May 3rd, 2008 08:58 PM
Problem with custom paper size adrineh Crystal Reports 0 August 26th, 2006 03:21 AM
Printing problem using dot-matrix paper size ismail_m HTML Code Clinic 1 January 1st, 2006 09:51 AM
Printing problem in Visual Basic ! Urgent venkatesh_anmca Beginning VB 6 2 January 29th, 2005 02:22 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.