1def text_to_rtf(input_file: str, output_file: str) -> None: 2 with open(input_file, "r", encoding="utf-8") as file: 3 text_content = file.read() 4 5 text_content = text_content.replace("\\", "\\\\") 6 text_content = text_content.replace("{", "\\{") 7 text_content = text_content.replace("}", "\\}") 8 9 text_content = text_content.replace("\n", "\\par\n") 10 11 rtf_content = "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2580\\cocoasubrtf220\n" 12 rtf_content += "{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}\n" 13 rtf_content += "\\vieww12000\\viewh15840\\viewkind0\n" 14 rtf_content += "\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\pardirnatural\\partightenfactor0\n" 15 rtf_content += "\\f0\\fs24 " 16 rtf_content += text_content 17 rtf_content += "\n}" 18 19 with open(output_file, "w", encoding="utf-8") as file: 20 file.write(rtf_content) 21 22 print(f"Conversion complete! RTF file saved as: {output_file}") 23 24 25if __name__ == "__main__": 26 import sys 27 28 if len(sys.argv) != 3: 29 print(f"Usage: python {sys.argv[0]} input.txt output.rtf") 30 sys.exit(1) 31 32 input_file = sys.argv[1] 33 output_file = sys.argv[2] 34 35 text_to_rtf(input_file, output_file) 36