vbscript >> How to set Paper size in vbs

by U3ViYnU » Wed, 12 Aug 2009 15:03:01 GMT

Hi all,
could anyone suggest a way to set the paper size in default printer in vbs.
This is not for MSoffice printing, but a 3rd party ECAD software, which
supports vbs.


I have used WMInterface to do this, but it is not setting the paper
size.(below is the code)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_PrinterConfiguration",,48)
For Each objItem in colItems
Wscript.Echo "PaperSize: " & objItem.PaperSize
objItem.PaperSize = 8
Wscript.Echo "PaperSize: " & objItem.PaperSize
Next

It is outputting paper size as 8(A3) but, it does not printout in A3.

Can anyone suggest the correct way of setting the papersize or printer
properties?

thanks





vbscript >> How to set Paper size in vbs

by Alex K. Angelopoulos » Wed, 12 Aug 2009 15:55:53 GMT


nfortunately, that technique won't work. The Win32_PrinterConfiguration
properties are read-only. You can set the PaperSize value because you're not
dealing with the PrinterConfiguration itself, but with a cached value
collection.

For WMI classes which _do_ have writable properties, you can use WMI's
Put_() method to write a modified instance back to the repository. Of
course, in this example, it will fail. If you do this:

For Each objItem in colItems
Wscript.Echo "PaperSize: " & objItem.PaperSize
objItem.PaperSize = 8
objItem.Put_()
Wscript.Echo "PaperSize: " & objItem.PaperSize
Next

The Put_ call will throw the error "SWbemObjectEx: Provider is not capable
of the attempted operation".

================
Approaches to setting the paper size

This is a problem that people have asked about repeatedly over the years,
and there's never been a simple out-of-box solution. I'm not totally aware
of the reasons, but I suspect its due to the fact that this is theoretically
a WMI-ish problem, but the core WMI infrastructure has never supported
general control over printer configuration details; that in turn is likely
due to the limited and inconsistent exposure of properties by printer OEMs
as a whole.

You have three options I can think of to get the results you need. Follow up
on what you can and we'll see if we can help.

(1) Use your CAD pacakge's capabilities
You didn't mention the name of the software package you use, but since it
supports VBScript it's apparently designed to be automated, and may expose
details for available printers internally. Could you tell us what it is, and
possibly post a link to the manufacturer's website?
This is a good option as a solution, since CAD is one problem domain where
printer sheet size control is important.

(2) Direct registry edit from script
A second option is finding out where the printer configuration data is
stored in the registry and in what format, and then modifying it directly.
There are general printer configuration details stored under , but its also
common for graphics applications such as art and CAD packages to set
specific configurations in their own software keys in the registry (possibly
under HKCU\Software\<appname> somewhere).
If your application does _not_ do this, things get complicated - too
complicated to be a good idea in my opinion; I suggest skipping to (3).

(3) Custom component
There are components that can manipulate printer settings directly for you.
Lee Peedin (a REXX guru who occasionally hangs out with us here) has one
such object that may be useful; it's PrinterObject2, which can be found on
his page here:
http://pragmaticlee.safedataisp.net/



"Subbu" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...



vbscript >> How to set Paper size in vbs

by U3ViYnU » Wed, 12 Aug 2009 22:01:02 GMT

hanks Alex for the detailed reply.
The ECAD software is E3.Schematic from zuken. www.zuken.com. I did realise
the read only properties of wmi.

1. as mentioned the Ecad scripting interface is yet to support paper size.
2. It uses the printer's configuration/properties for paper size etc. i.e
we get printer dialog box for these. If I can access the printer's setting
in the registry then it may be possible.
3. I did download the Activex Printer object 2. I ran the registry update.
However I am not sure how to use this object in the script. it is throwing
errors. any sample code

Thanks for the info so far
regards
subbu

"Alex K. Angelopoulos" wrote:



How to set Paper size in vbs

by Eric » Wed, 19 Aug 2009 03:42:22 GMT




