Exemple #1
0
def create_slide1(graph_name, prs):
    slide_layout = prs.slide_layouts[6]
    slide = prs.slides.add_slide(slide_layout)
    slide.shapes.add_picture(graph_name,
                             left=util.Inches(0.1),
                             top=util.Inches(1.0),
                             width=util.Inches(9),
                             height=util.Inches(6))
Exemple #2
0
 def __init__(
     self,
     files,
     file_path,
     output_filename,
     pic_per_page,
     image_height,
     pic_top_offset=0,
 ):
     self.files = files
     self.file_path = file_path
     self.slide_template = "sample_slide.pptx"
     self.output_filename = output_filename
     self.image_display_height = util.Inches(image_height / 2.54)
     self.pic_per_page = pic_per_page
     self.pic_top_offset = util.Inches(pic_top_offset / 2.54)
     self.image_display_width = 0
     self.aspect_ratio = 0
     # self.presentaition = Presentation(self.slide_template)
     self.presentaition = Presentation()
     self.slide_width = self.presentaition.slide_width
     self.slide_height = self.presentaition.slide_height
     self.slide_layout = self.presentaition.slide_layouts[5]
                else:

                    mask_dia = dilate_mask(mask, dilator, diff=True)
                    section_title = '%s %s - tumor margin' % (study_date,
                                                              RT_flag)

                # Create montage images
                mnames = display_segmentations(t2,
                                               mask_dia,
                                               save_path=os.getcwd(),
                                               sname='segs%d.png' % i)

                # Update PowerPoint
                content_slide = prs.slide_layouts[title_and_content]
                slide = prs.slides.add_slide(content_slide)

                title = slide.shapes.title
                title.text = section_title

                left = util.Inches(0.2)
                top = util.Inches(1.5)
                width = util.Inches(9.5)
                height = util.Inches(5.7)
                pic = slide.shapes.add_picture(mnames, left, top, width,
                                               height)

                # Delete montage images
                os.remove(mnames)

        prs.save(ppt_file)
