PDF 文件頁面方向解決方案

使用免費的跨平台應用程式和 API 輪換 PDF 文件

如何旋轉 PDF 頁面

為了旋轉PDF檔,我們將使用[Aspose.PDF](https://products.aspose.com/pdf)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於任何平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

旋轉 PDF 文件


您需要 [Aspose.PDF 庫](https://releases.aspose.com/pdf) 來嘗試環境中的代碼。

  1. 載入包含文件實例的 PDF。
  2. 將頁面向上移動以補償頁面大小的變化。
  3. 設置新舊頁面高度。
  4. 設定頁面旋轉角度。
  5. 儲存輸出的 PDF 檔案。

旋轉 PDF - C#。

    string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
    Document doc = new Document(dataDir + "input.pdf");
    foreach (Page page in doc.Pages)
{
    Aspose.Pdf.Rectangle r = page.MediaBox;
    double newHeight = r.Width;
    double newWidth = r.Height;
    double newLLX = r.LLX;
    double newLLY = r.LLY + (r.Height - newHeight);
    page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
    // Sometimes we also need to set CropBox (if it was set in original file)
    page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
    // Setting Rotation angle of page
    page.Rotate = Rotation.on90;
}
    dataDir = dataDir + "ChangeOrientation_out.pdf";
    // Save output file
    doc.Save(dataDir);