def test_fill_form(self): result = pypdftk.fill_form(TEST_XPDF_PATH, datas=SAMPLE_DATA2, flatten=False) result_data = ordered(pypdftk.dump_data_fields(result)) expected_data = ordered(json.loads(read(TEST_XPDF_FILLED_DATA_DUMP))) self.assertEqual(result_data, expected_data)
def get_dump_data_fields(pdfname): """ Get dumped fields for specified pdfname. Can be formatted. GET: /pdf/<pdfname>?format={pairs,keys} :pairs - list of pairs (key: value) for dumped data fields :keys - only dumped field names """ data = pypdftk.dump_data_fields("{folder}/{file}.pdf".format( folder=PDF_FOLDER, file=pdfname)) formated = request.args.get('format') if "pairs" == formated: data = format_fields_by_pairs(data) elif "keys" == formated: data = format_fields_by_keys(data) return jsonify(data)
def generate_form(datas): module_dir = os.path.dirname(__file__) # get current directory PATH = os.path.join(module_dir, "SOFC-Credit-Card-Payment.pdf") var = py.dump_data_fields(PATH) # for elem in var: # print(elem['FieldName']) generated_pdf = py.fill_form(PATH, datas, out_file=os.path.join(module_dir, 'new_pdf.pdf')) print('form has been generated') return os.path.join(module_dir, 'new_pdf.pdf') # datas = dict() # datas['Account Number'] = 123456 # datas['SubAccount'] = 123456 # datas['Amount'] = 123 # datas['Date'] = date # datas['Org Name'] = org # generate_form(datas) # Account Number # SubAccount # Date mmddyyyy # Amount # Vendor # Contact # Phone # Reservation Phone # Reservation Guest # Reservation by # Start Date # End Date # Statement of Benefit # Leader Phone # Leader Date # Advisor Phone # Advisor Date # Travel 1 # Travel 2 # Org Name # Invoice Confirmation
def test_dump_data_fields(self): result_data = ordered(pypdftk.dump_data_fields(TEST_XPDF_PATH)) expected_data = ordered(json.loads(read(TEST_XPDF_DATA_DUMP))) self.assertEqual(result_data, expected_data)
def test_dump_data_fields(self): result_data = ordered(pypdftk.dump_data_fields(TEST_XPDF_PATH)) expected_data = ordered(json.loads(read(TEST_XPDF_DATA_DUMP))) self.assertCountEqual(list(result_data), [dict(i) for i in expected_data])