Page 1 of 1

API Select Printer Paper Size - C#

Posted: Thu Mar 10, 2022 7:06 am
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

Re: API Select Printer Paper Size - C#

Posted: Thu Mar 10, 2022 8:26 am
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#

Re: API Select Printer Paper Size - C#

Posted: Thu Mar 10, 2022 1:48 pm
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.