| Crates.io | hwpers |
| lib.rs | hwpers |
| version | 0.5.0 |
| created_at | 2025-08-02 06:15:38.438345+00 |
| updated_at | 2026-01-18 23:10:31.158129+00 |
| description | A Rust library for parsing Korean Hangul Word Processor (HWP) files with full layout rendering support |
| homepage | https://github.com/Indosaram/hwpers |
| repository | https://github.com/Indosaram/hwpers |
| max_upload_size | |
| id | 1778350 |
| size | 583,916 |
A Rust library for parsing Korean Hangul Word Processor (HWP) files with full layout rendering support.
Add this to your Cargo.toml:
[dependencies]
hwpers = "0.3"
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);
}
}
}
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());
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")?;
// 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()
);
}
}
}
}
}
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
This library supports HWP 5.0 format files. For older HWP formats, consider using format conversion tools first.
The HWP writer functionality has been significantly improved with comprehensive feature support:
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.
This project is licensed under either of
at your option.