3 releases
0.1.2 | Jul 23, 2024 |
---|---|
0.1.1 | Jul 23, 2024 |
0.1.0 | Jul 23, 2024 |
#1787 in Text processing
13KB
61 lines
Convert HTML to pdf library Rust
This repository contains the htmltopdf Rust library, which converts HTML to PDF. Below are instructions for integrating and using this library in different environments.
Prerequisites
- Rust installed on your system
- Java Development Kit (JDK) installed
- Maven installed
Building the Rust Library
-
Clone the Repository
Clone the repository containing the
html_to_pdf_lib
Rust library.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
The shared library will be located in the target/release directory. The filename will be html_to_pdf_lib..
Usage Rust project
To use html_to_pdf_lib
in your Rust project, follow these steps:
-
Add the library as a dependency in your
Cargo.toml
:[dependencies] html_to_pdf_lib = "0.1.0"
-
Use the library in your Rust code:
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(()) }
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~27MB
~277K SLoC