纵向和横向方向

IronPDF for Java 可以修改新的和现有的 PDF 文档的页面方向。

使用IronPDF重新渲染的新PDF文档默认为竖向。 开发人员可以使用ChromePdfRenderOptions实例在将内容(HTML、RTF、URL等)转换为PDF时覆盖此行为。 setPaperOrientation 方法接受一个 PaperOrientation 值,允许开发人员根据需要更改生成的 PDF 的纸张方向。 第21至23行的示例代码创建了一个设置为横向的PDF文档。 在第 21 行调用 setPaperOrientation 并使用 PaperOrientation.LANDSCAPE 触发了页面方向行为。 将枚举值替换为PaperOrientation.PORTRAIT将使随后调用PdfDocument.renderUrlAsPdf在纵向方向上创建IronPDF主页

ChromePdfRenderOptions 对象不能用于更改现有 PDF 的页面方向(这些 PDF可能是通过先前调用任何 PDF 渲染方法生成的 PdfDocument,或使用 PdfDocument.fromFile 方法加载到 IronPDF 中的 PDF)。 对于这些PDF文档,可以通过基于旋转的变换调整页面方向。 为此,IronPDF 提供了 rotateAllPages 方法供使用。

rotateAllPages 接受一个 PageRotation 枚举类型,该类型指定了一组可接受的旋转值。 第40行的特色代码示例将工作PDF文档中的每个页面顺时针旋转270度。 要在 PDF 中仅旋转一页(或一部分页面),请选择使用 rotatePage 方法而不是 rotateAllPages

existingPdf.rotatePage(PageRotation.CLOCKWISE_270, PageSelection.firstPage());  
existingPdf.rotatePage(PageRotation.CLOCKWISE_180, PageSelection.lastPage());  
existingPdf.rotatePage(PageRotation.CLOCKWISE_90, PageSelection.singlePage(8)); // Rotate page 9  
existingPdf.rotatePage(PageRotation.CLOCKWISE_270, PageSelection.pageRange(9, 14)); // Rotate pages 10 - 15
existingPdf.rotatePage(PageRotation.CLOCKWISE_270, PageSelection.firstPage());  
existingPdf.rotatePage(PageRotation.CLOCKWISE_180, PageSelection.lastPage());  
existingPdf.rotatePage(PageRotation.CLOCKWISE_90, PageSelection.singlePage(8)); // Rotate page 9  
existingPdf.rotatePage(PageRotation.CLOCKWISE_270, PageSelection.pageRange(9, 14)); // Rotate pages 10 - 15
JAVA