PDF to EPUB – Convert PDF to EPUB using Python

Convert PDF to EPUB

A PDF displays the exact same content and layout no matter which operating system, device, or software application it is viewed on. PDF is easy to share or receive without compromising on the quality and it takes less space in the hard drive and can be shared quickly and easily. However, it’s not free to edit PDF files as you need specialized programs for this purpose. Furthermore, it’s difficult to work with text in PDF files, because they are perceived as a picture. However, one workable solution is to render PDF files to EPUB formats as it’s comparatively easy to create and edit the files. It’s supported on multiple reader platforms, the Retailer’s favorite and offers more security than PDF.

PDF Processing Python SDK

Aspose.PDF Cloud SDK for Python provides all PDF file processing capabilities. It enables you to create, edit as well as transform PDF files to popular formats. In order to perform PDF manipulation, no additional software download or installation is required. So the first in using the SDK is its installation which is freely available for download over PIP and GitHub repository. Simply execute the following command on the terminal/command prompt to install the latest version of SDK on the system.

pip install asposepdfcloud

Free Cloud Dashboard

Aspose Cloud dashboard enables our customers to manage their credentials as well as the files stored in their specific storage. So in order to use Cloud APIs, the next major step is a free subscription to our cloud services via Aspose.Cloud dashboard. The purpose of this subscription is to only allow authorized persons to access our file processing services. If you have GitHub or Google account, simply Sign Up or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client credentials
Image 1:- Client Credentials on Aspose.Cloud Dashboard.

Convert PDF to EPUB using Python

Please follow the steps given below to load PDF files stored on cloud storage and perform conversion to EPUB format.

  • Firstly, create an instance of ApiClient while passing client credentials as arguments
  • Secondly, initialize PdfApi by passing ApiClient object as argument
  • Thirdly, set value for optional parameter contentRecognitionMode to control content recognition. Value can be Fixed, PdfFlow, Flow.
  • Finally, call the put_pdf_in_storage_to_epub(..) method to load PDF file already available in cloud storage, convert it to EPUB format and save the resultant file in same storage.
PDF to EPUB preview
Image 2:- PDF to EPUB conversion preview.

The input PDF file used in the above example can be downloaded from marketing.pdf.

PDF to EPUB using cURL Command

The REST APIs can also be accessed via cURL commands and similarly, the same cURL command can be used to convert PDF files to EPUB format. However, as our APIs are only accessible to authorized customers, so we need to generate a JSON Web Token (JWT) based on your client credential details specified over Aspose.Cloud dashboard. This step is mandatory because our APIs are only accessible to registered users. Please execute the following command to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=88d1cda8-b12c-4a80-b1ad-c85ac483c5c5&client_secret=406b404b2df649611e508bbcfcd2a77f" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now that we have generated the JWT token, please execute the following command to perform the conversion and save the resultant file to cloud storage.

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/marketing.pdf/convert/epub?outPath=Converted.epub&contentRecognitionMode=Fixed" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" -v  \
-d{}

Quick Tip

In order to view the EPUB files, please try using our free EPUB viewer.

Conclusion

In this article, we have explored the options on how to convert PDF to EPUB using Python. Also, we have learned about the options of converting PDF to EPUB using Python as well as cURL commands. Furthermore, the complete source code of Aspose.PDF Cloud SDK for Python over GitHub. You can download it and modify it as per your requirements. In case you encounter any issues or you have any further queries, you may also contact us via the free customer support forum.

Related Articles

We recommend visiting the following articles to learn about: