Automatically select default printer paper

PAffiliates

Member
Joined
Aug 15, 2007
Messages
10
Programming Experience
Beginner
I wish I didn't have so many questions, and hopefully one day will be able to answer the questions of others.

I have looked everywhere, but I cannot figure out how to automatically change the paper size for the printer itself to 8.5x14. I have set the page size to 8.5x14, and when the print preview is viewed, the page reflects these changes. I need to change this setting because the user of the printer needs it by default to be set to 8.5x11 for normal printing. The only time it needs to be 8.5x14 is when he uses this program. Is there any way to do this? I have looked into the PrinterSettings.PageSize, but all I can figure out how to do is to populate a combo box with the available page sizes. Any help would be very appreciated. Thank you all for your time and effort.
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Here Is Some Code Used To Print Crystal Reports

VB.NET:
            myRpt.PrintOptions.PrinterName = "\\COMPUTERNAME\PRINTER NAME"
            myRpt.PrintOptions.PaperOrientation = CrystalDecisions.[Shared].PaperOrientation.Portrait
            myRpt.PrintOptions.PaperSize = CrystalDecisions.[Shared].PaperSize.PaperLegal
            myRpt.PrintToPrinter(1, True, 1, 99)

8 1/2 x 14 IS "legal" SIZE

HOPE THAT HELPS
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
The PrinterSettings.PaperSizes Property help page have a code sample that does just that (the custom part). If those measures is some kind of standard you should be able to set it by name. (ie create new PaperSize, set its PaperName, then set this as the PaperSize for DefaultPageSettings of PrintDocument.)

Edit: I just tried the above suggestion in code and it didn't work, just iterate the PaperSizes and check the PaperName, if it's the one you want set this in DefaultPageSettings.
 

PAffiliates

Member
Joined
Aug 15, 2007
Messages
10
Programming Experience
Beginner
I also tried that code sample, and got the same results you did. I have the defaultpagesettings set to 850x1400 and the print preview looks fine, but the printer still cuts off at 8.5x11. Like I said, I can't find a place that can tell me how to do it. I keep seeing that in VB 6 you could make an API call, but they say that that feature isn't available in vb.net or something like that. Thank you both for your help.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
Both custom sizes and selecting one of the supported predefined papersizes of the printer works fine when I test print, maybe your printer doesn't support that paper size? Here's a method to set a predefined size using the iterate method, for example a common PaperName "A6":
VB.NET:
Sub setPaperSize(ByVal pd As Printing.PrintDocument, ByVal name As String)
    For Each ps As Printing.PaperSize In pd.PrinterSettings.PaperSizes
        If ps.PaperName.ToLower = name.ToLower Then
            pd.DefaultPageSettings.PaperSize = ps
            Exit Sub
        End If
    Next
End Sub
for example called before print:
VB.NET:
setPaperSize(PrintDocument1, "A6")
You should look into what papers your printer returns in PrinterSettings.PaperSizes, investigate PaperName, Kind and metrics of each.
 

PAffiliates

Member
Joined
Aug 15, 2007
Messages
10
Programming Experience
Beginner
John,

I tried the code you gave me, but it didn't work for me the way it probably should. This could be due to my own errors in using it. Through much searching, I did find a For Next Loop that did do the job...

VB.NET:
For i As Int16 = 0 To CShort(PrintDocument.PrinterSettings.PaperSizes.Count - 1)
            If PrintDocument.PrinterSettings.PaperSizes(i).Kind = PaperKind.Legal Then
                PrintDocument.DefaultPageSettings.PaperSize = PrintDocument.PrinterSettings.PaperSizes(i)
                Exit For
            End If
        Next

Thank you again for all of your help!
 

dlw@pickpro.com

New member
Joined
May 13, 2008
Messages
3
Location
St. Louis area
Programming Experience
10+
i have a related need. To change the paper size of the printer / spooler queue via a console application.
I have a telnet based application that will "shell out" to run the console application, setting the paper size on the printer.
At that time, the telnet application generates the report. We are using printer forms to prevent other telnet sessions printing on special forms.
I do not want to create a new form, but select from the predefined forms.

The 'solutions' I've found to date suggest looping through available paper sizes/kind and then call the SetForm API (within winSpool.drv) to set that size.
However, every call to EnumForms API return ZERO items and ZERO bytes needed.

Any help is appreciated.
 
Last edited:
Top Bottom