Example #1
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()
Example #2
0
def HtmlTest2(test_dir):
    writer = PDFLite(os.path.join(test_dir, "tests/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)

    with open(os.path.join(test_dir, "test.html")) as fp:
        html_text = fp.read()

    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()
Example #3
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()
Example #4
0
def PieChartTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/PieChart.pdf"))

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

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

    # Get document object
    document = writer.get_document()
    cursor = PDFCursor(100, 50)
    data = [("English", 565004126), ("Chinese", 509965013), ("Spanish", 164968742),
            ("Arabic", 65365400), ("French", 59779525), ("Russian", 59700000),
            ("Japanese", 99182000), ("Portuguese", 82586600), ("German", 75422674),
            ("Korean", 39440000)]

    document.add_pie_chart(data, cursor, 400, 300, title="Languages Spoken on the Internet", legend="right")

    cursor = PDFCursor(100, 400)
    document.add_pie_chart(data, cursor, 400, 300, title="Languages Spoken on the Internet", labels=True)

    # Close Document
    writer.close()
Example #5
0
def BarChartTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/BarChart.pdf")

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

    # 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()
Example #6
0
def LineGraphTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/LineGraph.pdf"))

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

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

    # Get document object
    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=BasicBackground,
                            legend="right")

    cursor = PDFCursor(100, 400)
    document.add_line_graph(data,
                            cursor,
                            400,
                            300,
                            "Hits over Time",
                            None,
                            None, (3600, 50), ("time (s)", "count"),
                            "Auto",
                            background=BasicBackground,
                            dots=1)

    document.add_page()
    cursor = PDFCursor(100, 50)
    data = [{
        "series1": [(1, 100), (2, 200), (3, 150), (4, 125), (5, 170), (6, 190),
                    (7, 210)]
    }]

    document.add_line_graph(data, cursor, 200, 150, axis=False)

    # Close Document
    writer.close()
Example #7
0
def XYScatterPlotTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/XYScatterPlot.pdf"))

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

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

    # Get document object
    document = writer.get_document()
    cursor = PDFCursor(100, 50)
    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=BasicBackground, dots=1, legend="right")

    cursor = PDFCursor(100, 400)
    document.add_xy_scatter(data, cursor, 400, 200, "Ice Cream Sales vs Temperature", None, None, None, ("temperature", "sales"), "Auto", background=BasicBackground, dots=1, linear_regression=True, linear_regression_equation=True)

    # Close Document
    writer.close()
Example #8
0
def MultiBarChartTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/MultiBarChart.pdf"))

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

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

    # Get document object
    document = writer.get_document()

    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)

    cursor = PDFCursor(100, 400)
    document.add_multi_bar_chart(data, cursor, 400, 300, "Candidate Polls", ("day", "percent of votes"), y_axis_limits=(35, 50), y_axis_frequency=2, legend="right")

    # Close Document
    writer.close()
Example #9
0
def LineGraphTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/LineGraph.pdf")

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

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

    # Get document object
    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=BasicBackground,
        legend="right",
    )

    cursor = PDFCursor(100, 400)
    document.add_line_graph(
        data,
        cursor,
        400,
        300,
        "Hits over Time",
        None,
        None,
        (3600, 50),
        ("time (s)", "count"),
        "Auto",
        background=BasicBackground,
        dots=1,
    )

    document.add_page()
    cursor = PDFCursor(100, 50)
    data = [{"series1": [(1, 100), (2, 200), (3, 150), (4, 125), (5, 170), (6, 190), (7, 210)]}]

    document.add_line_graph(data, cursor, 200, 150, axis=False)

    # Close Document
    writer.close()
