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