Det här ämnet innehåller detaljerade steg om hur man installerar python för att köra Aspose.Pdf for Python via .NET. Det anses att du har .NET Framework konfigurerat i något av Microsoft Windows-, Linux- eller macOS-baserade operativsystem och uppmanar dig att installera all nödvändig programvara för att exekvera Aspose.Pdf-kod i Python. Vi kommer att installera Python under dessa steg och skapa en ny PDF-fil för att verifiera miljön.
Steg för att installera Python för att köra Aspose.Pdf för Python via .NET
- Det anses att du har ett Microsoft Windows-, Linux- eller macOS-operativsystem konfigurerat med .NET framework-stöd. För mer information kan du besöka, Install .NET on Windows, Linux, and macOS
- Installera Python-tillägget i VS Code
- Installera Python 3.9.6
- Installera Pip-kommandot
- Installera den senaste versionen av Aspose.Pdf for Python via .NET med Pip
- Generera och kör Aspose-Pdf-koden för Python för att skapa en PDF-fil
Om du redan har etablerat miljön som uppfyller de två första stegen, kan du ignorera dem och fortsätta till de efterföljande kommandona i terminalen eller kommandotolken i din Windows-, Linux- eller macOS-miljö. Du måste installera Python och Pip3 för att installera Aspose.Pdf.
Skript för att installera Python för att köra Aspose.Pdf för Python via .NET
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 |
Om .NET Framework, Python 3.9.6 och PIP redan är konfigurerade i din miljö, kan du börja från steg 5 och framåt för att använda API:et. Det rekommenderas att använda Python 3.9.6 med API istället för äldre Python2.x-versioner.
En grundläggande fungerande exempelkod som använder API tillhandahålls också för att verifiera installationen. Du kan använda andra exempel och utforska API-funktionerna för att arbeta med de olika exemplen du vill producera med hjälp av API:et.