'Is there a way to save excel worksheets as PDFs in Python without using win32.client?

I am looking to save multiple excel worksheets as a PDF and then merge them all into one.

I need to do this without win32.client - is this possible?



Solution 1:[1]

If you want to save an excel file as a pdf, you can use asposecells and jpype:

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, FileFormatType, PdfSaveOptions

workbook = Workbook("example.xlsx")
saveOptions = PdfSaveOptions()
saveOptions.setOnePagePerSheet(True)
workbook.save("example.pdf", saveOptions)

jpype.shutdownJVM()

You can find more information here: https://pypi.org/project/aspose-cells/

In order to merge pdf's with python you can use PyPdf2's PdfMerger:

from PyPDF2 import PdfFileMerger
pdfs = ['file1.pdf', 'file2.pdf', 'file3.pdf', 'file4.pdf']

merger = PdfFileMerger()

for pdf in pdfs:
    merger.append(pdf)

merger.write("result.pdf")
merger.close()

You can read more about this in this post: Merge PDF files

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tuurtje11