예제 #1
0
    def render(self, doc: docx.document.Document) -> None:
        if self.titre:
            doc.add_paragraph(self.titre, "Illustration Index Heading")
        paragraph = doc.add_paragraph()
        run = paragraph.add_run()
        fldChar = OxmlElement('w:fldChar')  # creates a new element
        fldChar.set(qn('w:fldCharType'), 'begin')  # sets attribute on element
        instrText = OxmlElement('w:instrText')
        instrText.set(qn('xml:space'), 'preserve')  # sets attribute on element
        instrText.text = self.command  # change 1-3 depending on heading levels you need

        fldChar2 = OxmlElement('w:fldChar')
        fldChar2.set(qn('w:fldCharType'), 'separate')
        fldChar3 = OxmlElement('w:t')
        fldChar3.text = "Right-click to update field."
        fldChar2.append(fldChar3)

        fldChar4 = OxmlElement('w:fldChar')
        fldChar4.set(qn('w:fldCharType'), 'end')

        r_element = run._r
        r_element.append(fldChar)
        r_element.append(instrText)
        r_element.append(fldChar2)
        r_element.append(fldChar4)
        p_element = paragraph._p
예제 #2
0
 def render(self, doc: docx.document.Document) -> None:
     table = doc.add_table(self.rows, self.cols, self.style)
     self.callback.render(table)
     if self.caption:
         doc.add_paragraph(
             Docx.DEFAULT_TABLEAU + self.key + " : " + self.caption,
             Docx.DEFAULT_STYLE_LEGENDE_TABLEAU)
예제 #3
0
    def render(self, doc: docx.document.Document) -> None:
        imagePath = 'images/' + self.filename

        # autosize en fonction de l'orientation
        last_section = doc.sections[-1]
        if last_section.orientation == WD_ORIENTATION.LANDSCAPE:  # @UndefinedVariable pylint: disable=no-member
            width = self.DEFAULT_WIDTH_LANDSCAPE
        else:
            width = self.width

        # ajuster de sorte que l'image ne sorte pas de la page verticalement
        im = Image.open(imagePath)
        ratio = im.size[0] / float(im.size[1])
        computedHeight = width / ratio
        if last_section.orientation == WD_ORIENTATION.LANDSCAPE:  # @UndefinedVariable pylint: disable=no-member
            if computedHeight > self.MAX_HEIGHT or (
                    self.height and self.height > self.MAX_HEIGHT):
                width = None
                height = self.MAX_HEIGHT
            else:
                height = self.height
        else:
            if computedHeight > int(self.MAX_HEIGHT_PORTRAIT) or (
                    self.height and self.height > self.MAX_HEIGHT_PORTRAIT):
                width = None
                height = self.MAX_HEIGHT_PORTRAIT
            else:
                height = self.height

        doc.add_picture(imagePath, width, height)
        if self.caption:
            doc.add_paragraph(
                Docx.DEFAULT_FIGURE + self.key + " : " + self.caption,
                Docx.DEFAULT_STYLE_LEGENDE_FIGURE)
예제 #4
0
 def render(self, doc: docx.document.Document) -> None:
     last_section = doc.sections[-1]
     last_orientation = last_section.orientation
     s = doc.add_section(self.start_type)
     if not last_orientation == self.orientation:
         new_width, new_height = s.page_height, s.page_width
         s.orientation, s.page_height, s.page_width = self.orientation, new_height, new_width
예제 #5
0
 def render(self, _: Paragraph, doc: docx.document.Document) -> None:
     doc.add_paragraph(self.text, self.style)
예제 #6
0
 def render(self, doc: docx.document.Document) -> None:
     doc.add_page_break()
예제 #7
0
 def render(self, doc: docx.document.Document) -> None:
     p = doc.add_paragraph(self.text, self.style)
     for obj in self.subs:
         obj.render(p, doc)