Crates.io | html_to_pdf_lib |
lib.rs | html_to_pdf_lib |
version | 0.1.2 |
source | src |
created_at | 2024-07-23 09:26:09.475936 |
updated_at | 2024-07-23 12:00:58.545735 |
description | A library for converting HTML to PDF. |
homepage | |
repository | |
max_upload_size | |
id | 1312595 |
size | 38,963 |
This repository contains the htmltopdf Rust library, which converts HTML to PDF. Below are instructions for integrating and using this library in different environments.
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.
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(())
}
This project is licensed under the MIT License - see the LICENSE file for details.