このトピックでは、python をインストールして .NET 経由で Aspose.Pdf for Python を実行する方法について詳しく説明します。 Microsoft Windows、Linux、または macOS ベースのオペレーティング システムのいずれかで .NET Framework が構成されていると見なされ、Python で Aspose.Pdf コードを実行するために必要なすべてのソフトウェアをインストールするように指示されます。これらの手順で Python をインストールし、新しい PDF ファイルを作成して環境を確認します。
Python をインストールして .NET 経由で Aspose.Pdf for Python を実行する手順
- .NET フレームワークをサポートするように構成された Microsoft Windows、Linux、または macOS オペレーティング システムを使用していると見なされます。詳細については、Install .NET on Windows, Linux, and macOS をご覧ください。
- VS Code に Python 拡張機能をインストールする
- Python 3.9.6をインストール
- Pip コマンドをインストールする
- Pip を使用して Aspose.Pdf for Python via .NET の最新バージョンをインストールします
- Python 用の Aspose-Pdf コードを生成して実行し、PDF ファイルを作成します。
最初の 2 つの手順を満たす環境が既に確立されている場合は、それらを無視して、Windows、Linux、または macOS 環境内のターミナルまたはコマンド プロンプトで後続のコマンドに進むことができます。 Aspose.Pdf をインストールするには、Python と Pip3 をインストールする必要があります。
Python をインストールして .NET 経由で Aspose.Pdf for Python を実行するスクリプト
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 を使用できます。古いバージョンの Python2.x ではなく、Python 3.9.6 と API を使用することをお勧めします。
インストールを検証するために、API を使用した基本的な作業サンプル コードも提供されています。他のサンプルを使用して API 機能を探索し、API を使用して生成するさまざまな例を操作できます。