def pptgen(elements,filename,tid):

  
  from pptx import Presentation,util

  prs = Presentation()
  title_slide_layout = prs.slide_layouts[1]
  title_layout = prs.slide_layouts[0]
  slide_to_voice={}
  subtopic_mapping=[]
  #Used to add bullet points
  #tf = body_shape.text_frame
  pg_cnt=0
  if len(elements)>1:
    current=0
    next_element=1
    while(next_element<len(elements)):
        if elements[next_element][:3]=="<p>":
                pg_cnt+=1
                heading=int(elements[current][2])
                if heading==1:
                    subtopic_mapping.append({"heading":elements[current][4:],"level":1,"pgno":pg_cnt,"children":[]})
                else:
                    x=subtopic_mapping[-1]
                    while(len(x)>=1):
                        if x["level"]==heading-1:
                            x["children"].append({"heading":elements[current][4:],"level":heading,"pgno":pg_cnt,"children":[]})
                            break
                        else:
                            if not x["children"] or x["children"][-1]["level"]==heading:
                                x["children"].append({"heading":elements[current][4:],"level":heading,"pgno":pg_cnt,"children":[]})
                                break
                            else:
                                x=x["children"][-1]
                summary=sg.processing(elements[next_element][3:])[0]
                summary = summary.split('.')
                summary.pop()

                for i in range(len(summary)):
                    if summary[i][1]=="\n":
                        summary[i]=summary[i][2:]+"."
                    else:
                        summary[i]=summary[i][1:]+"."
                for i in range(0,len(summary),3):
                    slide = prs.slides.add_slide(title_slide_layout)
                    title = slide.shapes.title
                    if i==0:
                        title.text=elements[current][4:]
                    else:
                        pg_cnt+=1
                        title.text=elements[current][4:]+" contd."
                    subtitle = slide.placeholders[1]
                    left = top = width = height = util.Inches(1.0)
                    shapes = slide.shapes
                    body_shape = shapes.placeholders[1]
                    tf = body_shape.text_frame
                    # tf.fit_text()# = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
                    title_shape = shapes.title
                    x=min(i+3,len(summary))
                    for j in range(i,x):
                        p = tf.add_paragraph()
                        p.text = summary[j]
                        p.level=0
                    tf.fit_text(max_size=25)
                    #print("^^^^^^^^^^^^^^^^")
                    #print(tf.paragraphs[0].font.size)
                    #print("^^^^^^^^^^^^^^^^")
        else:
            if elements[current][:2]=="<h":
                pg_cnt+=1
                heading=int(elements[current][2])
                if heading==1:
                    subtopic_mapping.append({"heading":elements[current][4:],"level":1,"pgno":pg_cnt,"children":[]})
                else:
                    x=subtopic_mapping[-1]
                    while(len(x)>=1):
                        if x["level"]==heading-1:
                            x["children"].append({"heading":elements[current][4:],"level":heading,"pgno":pg_cnt,"children":[]})
                            break
                        else:
                            x=x["children"][-1]
                slide = prs.slides.add_slide(title_layout)
                title = slide.shapes.title
                title.text = elements[current][4:]
                title.text_frame.paragraphs[0].font.size=Pt(60)
        current+=1
        next_element+=1
  
  else:
        print("here")
        title_text=topic_gen(elements[0][3:])
        subtopic_mapping.append({"heading":title_text.title(),"level":1,"pgno":1,"children":[]})
        slide = prs.slides.add_slide(title_layout)
        title = slide.shapes.title
        title.text = title_text.upper()
        title.text_frame.paragraphs[0].font.size=Pt(60)
        summary=sg.processing(elements[0][3:])[0]
        summary = summary.split('.')
        summary.pop()

        for i in range(len(summary)):
            if summary[i][1]=="\n":
                summary[i]=summary[i][2:]+"."
            else:
                summary[i]=summary[i][1:]+"."
        for i in range(0,len(summary),3):
            slide = prs.slides.add_slide(title_slide_layout)
            title = slide.shapes.title
            if i==0:
                title.text=title_text.title()
            else:
                title.text=title_text.title()+" contd."
            left = top = width = height = util.Inches(1.0)
            shapes = slide.shapes
            body_shape = shapes.placeholders[1]
            tf = body_shape.text_frame
            # tf.fit_text()# = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
            title_shape = shapes.title
            x=min(i+3,len(summary))
            for j in range(i,x):
                p = tf.add_paragraph()
                p.text = summary[j]
                p.level=0
            tf.fit_text(max_size=25)
                
  ppt_path='static/downloads/'+tid+".pptx"
  prs.save(ppt_path)
  print("**************")
  print(subtopic_mapping)
  name=filename.split(".")[0]
  pdf_name=name+".pdf"
  video_name=name+".mp4"
  ppt_path=os.path.abspath(ppt_path)
  pdf_path=ppt_path[:-4]+"pdf"
  print("**********    ",pdf_path,"      *********")
  #cv.ppt_presenter(filename,pdf_name,video_name,slide_to_voice)
  #cv.ppt_presenter('D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.pptx','D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.pdf','D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.mp4',slide_to_voice)
  #cv.PPTtoPDF(ppt_path,pdf_path)
  return {'ppt_path':ppt_path,'pdf_path':pdf_path,'mapping':subtopic_mapping}
Exemple #5
0
            visuals_cell = cells[2]
        elif len(cells) == 2:
            script_cell = cells[0]
            visuals_cell = cells[1]
        else:
            continue

        slide = pptx.slides.add_slide(layout)

        text = script_cell.xpath('normalize-space(.)')
        if text and len(text) > 0:
            slide.notes.add_note(text)

        text = visuals_cell.xpath('normalize-space(.)')
        if text and len(text) > 0:
            tbox = slide.shapes.add_textbox(util.Inches(0), util.Inches(0),
                                            pptx.slide_width, util.Inches(2))
            tbox.auto_size = enum.text.MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
            tbox.text = text
        images = visuals_cell.xpath("descendant::img")
        for img in images:
            src = img.attrib.get('src')
            r, bits = Http().request(src)
            fbits = StringIO(bits)
            ibox = slide.shapes.add_picture(fbits, 0, 0, pptx.slide_width,
                                            pptx.slide_height)

    pptx.save(fdOut)

    fdOut.close()