Example #10
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()
Example #11
0
def XYScatterPlotTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/XYScatterPlot.pdf")

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

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

    # Get document object
    document = writer.get_document()
    cursor = PDFCursor(100, 50)
    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=BasicBackground,
                            dots=1,
                            legend="right")

    cursor = PDFCursor(100, 400)
    document.add_xy_scatter(data,
                            cursor,
                            400,
                            200,
                            "Ice Cream Sales vs Temperature",
                            None,
                            None,
                            None, ("temperature", "sales"),
                            "Auto",
                            background=BasicBackground,
                            dots=1,
                            linear_regression=True,
                            linear_regression_equation=True)

    # Close Document
    writer.close()
Example #12
0
def JPGTest():
    """ Functional test for adding images.

    """

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

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

    # Set general information metadata
    writer.set_information(title="JPG Testing")  # 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("This should be before the image.")
    document.add_newline(1)

    mylogo = document.add_image("bin/example.jpg")
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This should be after")

    document.add_newline(1)
    document.draw_image(mylogo)

    document.add_text("There it is without a newline")

    # Close writer
    writer.close()
Example #13
0
def MultiBarChartTest():
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite("generated/MultiBarChart.pdf")

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

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

    # Get document object
    document = writer.get_document()

    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)

    cursor = PDFCursor(100, 400)
    document.add_multi_bar_chart(data,
                                 cursor,
                                 400,
                                 300,
                                 "Candidate Polls",
                                 ("day", "percent of votes"),
                                 y_axis_limits=(35, 50),
                                 y_axis_frequency=2,
                                 legend="right")

    # Close Document
    writer.close()
Example #14
0
def JustifyTest():
    """ Functional test for text, paragraph, and page
    splitting.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/JustifyTest.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.set_justification('right')
    document.add_text("Testing Right")
    document.add_text("Testing Right")
    document.add_newline(2)
    document.set_justification('center')
    document.add_text("In the middle")
    document.add_newline()
    document.add_text("Center")
    document.add_newline()
    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.set_justification('right')
    document.add_text("right")
    document.add_newline(2)
    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.""")

    # Close writer
    writer.close()
Example #15
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()
Example #16
0
def JPGTest():

    """ Functional test for adding images.

    """

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

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

    # Set general information metadata
    writer.set_information(title="JPG Testing")  # 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("This should be before the image.")
    document.add_newline(1)

    mylogo = document.add_image("bin/example.jpg")
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This should be after")

    document.add_newline(1)
    document.draw_image(mylogo)

    document.add_text("There it is without a newline")

    # Close writer
    writer.close()
Example #17
0
def JustifyTest():

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

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/JustifyTest.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.set_justification('right')
    document.add_text("Testing Right")
    document.add_text("Testing Right")
    document.add_newline(2)
    document.set_justification('center')
    document.add_text("In the middle")
    document.add_newline()
    document.add_text("Center")
    document.add_newline()
    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.set_justification('right')
    document.add_text("right")
    document.add_newline(2)
    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.""")

    # Close writer
    writer.close()
Example #18
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()
Example #19
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()
Example #20
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()
Example #21
0
def LandscapeTest(test_dir):
    """ Test landscape orientation & background images.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/Landscape.pdf"),
                     orientation="P")
    # If desired (in production code), set compression
    # writer.setCompression(True)

    # Set general information metadata
    writer.set_information(
        title="Testing Landscape")  # 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_page()
    document.change_page_orientation()
    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()
Example #22
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()
Example #23
0
def PNGTest(test_dir):
    """ Functional test for adding images.

    """
    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/PNGTest.pdf"))

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

    # Set general information metadata
    writer.set_information(title="PNG Testing")  # 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("This should be before the image.")
    document.add_newline(1)

    mylogo = document.add_image(os.path.join(test_dir, "example.png"))
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This should be after")

    document.add_newline(1)
    document.draw_image(mylogo)

    document.add_text("There it is without a newline")

    document.add_newline(3)
    apple = document.add_image(os.path.join(test_dir, 'apple_logo.png'))
    document.draw_image(apple)

    document.add_page()

    document.set_background_image(os.path.join(test_dir, "example.png"))

    document.add_text("This text, ")
    document.add_text("And this text")
    document.add_newline(2)
    document.add_text("Should be on the background.")

    # Close writer
    writer.close()
