Esempio n. 1
0
def CircleTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/CircleTest.pdf")

    # Set compression defaults to False
    writer.set_compression(False)

    # Set document metadata
    writer.set_information(title="Testing Circles")  # set optional information

    # Get document object
    document = writer.get_document()
    black = PDFColor()

    red = PDFColor(name='red')
    center = PDFCursor(100, 100)

    document.draw_circle(center, 10, black, red, style='F')

    green = PDFColor(name='green')
    center = PDFCursor(300, 300)
    document.draw_circle(center, 20, black, green, style='B', stroke="dotted")

    center = PDFCursor(350, 400)
    document.draw_circle(center, 30, None, None, size=2)

    # Close Document
    writer.close()
Esempio n. 2
0
def HtmlTest2():
    writer = PDFLite("generated/HTMLtest2.pdf")
    document = writer.get_document()

    document.add_text('Sample text')
    document.add_newline(2)


    red = PDFColor(name="red")
    blue = PDFColor(name='blue')
    green = PDFColor(name='green')

    normalfont = document.get_font()
    header1 = document.set_font('helvetica', style='B', size=22)
    coolfont = document.set_font('comic sans ms', style='', size=12)
    header2 = document.set_font('helvetica', style='I', size=18)

    html_text = open("bin/test.html")

    document.add_html(html_text,
                      context={"daytoday": " Thursday", "location": " California", "destination": " opera", "skiing": " at Stowe."},
                      formats={"h1": header1, "h2": header2, "red": red, "coolfont": coolfont, "p": normalfont,
                               'ul': normalfont, 'ol': normalfont, 'blue': blue, 'green': green}
                      )

    document.add_text("After HTML.")
    writer.close()
Esempio n. 3
0
def BarChartTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/BarChart.pdf"))

    # Set compression defaults to False
    writer.set_compression(True)

    # Set document metadata
    writer.set_information(
        title="Testing Bar Chart")  # set optional information

    # Get document object
    document = writer.get_document()

    cursor = PDFCursor(100, 50)
    data = [("Sunday", 11.5), ("Monday", 13.9), ("Tuesday", 15.1),
            ("Wednesday", 15.2), ("Thursday", 16.3), ("Friday", 18.0),
            ("Saturday", 12.1)]

    document.add_simple_bar_chart(data,
                                  cursor,
                                  400,
                                  300,
                                  "Blog Re-tweets By Day of the Week",
                                  axis_titles=("day",
                                               "percent chance of re-tweet"),
                                  y_axis_limits=(11, 19),
                                  y_axis_frequency=1,
                                  bar_border_colors=PDFColor(0, 0, 0),
                                  bar_fill_colors=PDFColor(183, 143, 207))

    cursor = PDFCursor(100, 400)
    document.add_simple_bar_chart(data,
                                  cursor,
                                  400,
                                  300,
                                  "Blog Re-tweets By Day of the Week",
                                  axis_titles=("day",
                                               "percent chance of re-tweet"),
                                  y_axis_limits=(11, 19),
                                  y_axis_frequency=1)

    # Close Document
    writer.close()
Esempio n. 4
0
def ArcTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/ArcTest.pdf"))

    # Set compression defaults to False
    writer.set_compression(False)

    # Set document metadata
    writer.set_information(title="Testing Arcs")  # set optional information

    # Get document object
    document = writer.get_document()
    black = PDFColor()

    center = PDFCursor(300, 300)
    radius = 50
    document.draw_circle(center, radius, black)

    red = PDFColor(name='red')
    starting_angle = 15
    arc_angle = 135

    document.draw_arc(center,
                      radius,
                      starting_angle,
                      arc_angle,
                      inverted=False,
                      border_color=red,
                      style='F')

    center = PDFCursor(300, 400)

    document.draw_arc(center,
                      radius,
                      starting_angle,
                      arc_angle,
                      inverted=True,
                      border_color=red)
    # Close Document
    writer.close()
