| from fpdf import FPDF |
| import os |
|
|
| def create_pdf_from_txt(txt_path, pdf_path): |
| with open(txt_path, 'r') as file: |
| content = file.read() |
| |
| |
| content = content.replace('•', '*') |
| content = content.replace('–', '-') |
| |
| pdf = FPDF() |
| pdf.add_page() |
| pdf.set_auto_page_break(auto=True, margin=15) |
| pdf.set_font("Arial", size=12) |
| |
| |
| for line in content.split('\n'): |
| try: |
| |
| encoded_line = line.encode('latin-1', 'replace').decode('latin-1') |
| pdf.cell(0, 10, txt=encoded_line, ln=True) |
| except Exception: |
| |
| continue |
| |
| pdf.output(pdf_path) |
|
|
| def main(): |
| |
| job_desc_dir = "JOB_DESCRIPTIONS" |
| txt_files = [f for f in os.listdir(job_desc_dir) if f.endswith('.txt')] |
| |
| for txt_file in txt_files: |
| txt_path = os.path.join(job_desc_dir, txt_file) |
| pdf_path = os.path.join(job_desc_dir, txt_file.replace('.txt', '.pdf')) |
| create_pdf_from_txt(txt_path, pdf_path) |
| os.remove(txt_path) |
|
|
| |
| resume_dir = "DATA_resume" |
| txt_files = [f for f in os.listdir(resume_dir) if f.endswith('.txt')] |
| |
| for txt_file in txt_files: |
| txt_path = os.path.join(resume_dir, txt_file) |
| pdf_path = os.path.join(resume_dir, txt_file.replace('.txt', '.pdf')) |
| create_pdf_from_txt(txt_path, pdf_path) |
| os.remove(txt_path) |
|
|
| if __name__ == "__main__": |
| main() |