Results 1 to 16 of 16

Thread: [2005] change default printer's layout

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Question [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.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2
    New Member
    Join Date
    Oct 2006
    Posts
    4

    Re: [2005] change default printer's layout

    Printer.Orientation = vbPRORLandscape

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] change default printer's layout

    Are you doing it specifically for your own print run? If so it would be:
    VB Code:
    1. Me.PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    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

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    that's what i figured, i'm searching for any additional info that i can

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  7. #7
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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...

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] change default printer's layout

    Geez Merrion. What do you know about printing?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    Quote Originally Posted by Merrion
    SetPrinter API - or if yopu want to use a wrapped up in .NET style way download the PrintQueueWatch code and use the PrinterInformation class...
    i'm looking at the class but i'm not seeing how to change the layout

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  10. #10

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    i'm trying to use

    VB Code:
    1. Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA"_
    2.         (ByVal pPrinterName As String, _
    3.         ByVal phPrinter As Integer, _
    4.         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?

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  11. #11
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2005] change default printer's layout

    Odd - what operating system are you using?

  12. #12

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    winxp

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  13. #13
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2005] change default printer's layout

    I have:-
    VB Code:
    1. <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    2. SetLastError:=True, CharSet:=CharSet.Ansi, _
    3. ExactSpelling:=False, _
    4. CallingConvention:=CallingConvention.StdCall)> _
    5. Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    6.                             <OutAttribute()> ByRef phPrinter As Int32, _
    7.                                <InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDefault As PRINTER_DEFAULTS _
    8.                                ) As Boolean
    9.  
    10.     End Function
    11.  
    12.     <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    13. SetLastError:=True, CharSet:=CharSet.Ansi, _
    14. ExactSpelling:=False, _
    15. CallingConvention:=CallingConvention.StdCall)> _
    16. Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    17.                               <OutAttribute()> ByRef phPrinter As Int32, _
    18.                               <InAttribute()> ByVal pDefault As Int32 _
    19.                                ) As Boolean
    20.  
    21.     End Function
    22.  
    23.  
    24.  
    25.     <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    26.     SetLastError:=True, CharSet:=CharSet.Ansi, _
    27.     ExactSpelling:=False, _
    28.     CallingConvention:=CallingConvention.StdCall)> _
    29.     Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    30.                                 <OutAttribute()> ByRef phPrinter As IntPtr, _
    31.                                 <InAttribute()> ByVal pDefault As PrinterDefaults _
    32.                                        ) As Boolean
    33.  
    34.     End Function
    35.  
    36. <StructLayout(LayoutKind.Sequential)> _
    37. Friend Class PrinterDefaults
    38.  
    39. #Region "Public interface"
    40.  
    41.     Public DataType As String
    42.     Public lpDevMode As IntPtr
    43.     Public DesiredAccess As PrinterAccessRights
    44.  
    45. #End Region
    46.  
    47. End Class
    48.  
    49.     <FlagsAttribute()> _
    50.     Public Enum PrinterAccessRights
    51.         ' READ_CONTROL - Allowed to read printer information
    52.         READ_CONTROL = &H20000
    53.         ' WRITE_DAC - Allowed to write device access control info
    54.         WRITE_DAC = &H40000
    55.         ' WRITE_OWNER - Allowed to change the object owner
    56.         WRITE_OWNER = &H80000
    57.         ' SERVER_ACCESS_ADMINISTER
    58.         SERVER_ACCESS_ADMINISTER = &H1
    59.         '  SERVER_ACCESS_ENUMERATE
    60.         SERVER_ACCESS_ENUMERATE = &H2
    61.         ' PRINTER_ACCESS_ADMINISTER Allows administration of a printer
    62.         PRINTER_ACCESS_ADMINISTER = &H4
    63.         ' PRINTER_ACCESS_USE Allows printer general use (printing, querying)
    64.         PRINTER_ACCESS_USE = &H8
    65.         ' PRINTER_ALL_ACCESS Allows use and administration.
    66.         PRINTER_ALL_ACCESS = &HF000C
    67.         ' SERVER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)
    68.         SERVER_ALL_ACCESS = &HF0003
    69.     End Enum

  14. #14
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    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?

  15. #15

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    Quote Originally Posted by Merrion
    I have:-
    VB Code:
    1. <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    2. SetLastError:=True, CharSet:=CharSet.Ansi, _
    3. ExactSpelling:=False, _
    4. CallingConvention:=CallingConvention.StdCall)> _
    5. Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    6.                             <OutAttribute()> ByRef phPrinter As Int32, _
    7.                                <InAttribute(), MarshalAs(UnmanagedType.LPStruct)> ByVal pDefault As PRINTER_DEFAULTS _
    8.                                ) As Boolean
    9.  
    10.     End Function
    11.  
    12.     <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    13. SetLastError:=True, CharSet:=CharSet.Ansi, _
    14. ExactSpelling:=False, _
    15. CallingConvention:=CallingConvention.StdCall)> _
    16. Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    17.                               <OutAttribute()> ByRef phPrinter As Int32, _
    18.                               <InAttribute()> ByVal pDefault As Int32 _
    19.                                ) As Boolean
    20.  
    21.     End Function
    22.  
    23.  
    24.  
    25.     <DllImport("winspool.drv", EntryPoint:="OpenPrinter", _
    26.     SetLastError:=True, CharSet:=CharSet.Ansi, _
    27.     ExactSpelling:=False, _
    28.     CallingConvention:=CallingConvention.StdCall)> _
    29.     Public Function OpenPrinter(<InAttribute()> ByVal pPrinterName As String, _
    30.                                 <OutAttribute()> ByRef phPrinter As IntPtr, _
    31.                                 <InAttribute()> ByVal pDefault As PrinterDefaults _
    32.                                        ) As Boolean
    33.  
    34.     End Function
    35.  
    36. <StructLayout(LayoutKind.Sequential)> _
    37. Friend Class PrinterDefaults
    38.  
    39. #Region "Public interface"
    40.  
    41.     Public DataType As String
    42.     Public lpDevMode As IntPtr
    43.     Public DesiredAccess As PrinterAccessRights
    44.  
    45. #End Region
    46.  
    47. End Class
    48.  
    49.     <FlagsAttribute()> _
    50.     Public Enum PrinterAccessRights
    51.         ' READ_CONTROL - Allowed to read printer information
    52.         READ_CONTROL = &H20000
    53.         ' WRITE_DAC - Allowed to write device access control info
    54.         WRITE_DAC = &H40000
    55.         ' WRITE_OWNER - Allowed to change the object owner
    56.         WRITE_OWNER = &H80000
    57.         ' SERVER_ACCESS_ADMINISTER
    58.         SERVER_ACCESS_ADMINISTER = &H1
    59.         '  SERVER_ACCESS_ENUMERATE
    60.         SERVER_ACCESS_ENUMERATE = &H2
    61.         ' PRINTER_ACCESS_ADMINISTER Allows administration of a printer
    62.         PRINTER_ACCESS_ADMINISTER = &H4
    63.         ' PRINTER_ACCESS_USE Allows printer general use (printing, querying)
    64.         PRINTER_ACCESS_USE = &H8
    65.         ' PRINTER_ALL_ACCESS Allows use and administration.
    66.         PRINTER_ALL_ACCESS = &HF000C
    67.         ' SERVER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)
    68.         SERVER_ALL_ACCESS = &HF0003
    69.     End Enum

    Merrion i used this but the changes aren't permanent. once the code finishes the orientation is still portrait.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  16. #16

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] change default printer's layout

    Quote 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

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width