xdufacool/pdf2pptx.py
def pdf_slide_to_pptx(slide_file, output_folder, template=None, dpi=200):
    """
    To convert a pdf slide given by slide_file to a PPTX file.
    """

    assert os.path.exists(slide_file)
    _, pdf_name = os.path.split(slide_file)
    basename, ext = os.path.splitext(pdf_name)
    assert ext.lower() == '.pdf'
    
    images = convert_from_path(slide_file, dpi=dpi)
    
    image_folder = os.path.join(output_folder, '.' + basename)
    if not os.path.exists(image_folder):
        os.mkdir(image_folder)

    image_paths = []
    for idx, image in enumerate(images):
        # print(type(image), image.getbbox())
        image_path = os.path.join(image_folder, f'image{idx:02d}.jpg')
        image.save(image_path)
        image_paths.append(image_path)

    if template is None:
        prs = Presentation()
    else:
        prs = Presentation(template)
    blank_slide_layout = prs.slide_layouts[6]

    left = top = 0
    for img_path in image_paths:
        slide = prs.slides.add_slide(blank_slide_layout)
        slide.shapes.add_picture(img_path, left, top,
                                 height=prs.slide_height)

    pptx_file = os.path.join(output_folder, basename + '.pptx')
    prs.save(pptx_file)

    To convert a pdf slide given by slide_file to a PPTX file.
    
To convert a pdf slide given by slide_file to a PPTX file.
To convert a pdf slide given by slide_file to a PPTX file .
def pdf_slide_to_pptx(slide_file, output_folder, template=None, dpi=200):
    assert os.path.exists(slide_file)
    _, pdf_name = os.path.split(slide_file)
    basename, ext = os.path.splitext(pdf_name)
    assert ext.lower() == '.pdf'
    images = convert_from_path(slide_file, dpi=dpi)
    image_folder = os.path.join(output_folder, '.' + basename)
    if not os.path.exists(image_folder):
        os.mkdir(image_folder)
    image_paths = []
    for idx, image in enumerate(images):
        image_path = os.path.join(image_folder, f'image{idx:02d}.jpg')
        image.save(image_path)
        image_paths.append(image_path)
    if template is None:
        prs = Presentation()
    else:
        prs = Presentation(template)
    blank_slide_layout = prs.slide_layouts[6]
    left = top = 0
    for img_path in image_paths:
        slide = prs.slides.add_slide(blank_slide_layout)
        slide.shapes.add_picture(img_path, left, top,
                                 height=prs.slide_height)
    pptx_file = os.path.join(output_folder, basename + '.pptx')
    prs.save(pptx_file)
def pdf_slide_to_pptx ( slide_file , output_folder , template = None , dpi = 200 ) : assert os . path . exists ( slide_file ) _ , pdf_name = os . path . split ( slide_file ) basename , ext = os . path . splitext ( pdf_name ) assert ext . lower ( ) == '.pdf' images = convert_from_path ( slide_file , dpi = dpi ) image_folder = os . path . join ( output_folder , '.' + basename ) if not os . path . exists ( image_folder ) : os . mkdir ( image_folder ) image_paths = [ ] for idx , image in enumerate ( images ) : image_path = os . path . join ( image_folder , f'image{idx:02d}.jpg' ) image . save ( image_path ) image_paths . append ( image_path ) if template is None : prs = Presentation ( ) else : prs = Presentation ( template ) blank_slide_layout = prs . slide_layouts [ 6 ] left = top = 0 for img_path in image_paths : slide = prs . slides . add_slide ( blank_slide_layout ) slide . shapes . add_picture ( img_path , left , top , height = prs . slide_height ) pptx_file = os . path . join ( output_folder , basename + '.pptx' ) prs . save ( pptx_file )
To convert a pdf slide given by slide_file to a PPTX file.
To convert a pdf slide given by slide_file to a PPTX file .
"""
    To convert a pdf slide given by slide_file to a PPTX file.
    """ # print(type(image), image.getbbox())
slide_file
output_folder
template
dpi