Web Analytics

hwpers

⭐ 179 stars English by Indosaram

hwpers

Crates.io Documentation CI License

A Rust library for parsing Korean Hangul Word Processor (HWP) files with full layout rendering support.

Features

Parser (Reading HWP files)

Writer (Creating HWP files) - v0.3.0+

Quick Start

Add this to your Cargo.toml:

[dependencies]
hwpers = "0.3"

Basic Usage

use hwpers::HwpReader;

// Parse an HWP file let document = HwpReader::from_file("document.hwp")?;

// Extract text content let text = document.extract_text(); println!("{}", text);

// Access document properties if let Some(props) = document.get_properties() { println!("Pages: {}", props.total_page_count); }

// Iterate through sections and paragraphs for (i, section) in document.sections().enumerate() { println!("Section {}: {} paragraphs", i, section.paragraphs.len()); for paragraph in §ion.paragraphs { if let Some(text) = ¶graph.text { println!(" {}", text.content); } } }

Visual Layout Rendering

use hwpers::{HwpReader, render::{HwpRenderer, RenderOptions}};

let document = HwpReader::from_file("document.hwp")?;

// Create renderer with custom options let options = RenderOptions { dpi: 96, scale: 1.0, show_margins: false, show_baselines: false, };

let renderer = HwpRenderer::new(&document, options); let result = renderer.render();

// Export first page to SVG if let Some(svg) = result.to_svg(0) { std::fs::write("page1.svg", svg)?; }

println!("Rendered {} pages", result.pages.len());

Creating Documents (v0.3.0+)

use hwpers::writer::HwpWriter;
use hwpers::model::hyperlink::Hyperlink;

// Create a new document let mut writer = HwpWriter::new();

// Add formatted text writer.add_aligned_paragraph( "제목", hwpers::writer::style::ParagraphAlignment::Center )?;

// Add hyperlinks let link = Hyperlink::new_url("Rust", "https://rust-lang.org"); writer.add_paragraph_with_hyperlinks( "Visit Rust website", vec![link] )?;

// Configure page layout writer.set_custom_page_size(210.0, 297.0, // A4 size hwpers::model::page_layout::PageOrientation::Portrait)?; writer.set_page_margins_mm(20.0, 20.0, 20.0, 20.0);

// Add header and footer writer.add_header("Document Header"); writer.add_footer_with_page_number("Page ", hwpers::model::header_footer::PageNumberFormat::Numeric);

// Save the document writer.save_to_file("output.hwp")?;

Advanced Formatting Access

// Access character and paragraph formatting
for section in document.sections() {
    for paragraph in §ion.paragraphs {
        // Get paragraph formatting
        if let Some(para_shape) = document.get_para_shape(paragraph.para_shape_id as usize) {
            println!("Indent: {}, Alignment: {}", 
                para_shape.indent, 
                para_shape.get_alignment()
            );
        }
        
        // Get character formatting runs
        if let Some(char_shapes) = ¶graph.char_shapes {
            for pos_shape in &char_shapes.char_positions {
                if let Some(char_shape) = document.get_char_shape(pos_shape.char_shape_id as usize) {
                    println!("Position {}: Size {}, Bold: {}", 
                        pos_shape.position,
                        char_shape.base_size / 100,
                        char_shape.is_bold()
                    );
                }
            }
        }
    }
}

Supported Features

Document Structure

Content Types

Layout and Rendering

Advanced Features

Command Line Tool

The library includes a command-line tool for inspecting HWP files:

# Install the tool
cargo install hwpers

Inspect an HWP file

hwp_info document.hwp

Format Support

This library supports HWP 5.0 format files. For older HWP formats, consider using format conversion tools first.

Writer Features (v0.3.0+)

The HWP writer functionality has been significantly improved with comprehensive feature support:

✅ Fully Implemented

❌ Not Yet Implemented

🔧 Known Issues

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under either of

at your option.

Acknowledgments

--- Tranlated By Open Ai Tx | Last indexed: 2026-03-13 ---