如何安装 Python 以通过 .NET 运行 Aspose.PDF for Python

本主题包含有关如何安装 python 以通过 .NET 运行 Aspose.Pdf for Python 的详细步骤。它被视为您在任何基于 Microsoft Windows、Linux 或 macOS 的操作系统中配置了 .NET Framework,并指导您安装所有必需的软件以在 Python 中执行 Aspose.Pdf 代码。我们将在这些步骤中安装 Python 并创建一个新的 PDF 文件来验证环境。

安装 Python 以通过 .NET 运行 Aspose.Pdf for Python 的步骤

  1. 您拥有配置了 .NET 框架支持的 Microsoft Windows、Linux 或 macOS 操作系统。如需更多信息,您可以访问 Install .NET on Windows, Linux, and macOS
  2. 在 VS Code 中安装 Python 扩展
  3. 安装Python 3.9.6
  4. 安装 pip 命令
  5. 使用 Pip 安装最新版本的 Aspose.Pdf for Python via .NET
  6. 为 Python 生成并执行 Aspose-Pdf 代码以创建 PDF 文件

如果您已经建立了满足前两个步骤的环境,则可以忽略它们,在您的 Windows、Linux 或 macOS 环境中的终端或命令提示符中继续执行后续命令。您需要安装 Python 和 Pip3 才能安装 Aspose.Pdf。

安装 Python 以通过 .NET 为 Python 运行 Aspose.Pdf 的脚本

1. Install .NET Framework (Required for Ubuntu only)
#For Ubuntu
apt update
apt upgrade
apt install sudo
sudo apt update
sudo apt install wget
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1
2. Install Python 3.9.6
#For Ubuntu
sudo apt install -y python3.9
# For MS Windows and macOS
install using MSI or DMG package. Be sure to select the check box to set the path during the installation
3. Installing Pip Command
# For Ubuntu
sudo apt install python3-pip
# For Windows and Mac
python3 -m pip install --upgrade pip
4. Install Aspose.Pdf
python3 -m pip install aspose-pdf
# Additional requirements for Ubuntu to install libgdiplus and libc6-dev
# For Ubuntu only
apt-get update
apt-get install -y libgdiplus
cd /usr/lib && ln -s libgdiplus.so gdiplus.dll
apt-get install -y --no-install-recommends libc6-dev
5. Write a sample program and save it as SamplePdf.Py and execute the Program
python3 SamplePdf.py
import aspose.pdf as pdf
# Create the empty PDF file
pdfDocument = pdf.Document()
# Insert the page in the PDF
pdfPage = pdfDocument.pages.add()
# Save the PDF on the disk
pdfDocument.save("GeneratedPdf.pdf")
print("Process completed")
6. Run the sample using the following command
python3 SamplePdf.py

如果您的环境中已经设置了 .NET Framework、Python 3.9.6 和 PIP,您可以从第 5 步开始使用 API。建议使用带有 API 的 Python 3.9.6 而不是旧的 Python2.x 版本。

还提供了使用 API 的基本工作示例代码来验证安装。您可以使用其他示例并探索 API 功能,以处理您想要使用 API 生成的不同示例。

 简体中文