PDF 旋转

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

如何旋轉 PDF 頁面

為了旋轉 PDF 文件,我們將使用 Aspose.PDF API,它是一款功能豐富、強大且易於使用的文件操作 API,適用於任何平台。開啟 NuGet 套件管理器,搜尋 Aspose.PDF 並安裝。您也可以在套件管理器控制台中使用下列命令。

旋轉 PDF 文件


您需要 Aspose.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);