如何设置页面方向和旋转
页面方向指的是页面的排列方式,可以是垂直(纵向)或水平(横向)。
页面旋转是调整页面角度的过程,允许您更改其方向,这对于纠正对齐或满足特定的观看偏好非常有用。 页面角度可以设置为90度、180度和270度。
IronPDF允许您在渲染过程中指定方向为纵向或横向。 此外,您可以根据需要将新渲染或现有的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 提供了四种可能的旋转度数:
- 无: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);