Esempio n. 5
0
def GraphBackgroundTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/GraphBackgrounds.pdf"))

    # Set compression defaults to False
    writer.set_compression(False)

    # Set document metadata
    writer.set_information(title="Testing Graph Backgrounds")  # set optional information

    # Get document object
    background = PDFGraphBackground("B", 2, PDFColor(name="plum"), PDFColor(name="cornflowerblue"), 0.11, "dotted")


    document = writer.get_document()
    cursor = PDFCursor(100, 50)
    data = [{"series1": [(0, 100), (3600, 425), (7200, 550), (10800, 425), (14400, 500), (18000, 825)]},
           {"series2": [(0, 50), (3600, 240), (7200, 675), (10800, 775), (14400, 980)]}]

    document.add_line_graph(data, cursor, 400, 200, "Hits over Time", (0, 18000), (0, 1100), (3600, 100), ("time (s)", "count"), "Auto", background=background, legend="right")

    cursor = PDFCursor(100, 400)
    data = [{"series1": [(14.2, 215), (16.4, 325), (11.9, 185), (15.2, 332), (18.5, 406), (22.1, 522), (19.4, 412), (25.1, 614), (23.4, 544), (18.1, 421), (22.6, 445), (17.2, 408)]}]

    document.add_xy_scatter(data, cursor, 400, 200, "Ice Cream Sales vs Temperature", (10, 26), (180, 660), (1, 50), ("temperature", "sales"), "Auto", background=background, dots=1, legend="right")

    document.add_page()
    cursor = PDFCursor(100, 50)
    data = [{"Susan Smith": [("S", 47.5), ("M", 46.1), ("T", 48.3), ("W", 44.2), ("T", 46.7), ("F", 47.6), ("S", 46.3)]},
            {"Jane Doe": [("S", 38.2), ("M", 38.9), ("T", 39.2), ("W", 38.6), ("T", 40.1), ("F", 41.6), ("S", 42.2)]}
           ]

    document.add_multi_bar_chart(data, cursor, 400, 300, "Candidate Polls", axis_titles=("day", "percent vote"), y_axis_limits=(35, 50), y_axis_frequency=2, background=background)


    # Close Document
    writer.close()
Esempio n. 6
0
def TableTest():

    """ Functional test for text, paragraph, and page
    splitting.

    """

    data = [["Heading1", "Heading2", "Heading3"],
            ["Cell a2", "Cell b2", "Cell c2"],
            ["Cell a3", "Cell b3", "Cell c3"]]

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/TableTest.pdf")

    # If desired (in production code), set compression
    # writer.setCompression(True)

    # Set general information metadata
    writer.set_information(title="Testing Table")  # set optional information

    # Use get_document method to get the generated document object.
    document = writer.get_document()

    document.set_cursor(100, 100)

    document.set_font(family='arial', style='UB', size=12)
    underline = document.get_font()

    document.set_font(family='arial', size=12)
    default_font = document.get_font()
    # Example for adding short and long text and whitespaces
    mytable = document.add_table(3, 3)
    green = PDFColor(name='green')

    default = document.add_cell_format({'font': default_font, 'align': 'left', 'border': (0, 1)})
    justleft = document.add_cell_format({'left': (0, 1)})
    header_format = document.add_cell_format({'font': underline, 'align': 'right', 'border': (0, 1)})
    green_format = document.add_cell_format({'font': default_font, 'border': (0, 1), 'fill_color': green})

    #mytable.set_column_width(1, 200)
    #mytable.set_row_height(2, 200)

    mytable.write_row(0, 0, data[0], header_format)
    mytable.write_row(1, 0, data[1], justleft)
    mytable.write_row(2, 0, data[2], green_format)

    document.draw_table(mytable)
    document.add_newline(4)
    document.add_text("Testing followup text")

    # Close writer
    writer.close()
Esempio n. 7
0
def EllipseTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/EllipseTest.pdf")

    # Set compression defaults to False
    writer.set_compression(False)

    # Set document metadata
    writer.set_information(title="Testing Lines")  # set optional information

    # Get document object
    document = writer.get_document()

    color = PDFColor(name='red')
    center = PDFCursor(100, 100)
    radius = PDFCursor(20, 30)

    circle = PDFEllipse(document.session, document.page, center, radius, color)
    circle._draw()

    center.x = 200
    center.y = 200
    circle = PDFEllipse(document.session,
                        document.page,
                        center,
                        radius,
                        color,
                        style='F')
    circle._draw()

    center.x = 100
    center.y = 200
    radius.x = 40
    circle = PDFEllipse(document.session,
                        document.page,
                        center,
                        radius,
                        color,
                        size=3)
    circle._draw()

    # Close Document
    writer.close()
