PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

在 Python SDK 中旋转 PDF

使用云端 Python SDK 旋转 PDF 文档。

Get Started

如何通过云端 Python SDK 旋转 PDF

要旋转 PDF,我们将使用 Aspose.PDF Cloud Python SDK。此云端 SDK 帮助 Python 程序员通过 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。如果 python 包托管在 Github 上,您可以直接从 Github 安装:

从 Github 安装


     
    pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git

包管理器控制台命令

     
    pip install asposepdfcloud

通过 Python SDK 旋转 PDF 的步骤

Aspose.PDF Cloud 开发人员可以仅用几行代码轻松加载和旋转 PDF。

  1. 安装 Python SDK
  2. 将原始文件上传到 Aspose Cloud
  3. 准备旋转 API 调用的参数
  4. 使用 Aspose Cloud 旋转页面
  5. 如果成功,记录成功消息并下载文件
 

使用 Python 旋转 PDF


    import logging
    from pathlib import Path
    from asposepdfcloud import PdfApi, AsposeResponse
    from change_layout_helper import PdfChangeLayoutHelper, Config

    class PdfRotatePages:
        def __init__(self, pdf_api: PdfApi, helper: PdfChangeLayoutHelper):
            self.pdfApi = pdf_api
            self.helper = helper
            
        def rotateDocumentPages(self, documentName: str, outputDocumentName: str, rotateAngle: str, pages: str):
            self.helper.uploadFile(documentName, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)
            
            args = {
                "folder": Config.REMOTE_FOLDER,
            }
            
            response: AsposeResponse = self.pdfApi.post_document_pages_rotate(documentName, rotateAngle, pages, **args)

            if response.code != 200:
                logging.error("rotateDocumentPages(): Unexpected error!")
            else:
                logging.info(f"rotateDocumentPages(): Pages '{pages}' successfully rotated!")
                self.helper.downloadFile(documentName, outputDocumentName, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER, "rotated_")
 

使用我们的 Python 库,您可以:

使用 Aspose.PDF Cloud Python SDK 旋转 PDF 文档。

  • 合并 PDF 文档。
  • 拆分 PDF 文件。
  • 将 PDF 转换为其他格式,反之亦然。
  • 操作注释。
  • 处理 PDF 中的图像等。
  • 您可以尝试我们的 免费应用 在线测试功能。