Example #24
0
def PNGTest(test_dir):

    """ Functional test for adding images.

    """
    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/PNGTest.pdf"))

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

    # Set general information metadata
    writer.set_information(title="PNG Testing")  # 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("This should be before the image.")
    document.add_newline(1)

    mylogo = document.add_image(os.path.join(test_dir, "example.png"))
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This should be after")

    document.add_newline(1)
    document.draw_image(mylogo)

    document.add_text("There it is without a newline")

    document.add_newline(3)
    apple = document.add_image(os.path.join(test_dir, 'apple_logo.png'))
    document.draw_image(apple)

    document.add_page()

    document.set_background_image(os.path.join(test_dir, "background.png"))

    document.add_text("This text, ")
    document.add_text("And this text")
    document.add_newline(2)
    document.add_text("Should be on the background.")

    # Close writer
    writer.close()
Example #25
0
def LandscapeTest(test_dir):

    """ Test landscape orientation & background images.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/Landscape.pdf"), orientation="P")
    # If desired (in production code), set compression
    # writer.setCompression(True)

    # Set general information metadata
    writer.set_information(title="Testing Landscape")  # 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_page()
    document.change_page_orientation()
    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()
Example #26
0
def EllipseTest(test_dir):
    """
    Functional test for drawing eclipses
    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/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()
