FAQ
プリンターの用紙の向きを変更

ナレッジ番号:5579 | 登録日:2023/07/27 | 更新日:2024/06/28

概要

ArcMap で印刷する際のプリンターの用紙の向きを、デフォルトの縦向きから横向きに変更するサンプル コードをご紹介いたします。

※ArcMap アドインでのみ使用可能です。

Image

Image

サンプル コード

下記のサンプル コードを使用する前に、データが追加してあるマップ ドキュメント(*.mxd)を開き、レイアウト ビューに切り替えて実行してください。
※レイアウト ビューへの切り替え方: ArcMap [表示] メニュー → [レイアウト ビュー]

//使用する名前空間
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Output;

protected override void OnClick()
{  
   //ArcMap アプリケーションにアクセス
   IMxApplication pMxApplication = ArcMap.ThisApplication;

   //マップ ドキュメントにアクセス
   IMxDocument pMxDocument = ArcMap.Document;
               
   //レイアウト ビューにアクセス
   IPageLayout pPageLayout = pMxDocument.PageLayout;

   //プリンターにアクセス
   IPrinter pPrinter = pMxApplication.Printer;

   //プリンターの用紙設定にアクセス
   IPaper pPaper = pPrinter.Paper;

   //プリンターの用紙の向きを変更
   //1 は縦向き、2 は横向き
   pPaper.Orientation = 2;

   //変更内容をレイアウト ビューに設定
   IActiveView pActiveView =(IActiveView)pPageLayout;
   pActiveView.PrinterChanged(pPrinter);
}
'使用する名前空間
imports ESRI.ArcGIS.ArcMapUI
imports ESRI.ArcGIS.Carto
imports ESRI.ArcGIS.Output

Protected Overrides Sub OnClick()
   'ArcMap アプリケーションにアクセス
   Dim pMxApplication As IMxApplication = My.ArcMap.ThisApplication

   'マップ ドキュメントにアクセス
   Dim pMxDocument As IMxDocument = My.ArcMap.Document

   'レイアウト ビューにアクセス
   Dim pPageLayout As IPageLayout = pMxDocument.PageLayout

   'プリンターにアクセス
   Dim pPrinter As IPrinter = pMxApplication.Printer

   'プリンターの用紙設定にアクセス
   Dim pPaper As IPaper = pPrinter.Paper

   'プリンターの用紙の向きを変更
   '1 は縦向き、2 は横向き
   pPaper.Orientation = 2

   '変更内容をレイアウト ビューに設定
   Dim pActiveView As IActiveView = DirectCast(pPageLayout, IActiveView)
   pActiveView.PrinterChanged(pPrinter)
End Sub

メタデータ

種類

製品