Convert EPUB to PDF in Python SDK
Import PDF Documents from multiple formats including EPUB with Aspose.PDF Cloud Python SDK
Get StartedHow to Convert EPUB to PDF Using Python SDK
To convert EPUB to PDF, we’ll use Aspose.PDF Cloud Python SDK This Cloud SDK assists Python programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Python programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Python SDK. If the python package is hosted on Github, you can install directly from Github:
You may also use the Installation from Github: pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git
Package Manager Console Command
pip install asposepdfcloud
Steps to Convert EPUB to PDF via Python
Aspose.PDF Cloud Python developers can easily load & convert EPUB files to PDFs in just a few lines of code.
- Set Input File Name
- Set Output File Name
- Create Options Dictionary
- Call API Method
- Downloads the PDF file for local use
System Requirements
It is easy to get started with Aspose.PDF Cloud Python SDK:
- Python 2.7 and 3.4+
This sample code shows EPUB to PDF via Cloud Python SDK Conversion
from asposepdfcloud import PdfApi, ApiClient
import shutil
import os
import json
from pathlib import Path
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
class PdfEpubToPdfConvert:
"""Class for converting EPUB to PDF using Aspose PDF Cloud API."""
def convert(self):
"""Convert EPUB to PDF document."""
localFolder = "C:\Samples"
storageImageName = "sample.epub"
storageTempFolder = "TempPdfCloud"
outputFileName = "output_convert_epub.pdf"
# Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))
if self.pdf_api:
file_path = localFolder + "/" + storageImageName
storageImagePath = storageTempFolder + '/' + storageImageName
self.pdf_api.upload_file(storageImagePath, file_path)
opts = { "dst_folder": storageTempFolder }
try:
response = self.pdf_api.put_epub_in_storage_to_pdf(outputFileName, storageImagePath, **opts)
if response.code == 200:
temp_file = self.pdf_api.download_file(storageTempFolder + '/' + outputFileName)
local_path = localFolder + '/' + outputFileName
shutil.move(temp_file, local_path)
logging.info(f"epub_convert(): EPUB file successfully converted to PDF: '{outputFileName}'.")
else:
logging.error(f"epub_convert(): Failed to convert EPUB file to PDF. Response code: {response.code}")
except Exception as e:
logging.error(f"epub_convert(): Error while converting EPUB file: {e}")