Exemple #6
0
def pptgen(text, summary, mapping, filename):

    language = 'hi'
    sentences = text.split('.')

    for i in range(len(sentences)):
        sentences[i] = sentences[i] + "."

    from gtts import gTTS

    summary = summary.split('.')
    summary.pop()

    for i in range(len(summary)):
        if summary[i][1] == "\n":
            summary[i] = summary[i][2:] + "."
        else:
            summary[i] = summary[i][1:] + "."

    print("xxxxxxxxxxxx")
    print(summary)
    print("xxxxxxxxxxxx")

    #summary

    from pptx import Presentation, util

    prs = Presentation()
    title_slide_layout = prs.slide_layouts[1]
    slide_to_voice = {}
    #Used to add bullet points
    #tf = body_shape.text_frame
    for i in range(0, len(summary), 3):
        slide = prs.slides.add_slide(title_slide_layout)
        print(slide.element)
        title = slide.shapes.title
        if i == 0:
            title.text = "Abstract"
        subtitle = slide.placeholders[1]
        left = top = width = height = util.Inches(1.0)
        shapes = slide.shapes
        body_shape = shapes.placeholders[1]
        tf = body_shape.text_frame
        # tf.fit_text()# = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
        title_shape = shapes.title
        x = min(i + 3, len(summary))
        for j in range(i, x):
            p = tf.add_paragraph()
            p.text = summary[j]
            p.level = 0
        tf.fit_text(max_size=25)
        print("^^^^^^^^^^^^^^^^")
        print(tf.paragraphs[0].font.size)
        print("^^^^^^^^^^^^^^^^")
        # for paragraph in tf.paragraphs:
        #   for run in paragraph.runs:
        #       run.font.size = Pt(9)
        voice_text = ' '.join(sentences[mapping[str(i)]:mapping[str(x - 1)] +
                                        1])
        myobj = gTTS(text=voice_text, lang=language, slow=False)
        myobj.save("voiceover_" + str(i) + ".mp3")
        slide_to_voice[i] = "voiceover_" + str(i) + ".mp3"
        movie = slide.shapes.add_movie("voiceover_" + str(i) + ".mp3",
                                       left,
                                       top,
                                       width,
                                       height,
                                       poster_frame_image=None,
                                       mime_type='video/unknown')
    ppt_path = 'static/downloads/' + filename
    prs.save(ppt_path)
    name = filename.split(".")[0]
    pdf_name = name + ".pdf"
    video_name = name + ".mp4"
    ppt_path = os.path.abspath(ppt_path)
    pdf_path = ppt_path[:-4] + "pdf"
    print("**********    ", pdf_path, "      *********")
    #cv.ppt_presenter(filename,pdf_name,video_name,slide_to_voice)
    #cv.ppt_presenter('D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.pptx','D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.pdf','D:\College\Capstone project\Create-tutorials-from-text-file\scripts\static\downloads\hi_summary.mp4',slide_to_voice)
    cv.PPTtoPDF(ppt_path, pdf_path)
    return {'ppt_path': ppt_path, 'pdf_path': pdf_path}
