直式與橫式排版
import {PdfDocument, PdfPaperOrientation} from "@ironsoftware/ironpdf";

(async () => {
    const options = {
        // For NEW PDF Documents use PdfPaperOrientation
        // PdfPaperOrientation: To choose Landscape or Portrait Orientation in a new PDF document
        paperOrientation: PdfPaperOrientation.Landscape,
    };
 
    const newPdfFromHtml = PdfDocument.fromHtml("<h1> Hello World! </h1>", {renderOptions: options});
    const newPdfFromHtmlFile = PdfDocument.fromHtml("example.html", {renderOptions: options});
    const newPdfFromUrl = PdfDocument.fromUrl("https://ironpdf.com", {renderOptions: options});
    
    // For EXISTING PDFs use setRotation
    // setRotation : To rotate a PDF page and all of its contents
    const existingPdf = PdfDocument.fromFile("old_report.pdf");

    // Rotate specified page
    (await existingPdf).setRotation(90,{pdfPageSelection: [0]});

    // Rotate ALL pages
    (await existingPdf).setRotation(270,{pdfPageSelection: "all"});
    
    (await existingPdf).saveAs("rotated.pdf");
})();
npm i @ironsoftware/ironpdf
直式與橫式排版

直式與橫式排版

頁面的方向和旋轉有時會混淆,因為在處理90度旋轉和橫向方向時,它們在視覺上看起來相似。

頁面的方向專指頁面如何初始佈局,有兩個選項:垂直(直向)或水平(橫向)。

另一方面,頁面旋轉涉及調整頁面的角度,允許您根據需要更改頁面的方向。 這對於校正對齊或滿足特定的觀賞偏好很有用。 頁面角度通常可以設置為90、180或270度。

了解更多關於在PDF渲染過程中配置頁面方向的方法,請參閱IronPDF的設定頁面方向指南。 然而,在現有的PDF文件中無法更改頁面的方向。 相反地,可以對現有的PDF文件應用旋轉,但無法在渲染過程中調整。

在GitHub上探索我們的PDF頁面方向範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.11剛剛發布