Heartsync/toss-hwp
0
1from pyhwp.html_converter import HwpToHtmlConverter2from hwp5.hwp5html import HTMLTransform3from hwp5.xmlmodel import Hwp5File4from contextlib import closing5import os6import sys7 8def main():9 hwp_file = 'test.hwp'10 output_path = 'test.html'11 12 print("Step 1: Init HTMLTransform", flush=True)13 transformer = HTMLTransform()14 output_dir = os.path.dirname(os.path.abspath(output_path))15 16 print(f"Step 2: Opening {hwp_file}", flush=True)17 with closing(Hwp5File(hwp_file)) as hwp5file:18 print("Step 3: Creating temp XHWP5", flush=True)19 with transformer.transformed_xhwp5_at_temp(hwp5file) as xhwp5path:20 print(f"Step 4: Temp XHWP5 at {xhwp5path}", flush=True)21 22 print("Step 5: Generating HTML...", flush=True)23 with open(output_path, 'wb') as f:24 transformer.transform_xhwp5_to_xhtml(xhwp5path, f)25 print("Step 5: HTML Done", flush=True)26 27 print("Step 6: Generating CSS...", flush=True)28 css_path = os.path.join(output_dir, 'styles.css')29 with open(css_path, 'wb') as f:30 transformer.transform_xhwp5_to_css(xhwp5path, f)31 print("Step 6: CSS Done", flush=True)32 33 print("Step 7: Extracting BinData...", flush=True)34 bindata_dir = os.path.join(output_dir, 'bindata')35 transformer.extract_bindata_dir(hwp5file, bindata_dir)36 print("Step 7: BinData Done", flush=True)37 38 print("All Done", flush=True)39 40if __name__ == "__main__":41 main()42 