コード例 #1
0
 def generate_book(self, now_, cameras_):
     page_width = 260
     page_height = 200
     text_large = 15
     text_regular = 11
     title = 'now'
     edition = '{} UTC'.format(now_)
     pdf = FPDF('P', 'mm', (page_width, page_height))
     pdf.set_author('Birk Weiberg')
     pdf.set_title('{} = {}'.format(title, edition))
     pdf.set_margins(0, 0, 0)
     pdf.add_page()
     pdf.set_font('Arial', 'B', text_large)
     pdf.cell(0, 0.5 * page_height, '', 0, 1, 'C')
     pdf.cell(0, 0, title, 0, 0, 'C')
     pdf.add_page()
     pdf.add_page()
     pdf.cell(0, 0.5 * page_height, '', 0, 1, 'C')
     pdf.cell(0, 0, edition, 0, 0, 'C')
     pdf.add_page()
     pdf.set_font('Arial', '', text_regular)
     pdf.cell(0, 0.8 * page_height, '', 0, 1, 'C')
     pdf.cell(0, 0.5 * text_regular, 'Birk Weiberg, 2016', 0, 1, 'C')
     pdf.cell(0, 0.5 * text_regular, 'https://github.com/birk/now-book', 0,
              1, 'C')
     pdf.add_page()
     for c in cameras_:
         pdf.add_page()
         pdf.add_page()
         try:
             w, h = self.get_prop_size(c.file, 0.7 * page_width,
                                       0.6 * page_height)
         except (OSError) as exc:
             print('Error loading image from {} - {}'.format(
                 c.location, c.url))
             return
         pdf.image(c.file, 0.5 * (page_width - w), 0.4 * (page_height - h),
                   w, h)
         pdf.cell(0, 0.85 * page_height, '', 0, 1, 'C')
         pdf.cell(0, 0.5 * text_regular, c.location_str, 0, 1, 'C')
         pdf.link(0.4 * page_width, 0.84 * page_height, 0.2 * page_width,
                  0.04 * page_height, c.link)
     pdf.add_page()
     pdf.add_page()
     while pdf.page % 4 != 0:
         pdf.add_page()
     file_name = '{}-{}.pdf'.format(
         title,
         str(now_).replace(' ', '-').replace(':', '-'))
     pdf.output(file_name, 'F')
     print('now-book: {}'.format(file_name))
コード例 #2
0
def test_link_alt_text(tmp_path):
    """
    It can be tested that the reference file for this test
    has the link description read out loud by the NVDA screen reader
    when opened with Adobe Acrobat Reader.
    """
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("helvetica", size=24)
    text = "PyFPDF/fpdf2"
    pdf.text(x=80, y=150, txt=text)
    width = pdf.get_string_width(text)
    line_height = 10
    pdf.link(
        x=80,
        y=150 - line_height,
        w=width,
        h=line_height,
        link="https://github.com/PyFPDF/fpdf2",
        alt_text="GitHub repository of the fpdf2 library",
    )
    assert_pdf_equal(pdf, HERE / "link_alt_text.pdf", tmp_path)
