|
-
Oct 10th, 2006, 07:58 AM
#1
Thread Starter
Frenzied Member
[2005] change default printer's layout
how can i change the default printer's layout ie from protait to landscape and then back again??? this has to be done without the dialog window.
-
Oct 10th, 2006, 08:09 AM
#2
New Member
Re: [2005] change default printer's layout
Printer.Orientation = vbPRORLandscape
-
Oct 10th, 2006, 09:15 AM
#3
Re: [2005] change default printer's layout
Are you doing it specifically for your own print run? If so it would be:
VB Code:
Me.PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
-
Oct 10th, 2006, 10:01 AM
#4
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
jmcilhinney that's what i did orignally however i'm interfacing with a different application's api and there is a method that you simply send a document reference to the api's print method and it prints the document. however it doesn't have an option or method to allow me to change anything to do with the printer in the api.
so i was thinking that if i could programmatically change the default printer's orientation to landscape and then back to portrait after the printing is complete. however, if i use the code above the printer still prints in portrait. I'm assuming I would have to us some win api or change something in the registery
-
Oct 10th, 2006, 10:06 AM
#5
Re: [2005] change default printer's layout
I'm certainly not sure but I'm thinking that you would have to use the Windows API. Everything I've seen in the Printing namespace seems geared towards using a PrintDocument.
-
Oct 10th, 2006, 10:09 AM
#6
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
that's what i figured, i'm searching for any additional info that i can
-
Oct 10th, 2006, 10:32 AM
#7
Re: [2005] change default printer's layout
SetPrinter API - or if yopu want to use a wrapped up in .NET style way download the PrintQueueWatch code and use the PrinterInformation class...
-
Oct 10th, 2006, 10:41 AM
#8
Re: [2005] change default printer's layout
Geez Merrion. What do you know about printing?
-
Oct 10th, 2006, 11:33 AM
#9
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
 Originally Posted by Merrion
i'm looking at the class but i'm not seeing how to change the layout
-
Oct 10th, 2006, 01:56 PM
#10
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
i'm trying to use
VB Code:
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA"_
(ByVal pPrinterName As String, _
ByVal phPrinter As Integer, _
ByVal pDefault As PRINTER_DEFAULTS) As Integer
and i get an exception of
A call to PInvoke function 'PickTicketPrinter!PickTicketPrinter.PrinterSettingsWrapper::OpenPrinter' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
if i take out the alias i get the following
Unable to find an entry point named 'OpenPrinter' in DLL 'winspool.drv'.
what am i doing wrong?
-
Oct 10th, 2006, 02:37 PM
#11
Re: [2005] change default printer's layout
Odd - what operating system are you using?
-
Oct 10th, 2006, 02:39 PM
#12
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
-
Oct 10th, 2006, 05:06 PM
#13
Re: [2005] change default printer's layout
I have:-
VB Code:
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As Int32, _
<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDefault As PRINTER_DEFAULTS _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As Int32, _
<InAttribute()> ByVal pDefault As Int32 _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As IntPtr, _
<InAttribute()> ByVal pDefault As PrinterDefaults _
) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)> _
Friend Class PrinterDefaults
#Region "Public interface"
Public DataType As String
Public lpDevMode As IntPtr
Public DesiredAccess As PrinterAccessRights
#End Region
End Class
<FlagsAttribute()> _
Public Enum PrinterAccessRights
' READ_CONTROL - Allowed to read printer information
READ_CONTROL = &H20000
' WRITE_DAC - Allowed to write device access control info
WRITE_DAC = &H40000
' WRITE_OWNER - Allowed to change the object owner
WRITE_OWNER = &H80000
' SERVER_ACCESS_ADMINISTER
SERVER_ACCESS_ADMINISTER = &H1
' SERVER_ACCESS_ENUMERATE
SERVER_ACCESS_ENUMERATE = &H2
' PRINTER_ACCESS_ADMINISTER Allows administration of a printer
PRINTER_ACCESS_ADMINISTER = &H4
' PRINTER_ACCESS_USE Allows printer general use (printing, querying)
PRINTER_ACCESS_USE = &H8
' PRINTER_ALL_ACCESS Allows use and administration.
PRINTER_ALL_ACCESS = &HF000C
' SERVER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)
SERVER_ALL_ACCESS = &HF0003
End Enum
-
Oct 10th, 2006, 06:03 PM
#14
Frenzied Member
Re: [2005] change default printer's layout
Not really an answer but more of a question on same lines i think, Using the New PrintForm powerpack is there a way of using that to bring up the normal print dialogue then being able to change settings in there to print?
-
Oct 11th, 2006, 07:58 AM
#15
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
 Originally Posted by Merrion
I have:-
VB Code:
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As Int32, _
<InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDefault As PRINTER_DEFAULTS _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As Int32, _
<InAttribute()> ByVal pDefault As Int32 _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
<OutAttribute()> ByRef phPrinter As IntPtr, _
<InAttribute()> ByVal pDefault As PrinterDefaults _
) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)> _
Friend Class PrinterDefaults
#Region "Public interface"
Public DataType As String
Public lpDevMode As IntPtr
Public DesiredAccess As PrinterAccessRights
#End Region
End Class
<FlagsAttribute()> _
Public Enum PrinterAccessRights
' READ_CONTROL - Allowed to read printer information
READ_CONTROL = &H20000
' WRITE_DAC - Allowed to write device access control info
WRITE_DAC = &H40000
' WRITE_OWNER - Allowed to change the object owner
WRITE_OWNER = &H80000
' SERVER_ACCESS_ADMINISTER
SERVER_ACCESS_ADMINISTER = &H1
' SERVER_ACCESS_ENUMERATE
SERVER_ACCESS_ENUMERATE = &H2
' PRINTER_ACCESS_ADMINISTER Allows administration of a printer
PRINTER_ACCESS_ADMINISTER = &H4
' PRINTER_ACCESS_USE Allows printer general use (printing, querying)
PRINTER_ACCESS_USE = &H8
' PRINTER_ALL_ACCESS Allows use and administration.
PRINTER_ALL_ACCESS = &HF000C
' SERVER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)
SERVER_ALL_ACCESS = &HF0003
End Enum
Merrion i used this but the changes aren't permanent. once the code finishes the orientation is still portrait.
-
Oct 11th, 2006, 08:09 AM
#16
Thread Starter
Frenzied Member
Re: [2005] change default printer's layout
 Originally Posted by max_carpenter
Not really an answer but more of a question on same lines i think, Using the New PrintForm powerpack is there a way of using that to bring up the normal print dialogue then being able to change settings in there to print?
nope doesn't do it either
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|