API Select Printer Paper Size - C#

Programming and macros
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

API Select Printer Paper Size - C#

Unread post by Jordan Brown »

Does anyone have experience with selecting paper size using C#? There is a great macro on Codestack (here) but it uses a VBA function "Device Capabilities" that, according to me reading, does not exist in C#.

Thanks,
Jordan
User avatar
AlexB
Posts: 483
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 27
x 257
x 432

Re: API Select Printer Paper Size - C#

Unread post by AlexB »

I know it's not a ton of help, since it's not directly in c#, but you should be able to translate it pretty easily.

The below code picks A (8.5" x 11") and B(11" x 17")

Code: Select all

With swModel.PageSetup

    Select Case PaperSize
        Case "A"
            .PrinterPaperSize = 1
            .ScaleToFit = True
            swPSize = 1

        Case "B"
            .PrinterPaperSize = 17
            swPSize = 17
            .ScaleToFit = True
        Case Else
            MsgBox("Error! You must select a page size before printing!")
            Exit Sub
    End Select
End With
This may also help if you haven't looked at it yet.
API Help Page - PageSetup Example c#
User avatar
JSculley
Posts: 632
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 864

Re: API Select Printer Paper Size - C#

Unread post by JSculley »

Jordan Brown wrote: Thu Mar 10, 2022 7:06 am Does anyone have experience with selecting paper size using C#? There is a great macro on Codestack (here) but it uses a VBA function "Device Capabilities" that, according to me reading, does not exist in C#.

Thanks,
Jordan
This
Stack Overflow post may help.
Post Reply