예제 #1
0
    with open('statements.pdf', 'rb') as statements_file:
        statements_pdf = PdfFileReader(statements_file)
        
        counts = {}
        for i, r in enumerate(reader):
            key = r.get('Association Key','').zfill(4)
            name = r.get('Association Name','')
            nlname = r.get('Newsletter Name', '')
            option1 = r.get('Newsletter Option 1', '')
            option2 = r.get('Newsletter Option 2', '')
            account = r.get('Account ID', '')
            
            print 'processing account: {0} {1}'.format(key, account)
            

            docs = manifest.get_for_key(key)
            
            if key not in nl:                
                pdf_writer = PdfFileWriter()
                sheets = 0
                for d in docs:
                    nl_f = open(d.path, 'rb')
                    nl_pdf = PdfFileReader(nl_f)
                    for p in nl_pdf.pages:
                        sheets += 1
                        pdf_writer.addPage(p)
                
                nl[key] = pdf_writer

            if nlname:
                file_root = path.join('tmp', '+{0} on {1} {2}'.format(sheets, option1, option2))
예제 #2
0
statements = PdfFileReader(open('statements.pdf', 'rb'))

manifest_file = open('documents/manifest.csv', 'rb')
manifest = Manifest(manifest_file)

with open('output.csv', 'rb') as output_data:
    data_reader = csv.DictReader(output_data)
    for ri, row in enumerate(data_reader):
        key = row.get('Association Key','').zfill(4)
        account_id = row.get('Account ID','')
        
        output = PdfFileWriter()
        output.addPage(statements.getPage(ri))
        
        newsletters = manifest.get_for_key(key)
        for nl in newsletters:
            nl_f = open(nl.path, 'rb')
            nl_pdf = PdfFileReader(nl_f)
            for p in nl_pdf.pages:
                output.addPage(p)
            nl_f
        
        with open(path.join(TMP_PATH, key + '_' + account_id + '.pdf'), 'wb') as output_stream:
            output.write(output_stream)
            
proof_pdfs = listdir(TMP_PATH)
proof_pdfs = [f for f in proof_pdfs if f != '.DS_Store']

PDF_FLUSH = 50
OUTPUT_FILENAME = 'proofs_{0}.pdf'