3 个版本
0.1.2 | 2024年7月23日 |
---|---|
0.1.1 | 2024年7月23日 |
0.1.0 | 2024年7月23日 |
#1436 在 文本处理
373 每月下载次数
13KB
61 行
Rust 将 HTML 转换为 PDF 库
此仓库包含 htmltopdf Rust 库,该库可以将 HTML 转换为 PDF。以下是不同环境中集成和使用此库的说明。
先决条件
- 系统上已安装 Rust
- 已安装 Java 开发工具包 (JDK)
- 已安装 Maven
构建 Rust 库
-
克隆仓库
克隆包含
html_to_pdf_lib
Rust 库的仓库。git clone https://github.com/Bansikah/htmltopdflib cd htmltopdflib
Build the Rust Library
Build the Rust library to generate the shared library file (.so, .dll, or .dylib) for JNI.
```sh
cargo build --release
cargo run file.html
共享库将位于 target/release 目录中。文件名为 html_to_pdf_lib..
Rust 项目使用方法
要在您的 Rust 项目中使用 html_to_pdf_lib
,请按照以下步骤操作
-
在
Cargo.toml
中添加库作为依赖项[dependencies] html_to_pdf_lib = "0.1.0"
-
在 Rust 代码中使用库
use html_to_pdf_lib::convert_html_to_pdf; fn main() -> Result<(), Box<dyn std::error::Error>> { let html_content = r#" <!DOCTYPE html> <html> <head> <title>Sample PDF</title> </head> <body> <h1>Hello, World!</h1> <p>This is a sample PDF generated from HTML.</p> </body> </html> "#; let output_path = "output.pdf"; convert_html_to_pdf(html_content, output_path)?; println!("PDF generated successfully at {}", output_path); Ok(()) }
许可证
本项目采用 MIT 许可证 - 请参阅 LICENSE 文件以获取详细信息。
依赖项
~27MB
~271K SLoC