Exemple #7
0
    def make_pptx_two_or_more_pic_per_slide(self):
        num_of_slides = int(math.ceil(len(self.files) / self.pic_per_page))
        for i in range(0, num_of_slides * 2 + 3, self.pic_per_page):
            slide = self.presentaition.slides.add_slide(self.slide_layout)

            for j in range(0, self.pic_per_page):
                try:
                    file_name = self.files[i + j]
                except IndexError:
                    break

                self.calc_aspect_ratio(file_name)
                self.calc_image_display_width()

                if self.pic_per_page == 2 and j == 0:
                    # first image when paste two images to one slide
                    left = (self.slide_width / 2 -
                            self.image_display_width) / 2
                    top = (self.slide_height -
                           self.image_display_height) / 2 - self.pic_top_offset

                if self.pic_per_page == 2 and j == 1:
                    # second image when paste two images to one slide
                    left = ((self.slide_width / 2 - self.image_display_width) /
                            2) + self.slide_width / 2
                    top = (self.slide_height -
                           self.image_display_height) / 2 - self.pic_top_offset

                if self.pic_per_page == 3 and j == 0:
                    # first image when paste three images to one slide
                    left = (self.slide_width / 3 -
                            self.image_display_width) / 2
                    top = (self.slide_height -
                           self.image_display_height) / 2 - self.pic_top_offset

                if self.pic_per_page == 3 and j == 1:
                    # second image when paste three images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width / 3
                    top = (self.slide_height -
                           self.image_display_height) / 2 - self.pic_top_offset

                if self.pic_per_page == 3 and j == 2:
                    # third image when paste three images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width * 2 / 3
                    top = (self.slide_height -
                           self.image_display_height) / 2 - self.pic_top_offset

                if self.pic_per_page == 4 and j == 0:
                    # first image when paste four images to one slide
                    left = (self.slide_width / 2 -
                            self.image_display_width) / 2
                    top = (self.slide_height -
                           self.image_display_height) / 4 - self.pic_top_offset

                if self.pic_per_page == 4 and j == 1:
                    # second image when paste four images to one slide
                    left = ((self.slide_width / 2 - self.image_display_width) /
                            2) + self.slide_width / 2
                    top = (self.slide_height -
                           self.image_display_height) / 4 - self.pic_top_offset

                if self.pic_per_page == 4 and j == 2:
                    # thrid image when paste four images to one slide
                    left = (self.slide_width / 2 -
                            self.image_display_width) / 2
                    top = (self.slide_height - self.image_display_height
                           ) * 3 / 4 - self.pic_top_offset

                if self.pic_per_page == 4 and j == 3:
                    # fourth image when paste four images to one slide
                    left = ((self.slide_width / 2 - self.image_display_width) /
                            2) + self.slide_width / 2
                    top = (self.slide_height - self.image_display_height
                           ) * 3 / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 0:
                    # first image when paste six images to one slide
                    left = (self.slide_width / 3 -
                            self.image_display_width) / 2
                    top = (self.slide_height -
                           self.image_display_height) / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 1:
                    # second image when paste six images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width / 3
                    top = (self.slide_height -
                           self.image_display_height) / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 2:
                    # third image when paste six images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width * 2 / 3
                    top = (self.slide_height -
                           self.image_display_height) / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 3:
                    # fourth image when paste six images to one slide
                    left = (self.slide_width / 3 -
                            self.image_display_width) / 2
                    top = (self.slide_height - self.image_display_height
                           ) * 3 / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 4:
                    # fifth image when paste six images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width / 3
                    top = (self.slide_height - self.image_display_height
                           ) * 3 / 4 - self.pic_top_offset

                if self.pic_per_page == 6 and j == 5:
                    # sixth image when paste six images to one slide
                    left = ((self.slide_width / 3 - self.image_display_width) /
                            2) + self.slide_width * 2 / 3
                    top = (self.slide_height - self.image_display_height
                           ) * 3 / 4 - self.pic_top_offset

                self.add_picture(slide, file_name, left, top)

                # add text
                height_cm = 1
                height = util.Inches(height_cm / 2.54)
                width = self.image_display_width
                print(height)
                txBox = slide.shapes.add_textbox(left, top - height, width,
                                                 height)
                tf = txBox.text_frame
                pg = tf.paragraphs[0]
                pg.text = (file_name.replace(".png",
                                             "").replace(".PNG", "").replace(
                                                 ".jpg", ""))
                pg.alignment = PP_ALIGN.CENTER
                tf.vertical_anchor = MSO_ANCHOR.MIDDLE
                pg.font.size = Pt(20)
                pg.font.bold = True

        self.presentaition.save(self.output_filename)