OksanaPochapska25 / python-examples

MIT License
0 stars 0 forks source link

the code is not working #1

Open imrankh46 opened 7 months ago

imrankh46 commented 7 months ago

hey, I run the code using colab but it crashes the sessions. and generate the xlsx file but corrupt one and empty. however the online demo is working.

OksanaPochapska25 commented 7 months ago

Hello! If you don't mind dealing with system-related issues, here's the code that works in Google Collab:

!wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
!sudo dpkg -i ./libssl1.1_1.1.0g-2ubuntu4_amd64.deb
!sudo apt-get install -y ttf-mscorefonts-installer fontconfig
!pip install aspose-pdf

import aspose.pdf as ap
import aspose.pdf.text as aptext
input_pdf = "/content/drive/MyDrive/sample_data/sample.pdf"
output_pdf = "/content/drive/MyDrive/sample_data/convert_pdf.xlsx"
folder_source = aptext.FolderFontSource("/usr/share/fonts/truetype/msttcorefonts")
aptext.FontRepository.sources.append(folder_source)
# Open PDF document
document = ap.Document(input_pdf)
# Save the file into MS Excel format
save_option = ap.ExcelSaveOptions()
document.save(output_pdf, save_option)

If you're interested, I've just published an article on how to convert PDF to XLSX using Aspose.PDF Cloud Python SDK. You can find it here: Effortless PDF to XLSX Conversion using Aspose.PDF Cloud Python SDK