def save_image ( pdf_path , img_path , page_num ) : pdf_img = Image ( filename = "{}[{}]" . format ( pdf_path , page_num ) ) with pdf_img . convert ( "png" ) as converted : # Set white background. converted . background_color = Color ( "white" ) converted . alpha_channel = "remove" converted . save ( filename = img_path )
add images to pdf python code
def save_image(pdf_path, img_path, page_num):
    """

    Creates images for a page of the input pdf document and saves it
    at img_path.

    :param pdf_path: path to pdf to create images for.
    :param img_path: path where to save the images.
    :param page_num: page number to create image from in the pdf file.
    :return:
    """
    pdf_img = Image(filename="{}[{}]".format(pdf_path, page_num))
    with pdf_img.convert("png") as converted:
        # Set white background.
        converted.background_color = Color("white")
        converted.alpha_channel = "remove"
        converted.save(filename=img_path)