Esempio n. 8
0
def LinesTest():
    """ Functional tests for creating lines.

    """
    # Create PDFLite object
    writer = PDFLite("generated/LinesTest.pdf")

    # Set compression defaults to False
    writer.set_compression(False)

    # Set document metadata
    writer.set_information(title="Testing Lines")  # set optional information

    # Get document object
    document = writer.get_document()

    # Test add line by (x, y, x, y)
    document.add_line(20, 40, 300, 80)

    # Add Horizontal rule under text
    document.add_text("Testing")
    document.add_newline(1)
    document.draw_horizontal_line()

    # Create color Object, apply to fill color
    lightblue = PDFColor(name='lightblue')

    # Draw styled rectangle.
    document.set_fill_color(lightblue)
    document.draw_rectangle(150, 500, 300, 600, style='B')

    # Draw Dashed Line
    document.add_line(400, 250, 300, 500, stroke="dots")

    # Close Document
    writer.close()
Esempio n. 9
0
def HtmlTest(test_dir):
    writer = PDFLite(os.path.join(test_dir, "tests/HTMLtest.pdf"))
    document = writer.get_document()

    document.add_text('Sample text')
    document.add_newline(2)

    red = PDFColor(name="red")
    blue = PDFColor(name='blue')
    green = PDFColor(name='green')

    normalfont = document.get_font()
    header1 = document.set_font('helvetica', style='B', size=22)
    coolfont = document.set_font('comic sans ms', style='', size=12)
    header2 = document.set_font('helvetica', style='I', size=18)
    document.set_font(font=normalfont)

    html_text = """
                  <html>
                  <head><title>Test Title</title>
                        <script>document.write("Hello World!")</script>
                  </head>
                  <h1>My Week</h1>
                  <p>Today, the day is <span class="red coolfont" data-bind="daytoday"></span>, and it is sunny here in
                        <span class="green" data-bind="location"></span>. Honestly, it's almost always sunny. It
                        can get rather boring.</p>
                  <br/>
                  <h2>Things I miss</h2>
                  <ol type='I' ">
                  <li>Fall Carnivals</li>
                  <li>Skiing <span class='blue' data-bind="skiing"></span></li>
                  <li>Museums</li>
                  <li><p>And a whole bunch of other things, that I'm not sure if I just liked it because I was a kid,
                  or because it was actually a lot of fun.</p></li>
                  <li>Testing Unordered List</li>
                  <li>
                    <ul>
                    <li>One</li>
                    <li>Two</li>
                    <li>Three</li>
                    <li>Testing Blockquote:
                        <blockquote>"Computers are useless, they can only give you answers"</blockquote></li>
                    <li>After the quote</li>
                    </ul>
                    </li>
                  <li>After the List</li>
                  </ol>
                  <p>Next week I will go to the <span class="blue coolfont" data-bind="destination"></span>.....
                  <a href="http://www.google.com">Visit Google.com!</a> I hope it's fun.
                  </p>
                  </html>
                """

    document.add_html(html_text,
                      context={
                          "daytoday": " Thursday",
                          "location": " California",
                          "destination": " opera",
                          "skiing": " at Stowe."
                      },
                      formats={
                          "h1": header1,
                          "h2": header2,
                          "red": red,
                          "coolfont": coolfont,
                          "p": normalfont,
                          'ul': normalfont,
                          'ol': normalfont,
                          'blue': blue,
                          'green': green
                      })

    document.add_text("After HTML.")
    writer.close()
