0

I am trying to use python to automate the conversion of pdf-docs into png-docs (pdf2image). So far the python-script works as hoped, but when I try to distribute my little programm to other people (using pyinstaller to convert the script into a exe-file) something goes wrong. However, when I run my python-script the task is executed properly, but after starting the exe literally nothing happens.

Unfortunalety I have few experience in coding and my code might be laborious but I will be very thankful, if someone can help me.

from pdf2image import convert_from_path
import os
from pathlib import Path


absolutePath = os.path.dirname(os.path.abspath(__file__)) 
newlist = [] 
counter = 1


def collectPDF(): 
    items = os.listdir(absolutePath)
    for names in items:
        if names.endswith('.pdf'):
            newlist.append(names) 
        number = list(range(100))
        for numb in number:
            if names.endswith(str(numb) + '.png'):
                exit()


def convert(filename):
    pages = convert_from_path(absolutePath + '/' + filename, 300)
    for page in pages:
        global counter
        page.save(absolutePath + '/' + str(counter) + '.png', 'PNG')
        counter += 1

collectPDF()
for name in newlist:
    convert(name)
del newlist[:] 
Jammmme
  • 11
  • 2
  • Does your script get executed if you run it directly with python: `python my_pdf_script.py`? Do you get results as you expected? – Yannis P. Mar 30 '22 at 14:49
  • @YannisP. yes, the script gets executed and creates the expected results... – Jammmme Mar 31 '22 at 10:42
  • @KJ Thanks for your help, but I'm afraid I'm not advanced enough to understand it yet... Could you elaborate on that a bit more? During the coding process I got to the point where I had to install the poppler-thing to use pdf2image in python. I didn't know why, but after that the conversion worked. What is poppler for? And is there a smarter way to create an exe that converts all pdf-files in the current folder into png-files with a numbered name (1.png, 2.png, 3.png...)? – Jammmme Mar 31 '22 at 10:49
  • @KJ thanks for your explanation. I'm not sure I understood all details yet, but it already did help a lot. But I am still looking for a possibility to convert one pdf-file into different pngs by just clicking an .exe-file or something that is equally simple... – Jammmme Apr 04 '22 at 14:37
  • @KJ ohh, this looks exactly like what I was looking for! But unfortunately I don't get how to work with it. Just clicking the exe in a folder with a pdf does obviously not work... How do I exactly set up the configuration-file? Sorry, if this is a dumb question, but I've never seen and worked with an application like that... – Jammmme Apr 05 '22 at 10:17

0 Answers0