You can do something like that in VB
( http://forums.devx.com/archive/index.php/t-65710.html ).
I remember setting the printer orientation in my own VB program and finding
something of an object with read only properties I had to work around. Does
VBScript have something similar?




How to set Paper size in vbs

by U3ViYnU » Mon, 31 Aug 2009 10:05:01 GMT

Guys,
Thanks for the replies so far. I found out the way to accomplish this in
VBS.

1. you need to download Windows resource kit tools. This is freely
downloadable.

http://www.microsoft.com/Downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Have a look at the help file also, in Allprograms-->windows resource kit
tools->Windows resource kit tools help.html

2. One of the tools in this took kit is, Setprinter.exe, spooler
configuration tool

3. Then I used the following code in VBS to achieve this.
Dim Wshshell, setpnra3, myprinter

Set Wshshell= CreateObject("WScript.Shell")
myprinter = "printer name"
setpnra3 = "setprinter " &_
"""" & myprinter & """" & " 2 " & """" & "pdevmode=dmpapersize=8" & """"
' size = 8 for A3, size 9 for A4 etc.

intRC = WshShell.Run(setpnra3, 0, TRUE)

if intRC <> 0 then
WScript.Echo "Error returned from Setting the Printer " & intRC
WScript.Quit
End If

4. Setprinter.exe can set printer settings to different levels. I have
used level "2" which has most of the printer settings, in pDevmode.
Remember, this sets "myprinter" to this new settings.

5. For the remote printers, if the access is denied, then you can not set
using this command. Work around to this is, Install the Remote pritner
locally, to a new local port( there is a procedure in Microsoft web site) and
then change the settings to this local printer. I have done this way, it
works fine.

6. Using this setprinter, you can set most of the printer settings(this is
not application based, will change the printer settings globally).
The following can be set:- in pdevmode
dmorientation = 1 (P) or 2 (L)
dmpapersize=9(a4), 8(a3)etc
dmcopies=1
dmdefaultsource=7
dmprintquality=600
dmcolor=1monochrome 2 color
dmduplex=1no.2 yes
dmyresolution=600
dmTToption=2 (True type fonts)
dmcollate=1 on 2 off
dmbitsperpel =4
dmICMmethod =1
dmICMintent=3
dmMediatype=1 plain

Hope this helps. If you have any issues, I will be glad to help, If I know.

regards









Similar Threads

1. How to set Paper size in vbs

2. How do I set the printer size of paper the same as page size (48

One idea is to get page width and height
from cells PageWidth and PageHeight of 
PageSheet, ex,
PgWi=objPage.PageSheet.Cells("PageWidth")
PgHi=objPage.PageSheet.Cells("PageHeight")
, 
and to decide ThisDocument.PaperSize in your 
own program.

3. Setting paper size through VB.NET code - Asp.Net

4. Setting paper size in code VB.net 2008

Hi All

Using VB.net 2008, windows forms application on Windows XP SP2

I need to set the paper size when printing to an 80mm Epson docket printer 
using windows drivers

Some customers have invoices with many items on it and once past 297mm, the 
rest are lost (not printed)

If I set a custom size within the printer driver (in printers and faxes) 
then all works fine. If not then the roll cuts off at 297mm, regardless of 
the custom size set in code, which is the default standard papersize length


I have tried the following... which DOES NOT WORK

frmpos.pd.PrintController = New StandardPrintController
frmpos.pd.DefaultPageSettings.Margins.Left = 10

frmpos.pd.DefaultPageSettings.Margins.Right = 10

frmpos.pd.PrinterSettings.DefaultPageSettings.Margins.Left = 10

frmpos.pd.PrinterSettings.DefaultPageSettings.Margins.Right = 10

Dim pkCustomSize1 As New PaperSize("New Long Roll", 315, 2000)

frmpos.pd.PrinterSettings.DefaultPageSettings.PaperSize = pkCustomSize1

frmpos.pd.DefaultPageSettings.PaperSize = pkCustomSize1

AddHandler frmpos.pd.PrintPage, AddressOf frmpos.pd_RePrintPage

frmpos.pd.Print()

RemoveHandler frmpos.pd.PrintPage, AddressOf frmpos.pd_RePrintPage



Regards

Steve


5. Setting printer paper size - VB.Net

6. Using VBA to create PDF - setting paper size

I am successfully using Ron de Bruin's Create and mail PDF files with Excel 
2007.  Here is the relevant snippet from his function:

        Myvar.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                FileName:=Fname, _
                Quality:=xlQualityMinimum, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=OpenPDFAfterPublish

My questions is, where can I learn more of the above settings?  
Specifically, I would like to set the paper size to Legal.  It's defaulting 
to Letter.  But I would also like to know where I can learn all the 
parameters I can set this way for future reference.

Thanks!

Keith

7. Set Printer Paper Size & Disable Advanced Printing Features

8. How to set custom paper size in crystal reports 8.5

Hi, I am unable to set the custom paper size using VB 6.0 (with SP 6) and Crystal Reports 8.5. I need to set it to 8.5 Inches x 6.0 Inches (Width x Height). My printer does not support the User Defined Sizes
I have tried the following cod
crptobj.PaperSize = crPaperUser