Example #27
0
def LinesTest(test_dir):

    """ Functional tests for creating lines.

    """
    # Create PDFLite object
    writer = PDFLite(os.path.join(test_dir, "tests/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()
Example #28
0
def ListTest(test_dir):

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

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/ListTest.pdf"))

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

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

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

    # Make a header
    document.set_font(family='helvetica', style='B', size=24)
    document.add_text("This is my list!")
    document.add_newline(2)

    # Make a list
    document.set_font(family='helvetica', size=16)
    document.add_list("Testing1", "Testing2", "Testing3")
    document.add_newline(4)

    document.set_font(family='arial', size=18)
    document.start_block_indent()
    document.add_list("Arial didn't", "have native", "bullets", force=True)
    document.end_block_indent()

    document.add_newline(2)
    document.add_text("And this is my followup text")

    # Close writer
    writer.close()
Example #29
0
def ImageSizeTest():
    """ Functional test for adding images.

    """

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

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

    # Set general information metadata
    writer.set_information(
        title="PNG Size Testing")  # 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("This is the image")
    document.add_newline(1)

    mylogo = document.add_image("bin/apple_logo.png")
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This is the image smaller")
    document.draw_image(mylogo, width=100)
    document.add_newline(1)

    document.add_page()
    document.add_text("This is the image larger")
    document.draw_image(mylogo, width=300)
    document.add_newline(3)

    # Close writer
    writer.close()
Example #30
0
def ListTest():

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

    """

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

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

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

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

    # Make a header
    document.set_font(family='helvetica', style='B', size=24)
    document.add_text("This is my list!")
    document.add_newline(2)

    # Make a list
    document.set_font(family='helvetica', size=16)
    document.add_list("Testing1", "Testing2", "Testing3")
    document.add_newline(4)

    document.set_font(family='arial', size=18)
    document.start_block_indent()
    document.add_list("Arial didn't", "have native", "bullets", force=True)
    document.end_block_indent()

    document.add_newline(2)
    document.add_text("And this is my followup text")

    # Close writer
    writer.close()
Example #31
0
def ImageSizeTest(test_dir):
    """ Functional test for adding images.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/ImageSizeTest.pdf"))

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

    # Set general information metadata
    writer.set_information(title="PNG Size Testing")  # 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("This is the image")
    document.add_newline(1)

    mylogo = document.add_image(os.path.join(test_dir, "apple_logo.png"))
    document.draw_image(mylogo)
    document.add_newline(1)

    document.add_text("This is the image smaller")
    document.draw_image(mylogo, width=100)
    document.add_newline(1)

    document.add_page()
    document.add_text("This is the image larger")
    document.draw_image(mylogo, width=300)
    document.add_newline(3)

    # Close writer
    writer.close()
Example #32
0
def TransformTest():

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/Transform.pdf", orientation="P")
    # If desired (in production code), set compression
    writer.set_compression(False)

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

    # Use get_document method to get the generated document object.
    document = writer.get_document()
    
    document.add_text("Transform test")
    
    document.add_newline(4)

    text = PDFText(document.session, document.page, None)
    text._text('transform')
    
    text.cursor.x_plus(20)
    text.text_rotate(90)
    text._text('transform')
    
    text = PDFText(document.session, document.page, None)
    text.cursor.x_plus(20)
    text.text_rotate(180)
    text._text('transform')
    
    text = PDFText(document.session, document.page, None)
    text.cursor.x_plus(20)
    text.text_rotate(-90)
    text._text('transform')
    
    document.add_newline(5)

    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_scale(2, 0.5)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_scale(0.5, 2)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_skew(30, 0)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_skew(0, 30)
    text._text('transform')

    # Close writer
    writer.close()
Example #33
0
def UnderlineTest():
    """ Functional test for text, paragraph, and page
    splitting.

    """

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

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

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

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

    # Check underlines at sizes
    document.set_font('helvetica', style='U', size=8)
    document.add_text("Testing size 8, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=12)
    document.add_text("Testing size 12, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=16)
    document.add_text("Testing size 16, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=20)
    document.add_text("Testing size 20, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=24)
    document.add_text("Testing size 24, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=28)
    document.add_text("Testing size 28, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=32)
    document.add_text("Testing size 32, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=36)
    document.add_text("Testing size 36, normal")
    document.add_newline(2)

    document.add_page()

    # Check underlines with Bold
    document.set_font('helvetica', style='BU', size=8)
    document.add_text("Testing size 8, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=12)
    document.add_text("Testing size 12, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=16)
    document.add_text("Testing size 16, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=20)
    document.add_text("Testing size 20, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=24)
    document.add_text("Testing size 24, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=28)
    document.add_text("Testing size 28, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=32)
    document.add_text("Testing size 32, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=36)
    document.add_text("Testing size 36, bold")
    document.add_newline(2)

    # Close writer
    writer.close()
Example #34
0
from pypdflite.pdflite import PDFLite
from pypdflite.pdfobjects.pdfcolorscheme import PDFColorScheme
from pypdflite.pdfobjects.pdfcolor import PDFColor


Writer = PDFLite("LinesTest.pdf")
# Writer.setCompression(True)
Writer.setInformation(title="Testing Lines")  # set optional information
Document = Writer.getDocument()
Document.addLine(20, 40, 300, 80)

Document.addText("Testing")
Document.addNewline(1)
Document.drawHorizonalLine()

lightblue = PDFColor(name="lightblue")
newscheme = PDFColorScheme(fillcolor=lightblue)

Document.setColorScheme(newscheme)
Document.drawRectangle(150, 500, 300, 600, style="B")

Writer.close()
Example #35
0
def PageNumberTest():

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

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/PageNumberTest.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('helvetica', style='B', 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.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.""")

    document.add_page_numbers(font=normal_font, color=PDFColor(), text2=' of %s')
    # Close writer
    writer.close()
Example #36
0
def HtmlTest():
    writer = PDFLite("generated/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()
Example #37
0
def MarginTest(test_dir):
    """ Functional test for text, paragraph, and page
    splitting.

    """

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite(os.path.join(test_dir, "tests/MarginTest.pdf"))

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

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

    # Use get_document method to get the generated document object.
    document = writer.get_document()
    document.set_margins(20, 30, 20, 30)

    document.set_font("helvetica", size=20)
    # Add test text
    document.add_text("""|00 TTTT TTTTTT TTTTTT TTTTT TTTTT TTTTT TTTTT TTT|
                         |01.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |02.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |03.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |04.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |05.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |06.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |07.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |08.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |09.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |10.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |11.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |12.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |13.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |14.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |15.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |16.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |17.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |18.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |19.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |20.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |21.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |22.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |23.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |24.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |25.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |26.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |27.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |28.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |29.. .... .... .... ....
                      """)

    document.add_text(" Small words ")
    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.""")

    writer.close()
Example #38
0
def TransformTest():

    #Create PDFLITE object, initialize with path & filename.
    writer = PDFLite("generated/Transform.pdf", orientation="P")
    # If desired (in production code), set compression
    writer.set_compression(False)

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

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

    document.add_text("Transform test")

    document.add_newline(4)

    text = PDFText(document.session, document.page, None)
    text._text('transform')

    text.cursor.x_plus(20)
    text.text_rotate(90)
    text._text('transform')

    text = PDFText(document.session, document.page, None)
    text.cursor.x_plus(20)
    text.text_rotate(180)
    text._text('transform')

    text = PDFText(document.session, document.page, None)
    text.cursor.x_plus(20)
    text.text_rotate(-90)
    text._text('transform')

    document.add_newline(5)

    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_scale(2, 0.5)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_scale(0.5, 2)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_skew(30, 0)
    text._text('transform')

    document.add_newline(2)
    text = PDFText(document.session, document.page, None)
    text._text('transform  ')
    text.text_skew(0, 30)
    text._text('transform')

    # Close writer
    writer.close()
Example #39
0
def MarginTest():

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

    """

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

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

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

    # Use get_document method to get the generated document object.
    document = writer.get_document()
    document.set_margins(20, 30, 20, 30)

    document.set_font("helvetica", size=20)
    # Add test text
    document.add_text("""|00 TTTT TTTTTT TTTTTT TTTTT TTTTT TTTTT TTTTT TTT|
                         |01.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |02.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |03.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |04.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |05.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |06.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |07.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |08.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |09.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |10.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |11.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |12.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |13.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |14.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |15.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |16.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |17.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |18.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |19.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |20.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |21.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |22.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |23.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |24.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |25.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |26.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |27.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |28.. .... .... .... .... .... .... .... .... ...... .... .... .... .... .... .... .... .... ... |\
                         |29.. .... .... .... ....
                      """)

    document.add_text(" Small words ")
    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.""")

    writer.close()
Example #40
0
def UnderlineTest():

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

    """

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

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

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

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

    # Check underlines at sizes
    document.set_font('helvetica', style='U', size=8)
    document.add_text("Testing size 8, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=12)
    document.add_text("Testing size 12, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=16)
    document.add_text("Testing size 16, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=20)
    document.add_text("Testing size 20, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=24)
    document.add_text("Testing size 24, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=28)
    document.add_text("Testing size 28, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=32)
    document.add_text("Testing size 32, normal")
    document.add_newline(2)

    document.set_font('helvetica', style='U', size=36)
    document.add_text("Testing size 36, normal")
    document.add_newline(2)

    document.add_page()

    # Check underlines with Bold
    document.set_font('helvetica', style='BU', size=8)
    document.add_text("Testing size 8, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=12)
    document.add_text("Testing size 12, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=16)
    document.add_text("Testing size 16, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=20)
    document.add_text("Testing size 20, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=24)
    document.add_text("Testing size 24, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=28)
    document.add_text("Testing size 28, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=32)
    document.add_text("Testing size 32, bold")
    document.add_newline(2)

    document.set_font('helvetica', style='BU', size=36)
    document.add_text("Testing size 36, bold")
    document.add_newline(2)

    # Close writer
    writer.close()
Example #41
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()
Example #42
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()