How to change paper size


This sample demonstrates how to change the form size of the Page and Paper objects. The Page and Paper objects appear to users in ArcMap's PageLayout View, and are normally changed through the Page and Print Setup dialog. Setting the form of the Page object, as shown in PageToTabloid(), will also turn off the "Same As Printer" checkbox that you see in the Page Setup dialog. If you want to keep Same As Printer enabled, change the FormID of the current Printer's Paper object instead. Because all print drivers report supported paper sizes differently, the code must search through all paper sizes reported by the printer. PaperToTabloid() demonstrates how to search for a Tabloid (11 x 17) form size and assign it to the Paper object.

How to use

  1. Paste this code into the Visual Basic editor and select Run Sub from the Run menu.
[VBA]
Public Sub PageToTabloid()
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    pMxDoc.PageLayout.Page.FormID = esriPageFormTabloid
    
End Sub

Public Sub PaperToTabloid()
    
    Dim pMxDoc As IMxDocument
    Dim pMxApp As IMxApplication
    Dim pPrinter As IPrinter
    Dim pPaper As IPaper
    Dim iFormId As Long
    Dim dPaperWidth As Double, dPaperHeight As Double
    Dim sFormName As String
    Dim pEnumTypeInfo As IEnumNamedID
    Dim sTargetForm As String
    
    Set pMxDoc = ThisDocument
    Set pMxApp = ThisDocument.Parent
    Set pPrinter = pMxApp.Printer
    Set pPaper = pPrinter.Paper
    
    ' do a non-case-sensitive search for "11 x 17" in the paper sizes
    '  reported by the printer.
    sTargetForm = "11 x 17"
    Set pEnumTypeInfo = pPaper.Forms
    pEnumTypeInfo.Reset
    iFormId = pEnumTypeInfo.Next(sFormName)
    Do While (InStr(1, sFormName, sTargetForm, vbTextCompare) < 1) And (iFormId > 0)
        Debug.Print "FormID:" & iFormId & vbTab & "FormName:" & sFormName
        iFormId = pEnumTypeInfo.Next(sFormName)
        DoEvents
    Loop
    Debug.Print "*** searched for '" & sTargetForm & "'... found:";
    Debug.Print "   FormID:" & iFormId & vbTab & "FormName:" & sFormName
    
    ' exit the subroutine if the target form was not found on the current printer
    If iFormId = 0 Then Exit Sub
    
    ' if target form was found, assign it's form id to the Paper object
    pPaper.FormID = iFormId
    
    ' set the page size to match the new paper size
    pPaper.QueryPaperSize dPaperWidth, dPaperHeight
    pMxDoc.PageLayout.Page.PutCustomSize dPaperWidth, dPaperHeight
    
    ' turn Same As Printer on
    pMxDoc.PageLayout.Page.FormID = esriPageFormSameAsPrinter
    pMxDoc.ActiveView.PrinterChanged pMxApp.Printer
    
End Sub