コード例 #3
0
ファイル: main.py プロジェクト: joehenry9498/EducationChart
def create_chart():
    name = input("\nEnter name of student: ")
    pdf_file_name = input("Enter preferred output file name (must end in .pdf): ")

    all_schools = []
    school_keys = []
    other_info = []
    category = ["School", "Grades", "Location", "Deadline",
                "Application", "Testing", "Learning Support", "URL"]
    categories = [category]

    n = int(input("Enter number of Schools you would like to include in the green zone then type their keys out, "
                  "followed by an enter : "))

    for i in range(0, n):
        ele = str(input())

        school_keys.append(ele)

    for key in school_keys:
        s = shelve.open('test_shelf.db')
        try:
            existing = s[key]
            all_schools.append([existing['name'], existing['age'], existing['location'], existing['application deadline'],
                                existing['application method'], existing['testing accepted'],
                                existing['learning support'], existing['other']])
            other_info.append([existing['name'], existing['extra']])
        finally:
            s.close()

    yellow_schools = []
    yellow_school_keys = []

    n = int(input("Enter number of Schools you would like to include in the yellow zone then type their keys out"
                  "followed by an enter : "))

    for i in range(0, n):
        ele = str(input())

        yellow_school_keys.append(ele)  # adding the element

    for key in yellow_school_keys:
        s = shelve.open('test_shelf.db')
        try:
            existing = s[key]
            yellow_schools.append([existing['name'], existing['age'], existing['location'], existing['application deadline'],
                                existing['application method'], existing['testing accepted'],
                                existing['learning support'], existing['other']])
            other_info.append([existing['name'], existing['extra']])
        finally:
            s.close()

    red_schools = []
    red_school_keys = []

    n = int(input("Enter number of Schools you would like to include in the red zone then type their keys out"
                  "followed by an enter : "))

    for i in range(0, n):
        ele = str(input())

        red_school_keys.append(ele)  # adding the element

    for key in red_school_keys:
        s = shelve.open('test_shelf.db')
        try:
            existing = s[key]
            red_schools.append([existing['name'], existing['age'], existing['location'], existing['application deadline'],
                                existing['application method'], existing['testing accepted'],
                                existing['learning support'], existing['other']])
            other_info.append([existing['name'], existing['extra']])
        finally:
            s.close()

    pdf = FPDF(format=(266.7, 457.2))

    # Add a page
    pdf.add_page()

    # set style and size of font
    # that you want in the pdf
    pdf.set_font("Times", size=11)
    pdf.image("hall.jpg", 82, 10, 105)
    pdf.cell(0, 10, ln=1, align='C')
    pdf.cell(0, 10, ln=1, align='C')
    pdf.cell(0, 10, ln=1, align='C')
    pdf.cell(0, 10, ln=1, align='C')

    pdf.set_font("Times", 'B', size=11)
    title_string = "Initial School Exploration List: " + name
    pdf.cell(0, 10, txt=title_string, ln=1, align='L')

    pdf.set_font("Times", size=11)

    pdf.line(10, 58, 255, 58)

    pdf.set_font("Times", 'B', size=11)
    pdf.cell(13, 7, txt="Green: ", align='L')
    pdf.set_font("Times", size=11)

    pdf.cell(0, 7, txt="Schools we should actively pursue now.", ln=1, align='L')

    pdf.set_font("Times", 'B', size=11)
    pdf.cell(15, 7, txt="Yellow: ", align='L')
    pdf.set_font("Times", size=11)

    pdf.cell(0, 7, txt="Schools we would like you to proceed with, although not as strong a fit.", ln=1, align='L')

    pdf.set_font("Times", 'B', size=11)
    pdf.cell(10, 7, txt="Red: ", align='L')
    pdf.set_font("Times", size=11)

    pdf.cell(0, 7, txt="These schools could be a fit but less likely than the yellow and green.", ln=1, align='L')
    pdf.ln(1)

    epw = pdf.w - 2 * pdf.l_margin
    pdf.set_font('Times', 'B', 10)
    col_width = epw / 8
    th = pdf.font_size

    pdf.set_fill_color(0, 230, 0)
    pdf.rect(pdf.x, pdf.y, epw, 7, style='DF')
    pdf.cell(0, 7, txt="Green: Schools we should actively pursue now.", ln=1, align='C')

    pdf.set_font("Times", 'B', size=10)

    for row in categories:
        for datum in row:
            pdf.cell(col_width, 2 * th, str(datum), border=1)

        pdf.ln(2 * th)
    pdf.set_font('Times', '', 7)

    link_counter = 0
    for row in all_schools:
        for datum in row:
            link_counter = link_counter + 1
            if link_counter == 8:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
                pdf.link(pdf.x - col_width, pdf.y - (2 * th), 3, 3, str(datum))
            else:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
        link_counter = 0
        pdf.ln(2 * th)

    pdf.set_fill_color(255, 255, 0)
    pdf.rect(pdf.x, pdf.y, epw, 7, style='DF')
    pdf.set_font('Times', 'B', 10)
    pdf.cell(0, 7, txt="Yellow: Schools we should pursue, but not as strong as green.", ln=1, align='C')
    pdf.set_font('Times', '', 7)

    link_counter = 0
    for row in yellow_schools:
        for datum in row:
            link_counter = link_counter + 1
            if link_counter == 8:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
                pdf.link(pdf.x - col_width, pdf.y - (2 * th), 3, 3, str(datum))
            else:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
        link_counter = 0
        pdf.ln(2 * th)

    pdf.set_fill_color(255, 0, 0)
    pdf.rect(pdf.x, pdf.y, epw, 7, style='DF')
    pdf.set_font('Times', 'B', 10)
    pdf.cell(0, 7, txt="Red: These schools could be a fit but less likely than "
                       "the yellow and green.", ln=1, align='C')
    pdf.set_font('Times', '', 7)

    link_counter = 0
    for row in red_schools:
        for datum in row:
            link_counter = link_counter + 1
            if link_counter == 8:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
                pdf.link(pdf.x - col_width, pdf.y - (2 * th), 3, 3, str(datum))
            else:
                pdf.cell(col_width, 2 * th, str(datum), border=1)
        link_counter = 0
        pdf.ln(2 * th)

    pdf.set_font("Times", 'B', size=14)
    pdf.cell(0, 13, txt="Extra Information", ln=1, align='C')
    pdf.set_font("Times", size=11)

    for entry in other_info:
        if entry[1] != "":
            input_string = entry[0] + ": " + entry[1]
            pdf.cell(0, 7, txt=input_string, ln=1, align='L')

    pdf.output(pdf_file_name)

    main()