Esempio n. 10
0
def TextTest():
    """ Functional test for text, paragraph, and page
    splitting.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/TextTest.pdf")

    # If desired (in production code), set compression
    # writer.setCompression(True)

    # Set general information metadata
    writer.set_information(title="Testing Text")  # set optional information

    # Use get_document method to get the generated document object.
    document = writer.get_document()

    # Example for adding short and long text and whitespaces
    document.add_text("Testing")
    document.add_newline(4)
    document.add_text("Testing Again")
    document.add_newline()
    document.add_indent()
    document.add_text(
        "This should be enough text to test going over the edge of the \
        page, and having to wrap back around. Let's see if it works!")
    document.add_page()

    # Save existing font, define a new font, use it for a header
    normal_font = document.get_font()
    document.set_font('simfang', style='', size=24)
    header_font = document.get_font()
    document.add_newline(2)
    document.add_text("1.0 Testing a Header开窗透透气")

    # Change font back
    document.set_font(font=normal_font)
    document.add_newline(2)
    document.add_indent()
    document.add_text("And we're back to normal after the header.")
    document.add_newline(2)

    # Test decoration, and size changes
    document.set_font('helvetica', style='BUI', size=12)
    document.add_text("Testing Bold Underline Italic Style")
    document.add_newline(2)
    document.set_font("helvetica", style="BUI", size=24)
    document.add_text("Testing Bold Underline Italic Style Bigger")
    document.add_newline(2)
    document.set_font("helvetica", style="BUI", size=8)
    document.add_text("Testing Bold Underline Italic Style Smaller")

    # Test automatic page split
    document.set_font(font=normal_font)
    document.add_newline(5)
    document.add_text("What")
    document.add_newline(5)
    document.add_text("will")
    document.add_newline(5)
    document.add_text("happen")
    document.add_newline(5)

    # Create color Object, apply to fill color
    document.add_text("when")
    document.add_newline(5)
    lightblue = PDFColor(name='lightblue')
    document.set_text_color(lightblue)
    document.add_text("I")
    document.add_newline(5)
    document.add_text("go")
    document.add_newline(5)
    document.add_text("on")
    document.add_newline(5)
    document.add_text("to")
    document.add_newline(5)
    document.add_text("the")
    document.add_newline(5)
    document.add_text("next")
    document.add_newline(5)
    document.add_text("page?")
    document.add_newline()

    # Test Page splitting with paragraphs
    document.add_text("""Lorem Ipsum is simply dummy text of the printing and\
        typesetting industry. Lorem Ipsum has been the industry's\
        standard dummy text ever since the 1500s, when an unknown\
        printer took a galley of type and scrambled it to make a\
        type specimen book. It has survived not only five centuries,\
        but also the leap into electronic typesetting, remaining\
        essentially unchanged. It was popularised in the 1960s with\
        the release of Letraset sheets containing Lorem Ipsum passages,\
        and more recently with desktop publishing software like Aldus\
        PageMaker including versions of Lorem Ipsum.""")
    document.add_newline(2)
    document.double_space(0.5)
    document.add_text(
        """Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
        Cras et erat dolor. Nullam id aliquam neque. Vivamus nec nibh\
        orci. Nam faucibus dignissim diam eget tempor. Aenean neque sem,\
        euismod sit amet tellus nec, elementum varius diam. Vestibulum\
        in ultricies enim. Fusce imperdiet tempus lacus facilisis\
        vestibulum. Vestibulum urna magna, dignissim vel venenatis in,\
        pulvinar ac orci. Etiam vitae tempor metus, eu tristique mauris.\
        Donec tincidunt purus et scelerisque sagittis. Proin semper\
        facilisis vehicula.""")
    document.add_text(
        """Pellentesque rhoncus vestibulum turpis ut varius. Nunc a rutrum\
        est. Etiam sollicitudin rhoncus nisl, quis scelerisque felis\
        dignissim vitae. Maecenas rutrum quam at risus mattis congue. Sed\
        hendrerit nulla ac nunc consectetur suscipit. Fusce elementum\
        interdum nibh, et fermentum lacus egestas non. Sed consectetur\
        mollis tortor, eu aliquam leo tristique sit amet. Etiam nec lectus\
        magna. Nam faucibus scelerisque velit nec cursus. Ut a dolor\
        accumsan, gravida nunc vitae, luctus quam. Vestibulum quis gravida\
        quam. Proin feugiat urna ut rutrum facilisis. Vivamus gravida iaculis\
        nibh at feugiat.""")

    # Close writer
    writer.close()