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

Time:03-17

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?

CodePudding user response:

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

  • Related