ページの向きと回転を設定する方法
ページの向きは、ページがどのように配置されているかを指し、縦(縦向き)または横(横向き)のいずれかです。
ページ回転は、ページの角度を調整することで、その向きを変更することを指します。これにより、ページの整列を修正したり、特定の表示の好みに合わせたりするのに役立ちます。 ページの角度は90度、180度、270度に設定できます。
IronPDFでは、レンダリングプロセス中に縦向きまたは横向きを指定することができます。 さらに、新しくレンダリングされたPDFページや既存のPDFページを、必要に応じて0度、90度、180度、または270度の角度に個別に回転させることができます。
ページの向きと回転を設定する方法
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
ページの向きの例
他の形式からPDFドキュメントを生成する場合にのみ、向きを設定できます。 RenderingOptions クラスから PaperOrientation プロパティにアクセスできます。 このプロパティは、縦向きまたは横向きに設定することができます。 縦向きはデフォルトのページの向き設定です。
コード
:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-orientation.cs
using IronPdf;
using IronPdf.Rendering;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Change paper orientation
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
pdf.SaveAs("landscape.pdf");
PDFを出力
ページ回転の例
IronPDFで提供される回転度数は次の4種類です:
- なし: 0度または回転されていないドキュメント。
- Clockwise90: 90度時計回りに回転。
- Clockwise180: 時計回りに180度回転。
-
Clockwise270: 時計回りに270度回転。
次の内容にご注意ください。
以下に記載されているすべてのページインデックス位置は、ゼロベースのインデックス付けに従います。
ページの回転を設定
以下の方法を使用して単一ページ、複数ページ、またはすべてのページの回転を設定します。
SetAllPageRotations
: すべてのページの回転角度を設定します。SetPageRotation
: 単一ページの回転度を設定します。SetPageRotations
: 選択したページのリストに対して回転角度を設定します。
:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-set-rotation.cs
using IronPdf;
using IronPdf.Rendering;
using System.Collections.Generic;
PdfDocument pdf = PdfDocument.FromFile("landscape.pdf");
// Set all pages
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90);
// Set a single page
pdf.SetPageRotation(1, PdfPageRotation.Clockwise180);
// Set multiple pages
List<int> selectedPages = new List<int>() { 0, 3 };
pdf.SetPageRotations(selectedPages, PdfPageRotation.Clockwise270);
pdf.SaveAs("rotatedLandscape.pdf");
PDFを出力
ページ回転を取得
GetPageRotation
メソッドを使用して、PDFドキュメント内の特定のページの回転を取得します。 ページインデックスをメソッドに単純に指定します。
:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-get-rotation.cs
using IronPdf;
using IronPdf.Rendering;
PdfDocument pdf = PdfDocument.FromFile("rotatedLandscape.pdf");
PdfPageRotation rotation = pdf.GetPageRotation(1);