https://github.com/sectasy0/zhtml2pdf
WebKit2-based HTML-to-PDF converter with simple API
https://github.com/sectasy0/zhtml2pdf
Last synced: 9 months ago
JSON representation
WebKit2-based HTML-to-PDF converter with simple API
- Host: GitHub
- URL: https://github.com/sectasy0/zhtml2pdf
- Owner: sectasy0
- License: wtfpl
- Created: 2025-02-07T20:04:56.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-20T18:15:00.000Z (over 1 year ago)
- Last Synced: 2025-05-30T12:31:32.728Z (about 1 year ago)
- Language: Zig
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `libzhtml2pdf` - WebKit2-based HTML-to-PDF Converter with Simple API
`libzhtml2pdf` is a C-based library designed for converting HTML documents into PDF format. This library uses **WebKit2GTK-4.0** as its rendering engine for HTML content, allowing you to create high-quality PDFs from HTML with ease. It offers a simple API that can be integrated into various applications and projects.
---
## Prerequisites
Before compiling `libzhtml2pdf`, you need to ensure that the following dependencies are installed on your system:
### 1. **WebKit2GTK-4.0**
- **Version**: `4.0` (or later)
### 2. **Zig Compiler**
- **Version**: `0.13` (or later)
---
## Building `libzhtml2pdf`
Once you have the prerequisites installed, you can proceed to compile `libzhtml2pdf` on your system. Follow these steps:
1. **Clone the Repository**:
First, clone the `libzhtml2pdf` repository from GitHub or another source:
```bash
git clone https://github.com/your-repository/libzhtml2pdf.git
cd libzhtml2pdf
build zig
```
After successfully compilation it will produce static library to `zig-out/lib`
## CAPI Example usage
```c
#include "zhtml2pdf.h"
int main() {
init_zhtml2pdf();
const char* html_content = "
Sample PDF
This is a test PDF generated from HTML.
";
unsigned char* pdf_data = NULL;
int size = zhtml2pdf_convert(html_content);
if (size < 0) {
printf("Failed to convert html to pdf!\n");
return -1;
}
printf("PDF successfully created!\n");
// Do whatever you want with pdf, output is in base64
zhtml2pdf_free(pdf_data);
deinit_zhtml2pdf();
return 0;
}
```