import sys

from wand.image import Color
from wand.image import Image

from OMRnotes.scripts.utils.utils import filename, cleandir, makedir
from tests.generate_ly.separator import separate


def convertpdf(file):
    '''Prevod pdf souboru na png
    '''
    filen=filename(file)
    makedir(filen)
    cleandir(filename(filen))
    with Image(filename=file, resolution=300) as img:
        for i, page in enumerate(img.sequence):
            with Image(width=img.width, height=img.height, background=Color("white")) as page_image:
                page_image.composite(Image(page), 0, 0)
                page_image.save(filename=filename(filen) + '/page-' + str(i) +'.png')
    separate(filen)

if __name__ == "__main__":
    for arg in sys.argv[1:]:
        convertpdf(arg)