def test_write_document(self):

        pdf = Document()
        page = Page()
        pdf.append_page(page)

        # layout
        layout = MultiColumnLayout(page, number_of_columns=2)

        #
        # add title
        layout.add(
            Paragraph(
                """
                Help the person find their way home by colouring in a path through the stepping stones by making a sentence.  
                A really fun way to practice the alphabet!
                """,
                font_color=X11Color("SlateGray"),
                font_size=Decimal(8),
            ))

        seq = [x for x in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
        layout.add(
            SteppingStonePuzzle(
                seq,
                seq,
                "https://icons.iconarchive.com/icons/chanut/role-playing/128/King-icon.png",
                "https://icons.iconarchive.com/icons/chanut/role-playing/128/Castle-icon.png",
            ))

        # go to next column
        layout.switch_to_next_column()

        # add title
        layout.add(
            Paragraph(
                "Stepping Stones",
                font_size=Decimal(20),
                font_color=X11Color("YellowGreen"),
            ))

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # determine output location
        out_file = self.output_dir / ("output.pdf")

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create document
        pdf = Document()

        # add page
        page = Page()
        pdf.append_page(page)

        layout = MultiColumnLayout(page, number_of_columns=2)

        layout.add(Heading("The Raven", font_size=Decimal(20)))
        layout.add(
            Paragraph(
                "Edgar Allen Poe",
                font="Helvetica-Oblique",
                font_size=Decimal(8),
                font_color=X11Color("SteelBlue"),
            )
        )
        for i in range(0, 100):
            layout.add(
                Heading("Heading %d" % i, font_size=Decimal(20), outline_level=1)
            )
            for _ in range(0, random.choice([10, 20, 3])):
                layout.add(
                    Paragraph(
                        "Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore- While I nodded, nearly napping, suddenly there came a tapping, As of some one gently rapping, rapping at my chamber door. Tis some visitor, I muttered, tapping at my chamber door- Only this and nothing more.",
                        font_size=Decimal(12),
                        font_color=X11Color("SlateGray"),
                        horizontal_alignment=Alignment.LEFT,
                    )
                )

        # determine output location
        out_file = self.output_dir / "output.pdf"

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create document
        pdf = Document()

        # add page
        page = Page()
        pdf.append_page(page)

        layout = MultiColumnLayout(page, number_of_columns=2)
        layout.add(
            Paragraph(
                "The Raven",
                font_size=Decimal(20),
                font="Helvetica-Oblique",
                font_color=HexColor("708090"),
            ))

        layout.add(
            Paragraph(
                """Once upon a midnight dreary, while I pondered, weak and weary,
                                Over many a quaint and curious volume of forgotten lore-
                                While I nodded, nearly napping, suddenly there came a tapping,
                                As of some one gently rapping, rapping at my chamber door.
                                'Tis some visitor,' I muttered, 'tapping at my chamber door-
                                Only this and nothing more.'""",
                text_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))

        # determine output location
        out_file = self.output_dir / "output.pdf"

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)
Ejemplo n.º 4
0
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create empty document
        pdf: Document = Document()

        # create empty page
        page: Page = Page()

        # add page to document
        pdf.append_page(page)

        # add Image
        layout = MultiColumnLayout(page)

        # add image
        layout.add(
            Image(
                "https://images.unsplash.com/photo-1550155864-3033f844da36?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80",
                width=Decimal(256),
            )
        )
        layout.switch_to_next_column()

        # add title
        layout.add(
            Paragraph(
                "Love you more",
                font_color=X11Color("Crimson"),
                font="Helvetica-Bold",
                font_size=Decimal(20),
            )
        )
        layout.add(
            Paragraph(
                """When I say I love you more,
                                I don't just mean I love you more
                                than you love me. I mean I love
                                you more than the bad days
                                ahead of us. I love you more
                                than any fight we will ever have.
                                I love you more than the distance between us.
                                I love you more than any obstacle that
                                could ever try and come
                                between us. I love you the most.
                                """,
                respect_newlines_in_text=True,
            )
        )
        layout.add(
            Paragraph(
                """yours, most sincerely
                                JS
                             """,
                font_color=X11Color("SlateGray"),
                font="Helvetica-Bold",
                font_size=Decimal(8),
                respect_newlines_in_text=True,
            )
        )

        # write
        file = self.output_dir / "output.pdf"
        with open(file, "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, pdf)

        return True
Ejemplo n.º 5
0
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create document
        pdf = Document()

        # add page
        page = Page()
        pdf.append_page(page)

        layout = MultiColumnLayout(page)

        # background
        self._write_background(page)

        # table
        avatar_urls = [
            "https://avatars.githubusercontent.com/u/" + str(x)
            for x in self.FIRST_100_STARS
        ]
        t = Table(number_of_columns=4, number_of_rows=25)
        for s in avatar_urls[0 : (4 * 25)]:
            im = PILImage.open(requests.get(s, stream=True).raw)
            t.add(Image(im, width=Decimal(20), height=Decimal(20)))
        t.set_padding_on_all_cells(Decimal(2), Decimal(2), Decimal(2), Decimal(2))
        t.no_borders()
        layout.add(t)

        layout.add(
            Paragraph(
                "100 stars!",
                font="Helvetica-Bold",
                font_size=Decimal(20),
                font_color=self.ACCENT_COLOR_1,
                horizontal_alignment=Alignment.CENTERED,
            )
        )

        # next column
        layout.switch_to_next_column()

        # paragraph
        layout.add(
            Paragraph(
                "Thank you,",
                font="Helvetica-Bold",
                font_size=Decimal(20),
                font_color=self.ACCENT_COLOR_1,
            )
        )
        layout.add(
            Paragraph(
                "Your support and encouragement have always been the driving factors in the development of pText. "
                "I want you to know that I value your appreciation immensely!"
            )
        )
        layout.add(
            Paragraph(
                "-- Joris Schellekens",
                font="Helvetica-Oblique",
                font_size=Decimal(8),
                font_color=self.ACCENT_COLOR_2,
            )
        )

        layout.add(
            Barcode(
                data="https://github.com/jorisschellekens/ptext-release/stargazers",
                type=BarcodeType.QR,
                width=Decimal(128),
                stroke_color=self.ACCENT_COLOR_1,
            )
        )

        # footer
        rectangle_box = Rectangle(
            Decimal(0),
            Decimal(0),
            page.get_page_info().get_width(),
            page.get_page_info().get_height() * Decimal(0.1),
        )
        Shape(
            LineArtFactory.rectangle(rectangle_box),
            fill_color=self.ACCENT_COLOR_1,
            stroke_color=self.ACCENT_COLOR_1,
            line_width=Decimal(1),
        ).layout(page, rectangle_box)

        rectangle_box = Rectangle(
            Decimal(0),
            page.get_page_info().get_height() * Decimal(0.1),
            page.get_page_info().get_width(),
            Decimal(2),
        )
        Shape(
            LineArtFactory.rectangle(rectangle_box),
            fill_color=self.ACCENT_COLOR_2,
            stroke_color=self.ACCENT_COLOR_2,
            line_width=Decimal(1),
        ).layout(page, rectangle_box)

        # determine output location
        out_file = self.output_dir / "output.pdf"

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)

        with open(out_file, "rb") as in_file_handle:
            PDF.loads(in_file_handle)
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create empty document
        pdf: Document = Document()

        # create empty page
        page: Page = Page()

        # add page to document
        pdf.append_page(page)

        # set layout
        layout = MultiColumnLayout(page)

        # add chart
        layout.add(Chart(self._create_plot()))

        layout.switch_to_next_column()

        # add Heading
        layout.add(
            Heading("3D Plot",
                    font_color=X11Color("Orange"),
                    font_size=Decimal(20)))
        layout.add(
            Paragraph(
                "Demonstrates plotting a 3D surface colored with the coolwarm color map. "
                "The surface can be made opaque by using antialiased=False."))
        layout.add(
            Paragraph(
                "Check out https://python-graph-gallery.com/ for more wonderful examples of plots in Python."
            ))
        layout.add(
            Barcode(
                data="https://python-graph-gallery.com/",
                type=BarcodeType.QR,
                stroke_color=X11Color("Orange"),
            ))

        # write
        file = self.output_dir / "output.pdf"
        with open(file, "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, pdf)

        return True
Ejemplo n.º 7
0
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create document
        pdf = Document()

        # add page
        page = Page()
        pdf.append_page(page)

        # first layer, displaying a raven
        layout = SingleColumnLayout(page)
        for _ in range(0, 12):
            layout.add(Paragraph(" ", respect_spaces_in_text=True))
        layout.add(
            Image(
                "https://cdn3.vectorstock.com/i/1000x1000/03/47/black-raven-on-white-background-vector-4780347.jpg"
            ))

        # second layer, displaying the poem
        layout = MultiColumnLayout(page, number_of_columns=2)
        layout.add(
            Paragraph(
                "The Raven",
                font_size=Decimal(20),
                font="Helvetica-Oblique",
                font_color=HexColor("708090"),
            ))
        layout.add(
            Paragraph(
                """Once upon a midnight dreary, while I pondered, weak and weary,
                                Over many a quaint and curious volume of forgotten lore-
                                While I nodded, nearly napping, suddenly there came a tapping,
                                As of some one gently rapping, rapping at my chamber door.
                                'Tis some visitor,' I muttered, 'tapping at my chamber door-
                                Only this and nothing more.'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Ah, distinctly I remember it was in the bleak December;
                                And each separate dying ember wrought its ghost upon the floor.
                                Eagerly I wished the morrow;-vainly I had sought to borrow
                                From my books surcease of sorrow-sorrow for the lost Lenore-
                                For the rare and radiant maiden whom the angels name Lenore-
                                Nameless here for evermore.""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """And the silken, sad, uncertain rustling of each purple curtain
                                Thrilled me-filled me with fantastic terrors never felt before;
                                So that now, to still the beating of my heart, I stood repeating
                                'Tis some visitor entreating entrance at my chamber door-
                                Some late visitor entreating entrance at my chamber door;-
                                This it is and nothing more.'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Presently my soul grew stronger; hesitating then no longer,
                                'Sir,' said I, 'or Madam, truly your forgiveness I implore;
                                But the fact is I was napping, and so gently you came rapping,
                                And so faintly you came tapping, tapping at my chamber door,
                                That I scarce was sure I heard you'-here I opened wide the door;-
                                Darkness there and nothing more.""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.switch_to_next_column()
        layout.add(
            Paragraph(
                """Deep into that darkness peering, long I stood there wondering, fearing,
                                Doubting, dreaming dreams no mortal ever dared to dream before;
                                But the silence was unbroken, and the stillness gave no token,
                                And the only word there spoken was the whispered word, 'Lenore?'
                                This I whispered, and an echo murmured back the word, 'Lenore!'-
                                Merely this and nothing more.""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Back into the chamber turning, all my soul within me burning,
                                Soon again I heard a tapping somewhat louder than before.
                                'Surely,' said I, 'surely that is something at my window lattice;
                                Let me see, then, what thereat is, and this mystery explore-
                                Let my heart be still a moment and this mystery explore;-
                                'Tis the wind and nothing more!'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Open here I flung the shutter, when, with many a flirt and flutter,
                                In there stepped a stately Raven of the saintly days of yore;
                                Not the least obeisance made he; not a minute stopped or stayed he;
                                But, with mien of lord or lady, perched above my chamber door-
                                Perched upon a bust of Pallas just above my chamber door-
                                Perched, and sat, and nothing more.""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Then this ebony bird beguiling my sad fancy into smiling,
                                By the grave and stern decorum of the countenance it wore,
                                'Though thy crest be shorn and shaven, thou,' I said, 'art sure no craven,
                                Ghastly grim and ancient Raven wandering from the Nightly shore-
                                Tell me what thy lordly name is on the Night's Plutonian shore!'
                                Quoth the Raven 'Nevermore.'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """Much I marvelled this ungainly fowl to hear discourse so plainly,
                                Though its answer little meaning-little relevancy bore;
                                For we cannot help agreeing that no living human being
                                Ever yet was blessed with seeing bird above his chamber door-
                                Bird or beast upon the sculptured bust above his chamber door,
                                With such name as 'Nevermore.'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        layout.add(
            Paragraph(
                """But the Raven, sitting lonely on the placid bust, spoke only
                    That one word, as if his soul in that one word he did outpour.
                    Nothing farther then he uttered-not a feather then he fluttered-
                    Till I scarcely more than muttered 'Other friends have flown before-
                    On the morrow he will leave me, as my Hopes have flown before.'
                    Then the bird said 'Nevermore.'""",
                horizontal_alignment=Alignment.CENTERED,
                font_size=Decimal(7),
                respect_newlines_in_text=True,
            ))
        # determine output location
        out_file = self.output_dir / "output.pdf"

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)

        with open(out_file, "rb") as in_file_handle:
            PDF.loads(in_file_handle)
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create empty document
        pdf: Document = Document()

        # create empty page
        page: Page = Page()

        # add page to document
        pdf.append_page(page)

        # add Image
        layout = MultiColumnLayout(page)

        layout.add(
            Paragraph(
                "Rose",
                font_color=X11Color("MistyRose"),
                font_size=Decimal(20),
                font="Helvetica-Bold",
            )
        )
        layout.add(
            Paragraph(
                "A rose is a woody perennial flowering plant of the genus Rosa, in the family Rosaceae, or the flower it bears. "
                "There are over three hundred species and tens of thousands of cultivars. "
            )
        )
        layout.add(
            Paragraph(
                "They form a group of plants that can be erect shrubs, climbing, or trailing, with stems that are often armed with sharp prickles. "
                "Flowers vary in size and shape and are usually large and showy, "
                "in colours ranging from white through yellows and reds."
            )
        )
        layout.add(
            Paragraph(
                "Most species are native to Asia, with smaller numbers native to Europe, North America, and northwestern Africa. "
                "Species, cultivars and hybrids are all widely grown for their beauty and often are fragrant. "
            )
        )
        layout.add(
            Paragraph("Roses have acquired cultural significance in many societies. ")
        )
        layout.add(
            Paragraph(
                "Rose plants range in size from compact, miniature roses, to climbers that can reach seven meters in height. "
                "Different species hybridize easily, and this has been used in the development of the wide range of garden roses."
            )
        )

        # add image
        im = PILImage.open(
            requests.get(
                "https://images.unsplash.com/photo-1597826368522-9f4cb5a6ba48?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw",
                stream=True,
            ).raw
        )
        layout.add(Image(im, width=Decimal(256)))

        # add UnorderedList
        layout.add(Paragraph("The genus Rosa is subdivided into four subgenera:"))
        layout.add(
            UnorderedList()
            .add(Paragraph("Hulthemia", padding_bottom=Decimal(2)))
            .add(Paragraph("Hesperrhodos", padding_bottom=Decimal(2)))
            .add(Paragraph("Platyrhodon", padding_bottom=Decimal(2)))
            .add(Paragraph("Rosa", padding_bottom=Decimal(2)))
            .add(
                UnorderedList()
                .add(Paragraph("Banksianae"))
                .add(Paragraph("Bracteatae"))
                .add(Paragraph("Caninae"))
                .add(Paragraph("Carolinae"))
                .add(Paragraph("Chinensis"))
                .add(Paragraph("Gallicanae"))
                .add(Paragraph("Gymnocarpae"))
                .add(Paragraph("Laevigatae"))
                .add(Paragraph("Pimpinellifoliae"))
                .add(Paragraph("Rosa"))
                .add(Paragraph("Synstylae"))
            )
        )
        # write
        file = self.output_dir / "output.pdf"
        with open(file, "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, pdf)

        return True
Ejemplo n.º 9
0
    def test_write_document(self):

        words = [
            "COW",
            "PUPPY",
            "TURTLE",
            "PARROT",
            "SNAKE",
            "GOLDFISH",
            "HAMSTER",
            "KITTEN",
            "TURKEY",
            "DOVE",
            "HORSE",
            "BEE"
            "RABBIT",
            "DUCK",
            "SHRIMP",
            "PIG",
            "GOAT",
            "CRAB",
            "DOG",
            "DEER",
            "CAT",
            "MOUSE",
            "ELEPHANT",
            "LION",
            "PENGUIN",
            "SPARROW",
            "STORK",
            "HAWK",
        ]

        pdf = Document()
        page = Page()
        pdf.append_page(page)

        # layout
        layout = MultiColumnLayout(page, number_of_columns=2)

        # add title
        layout.add(
            Paragraph(
                """
                Word scrambles or anagrams are an excellent way of helping children 
                with their spelling as they have to recognise letter patterns. 
                They are also a fun way of testing knowledge on a subject. 
                We have word scrambles on lots of topics ready to print for home or classroom.
                """,
                font_color=X11Color("SlateGray"),
                font_size=Decimal(8),
            ))

        # add table
        t = Table(number_of_rows=len(words), number_of_columns=2)
        for i, w in enumerate(words):
            # shuffle word
            permuted_word = w
            while permuted_word == w:
                letters = [x for x in w]
                random.shuffle(letters)
                permuted_word = "".join([x for x in letters])
            t.add(
                TableCell(
                    Paragraph(str(i + 1) + ". " + permuted_word),
                    border_top=False,
                    border_right=False,
                    border_left=False,
                    border_bottom=False,
                ))
            # empty column
            t.add(
                TableCell(
                    Paragraph(""),
                    border_top=False,
                    border_right=False,
                    border_left=False,
                ))

        layout.add(t)

        # go to next column
        layout.switch_to_next_column()

        # add title
        layout.add(
            Paragraph(
                "Word Scramble",
                font_size=Decimal(20),
                font_color=X11Color("YellowGreen"),
            ))

        # add Image
        layout.add(
            Image(
                "https://www.how-to-draw-funny-cartoons.com/images/cartoon-tree-012.jpg"
            ))

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # determine output location
        out_file = self.output_dir / ("output.pdf")

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)
    def test_write_document(self):

        words = [
            "COW",
            "PUPPY",
            "TURTLE",
            "PARROT",
            "SNAKE",
            "GOLDFISH",
            "HAMSTER",
            "KITTEN",
            "TURKEY",
            "DOVE",
            "HORSE",
            "BEE"
            "RABBIT",
            "DUCK",
            "SHRIMP",
            "PIG",
            "GOAT",
            "CRAB",
            "DOG",
            "DEER",
            "CAT",
            "MOUSE",
            "ELEPHANT",
            "LION",
            "PENGUIN",
            "SPARROW",
            "STORK",
            "HAWK",
        ]
        ws = WordSearch(words)

        pdf = Document()
        page = Page()
        pdf.append_page(page)

        # layout
        layout = MultiColumnLayout(page, number_of_columns=2)

        # add title
        layout.add(
            Paragraph(
                """
                A word search, word find, word seek, 
                word sleuth or mystery word puzzle is a word game that consists of the letters of words placed in a grid, 
                which usually has a rectangular or square shape.
                The objective of this puzzle is to find and mark all the words hidden inside the box.
                """,
                font_color=X11Color("SlateGray"),
            ))

        # add grid
        layout.add(ws)

        # go to next column
        layout.switch_to_next_column()

        # add title
        layout.add(
            Paragraph("Word Search",
                      font_size=Decimal(20),
                      font_color=X11Color("YellowGreen")))

        # add list
        ul = UnorderedList()
        for w in words:
            ul.add(Paragraph(w))
        layout.add(ul)

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # determine output location
        out_file = self.output_dir / ("output.pdf")

        # attempt to store PDF
        with open(out_file, "wb") as in_file_handle:
            PDF.dumps(in_file_handle, pdf)
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create empty document
        pdf: Document = Document()

        # create empty page
        page: Page = Page()

        # add page to document
        pdf.append_page(page)

        # set layout
        layout = MultiColumnLayout(page)

        # add chart
        import numpy as np

        # create data
        x = np.random.rand(15)
        y = x + np.random.rand(15)
        z = x + np.random.rand(15)
        z = z * z

        layout.add(
            Heading(
                "#197 Available color palettes with Matplotlib",
                font_size=Decimal(20),
                font_color=X11Color("SteelBlue"),
            ))

        # Use it with a call in cmap
        layout.add(
            Heading(
                "1.0 BuPu",
                font_size=Decimal(16),
                font_color=X11Color("DarkBlue"),
                outline_level=1,
            ))
        MatPlotLibPlot.scatter(
            x,
            y,
            s=z * 2000,
            c=x,
            cmap="BuPu",
            alpha=0.4,
            edgecolors="grey",
            linewidth=2,
        )
        layout.add(Chart(MatPlotLibPlot.gcf()))

        # You can reverse it:
        layout.add(
            Heading(
                "1.1 Inferno",
                font_size=Decimal(16),
                font_color=X11Color("DarkBlue"),
                outline_level=1,
            ))
        MatPlotLibPlot.scatter(
            x,
            y,
            s=z * 2000,
            c=x,
            cmap="inferno",
            alpha=0.4,
            edgecolors="grey",
            linewidth=2,
        )
        layout.add(Chart(MatPlotLibPlot.gcf()))

        # add explanation
        layout.switch_to_next_column()
        layout.add(
            Paragraph(
                "Post #196 describes how to pick up a single color when working with python and matplotlib. "
                "This post aims to describe a few color palette that are provided, and thus make your life easier when plotting several color. "
                "There are 3 types of color palettes: Sequential, Discrete and Diverging. Here are a few explanations for each:"
            ))

        # OTHER: viridis / inferno / plasma / magma
        layout.add(
            Heading(
                "1.2 Plasma",
                font_size=Decimal(16),
                font_color=X11Color("DarkBlue"),
                outline_level=1,
            ))
        MatPlotLibPlot.scatter(
            x,
            y,
            s=z * 2000,
            c=x,
            cmap="plasma",
            alpha=0.4,
            edgecolors="grey",
            linewidth=2,
        )
        layout.add(Chart(MatPlotLibPlot.gcf()))

        layout.add(
            Heading(
                "2.0 Acknowledgements",
                font_size=Decimal(16),
                font_color=X11Color("DarkBlue"),
            ))
        layout.add(
            Paragraph(
                "Check out https://python-graph-gallery.com/ for more wonderful examples of plots in Python."
            ))
        layout.add(
            Barcode(
                data="https://python-graph-gallery.com/",
                type=BarcodeType.QR,
                stroke_color=X11Color("YellowGreen"),
            ))

        # write
        file = self.output_dir / "output.pdf"
        with open(file, "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, pdf)

        return True
    def test_write_document(self):

        # create output directory if it does not exist yet
        if not self.output_dir.exists():
            self.output_dir.mkdir()

        # create empty document
        pdf: Document = Document()

        # create empty page
        page: Page = Page()

        # add page to document
        pdf.append_page(page)

        # set layout
        layout = MultiColumnLayout(page)

        # add chart
        layout.add(Chart(self._create_plot()))

        layout.switch_to_next_column()

        # add Heading
        layout.add(
            Heading(
                "3D Density Chart",
                font_color=X11Color("YellowGreen"),
                font_size=Decimal(20),
            )
        )
        layout.add(
            Paragraph(
                "The mplot3D toolkit of Matplotlib allows to easily create 3D scatterplots. "
                "Note that most of the customisations presented in the Scatterplot section will work in 3D as well. "
                "The result can be a bit disappointing since each marker is represented as a dot, not as a sphere.."
            )
        )
        layout.add(
            Paragraph(
                "Check out https://python-graph-gallery.com/ for more wonderful examples of plots in Python."
            )
        )
        layout.add(
            Barcode(
                data="https://python-graph-gallery.com/",
                type=BarcodeType.QR,
                stroke_color=X11Color("YellowGreen"),
            )
        )

        # write
        file = self.output_dir / "output.pdf"
        with open(file, "wb") as pdf_file_handle:
            PDF.dumps(pdf_file_handle, pdf)

        return True