コード例 #1
0
def main():
    parser = argparse.ArgumentParser(
        description="Tool for pictures to pdf file")
    parser.add_argument('-f',
                        '--fromdir',
                        required=True,
                        help='the directory path of the input file')
    parser.add_argument('-H',
                        '--height',
                        type=int,
                        required=True,
                        help='height of the output file')
    parser.add_argument('-W',
                        '--width',
                        type=int,
                        required=True,
                        help='width of the output file')
    args = parser.parse_args()
    fromdir = args.fromdir
    width = args.width
    height = args.height

    pdf = FPDF()
    pdf.footer()
    pdf.add_page()
    for file in range(1, 303):
        file = str(file) + ".png"
        if file == "desktop.ini":
            continue
        filein = os.path.join(fromdir, file)
        print(filein)
        try:
            pdf.image(filein, None, None, width / 3.5, height / 3.5, "PNG")
        except Exception as e:
            print(e)
            continue
    pdf.output("信息化导论.pdf", "F")
コード例 #2
0
pdf.set_font('Arial', 'I', 12)
pdf.cell(180, 8, txt="Generated With Concisely Yours", ln=1, align='C')

pdf.set_font('Arial', 'B', 12)
pdf.cell(200, 10, txt="Summary", ln=2, align='L')

pdf.add_font('ArialUnicode', fname='Arial-Unicode-Regular.ttf', uni=True)
pdf.set_font('ArialUnicode', '', 10)

pdf.multi_cell(0, 6, summary)

pdf.set_font('Arial', 'B', 12)
pdf.cell(200,
         10,
         txt="Potential Red Flags & Points of Importance",
         ln=2,
         align='L')

pdf.add_font('ArialUnicode', fname='Arial-Unicode-Regular.ttf', uni=True)
pdf.set_font('ArialUnicode', '', 10)

pdf.multi_cell(0, 6, notes)

FPDF.footer(pdf)
pdf.set_y(249)
pdf.set_font('Arial', 'I', 8)
pdf.cell(0, 10, 'A UofTHacks VIII Project', 0, 0, 'C')

pdf.output("summary.pdf")