Warning: Can not open [/home/conf/public_html/cgi-bin/show_python.log]. Ignore No title

Download script from xlsx2img.py
Related files:


import os
import sys
from comtypes.client import CreateObject
import fitz # PyMuPDF


excel_file = 'test.xlsx'
pdf_file = 'output.pdf'
out_dir = 'images'
image_format = 'png'


nargv = len(sys.argv)
if nargv >= 2: infile = sys.argv[1]
if nargv >= 3: out_dir = sys.argv[2]
if nargv >= 4: image_format = sys.argv[3]


def convert_excel_to_pdf(excel_file, pdf_file):
    excel = CreateObject('Excel.Application')
    excel.Visible = False

    workbook = excel.Workbooks.Open(os.path.abspath(excel_file))


    workbook.Close(False)
    excel.Quit()

def convert_pdf_to_images(pdf_file, out_dir, image_format):
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    doc = fitz.open(pdf_file)
    for page_num in range(len(doc)):
        page = doc.load_page(page_num)
        pix = page.get_pixmap()
        output_path = os.path.join(out_dir, f'page_{page_num + 1}.{image_format}')
        pix.save(output_path)

if __name__ == '__main__':
    current_dir = os.getcwd()

    excel_path = os.path.join(current_dir, excel_file)
    pdf_path = os.path.join(current_dir, pdf_file)

    convert_excel_to_pdf(excel_path, pdf_path)

    convert_pdf_to_images(pdf_path, out_dir, image_format)