Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicolasalmerge/newharu
PDF Creation Library based on the C LibHaru library
https://github.com/nicolasalmerge/newharu
cpp cpp17 cpp20 libharu object-oriented object-oriented-programming oop pdf pdf-generation
Last synced: about 2 months ago
JSON representation
PDF Creation Library based on the C LibHaru library
- Host: GitHub
- URL: https://github.com/nicolasalmerge/newharu
- Owner: NicolasAlmerge
- License: mit
- Created: 2022-06-26T22:02:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-05T11:48:44.000Z (9 months ago)
- Last Synced: 2024-04-05T12:40:57.535Z (9 months ago)
- Topics: cpp, cpp17, cpp20, libharu, object-oriented, object-oriented-programming, oop, pdf, pdf-generation
- Language: C++
- Homepage: https://nicolasalmerge.github.io/NewHaru/
- Size: 3.25 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NewHaru
PDF Creation C++ Library, made by [Nicolas Almerge](https://github.com/NicolasAlmerge).
It is based on the C library [LibHaru](https://github.com/libharu/libharu), but provides an easier, cleaner and simpler syntax with object oriented patterns, exception handling and flexibility.
## Usage
```cpp
#include "include/NewHaru.hpp"
#include "iostream"int main() {
pdf::Document document;// Print 'true' or 'false' instead of '1' and '0' for boolean types
std::cout << std::boolalpha;try {
// Open the document
document.open();// Get font 'Helvetica'
pdf::Font font = document.getFont("Helvetica");// Add a page at the end of the document
pdf::Page page = document.addPage();// Set the pdf creation date to December 10th, 2002 at 12:15:30 PM
document.setAttribute(
pdf::enums::DateTimeAttribute::CREATION_DATE,
{2000, 12, 10, 12, 15, 30}
);// Set font and size
page.setFontAndSize(font, 12);// Write text at specified positions
page.writeText("This is a test\n", {50, 50});
page.writeText("This is a second test\n", {150, 50});// Create a new text annotation and set the icon to a help icon
pdf::TextAnnotation annotation = page.createTextAnnotation(
"Hi there!", {200, 200, 200, 200}
);
annotation.setIcon(pdf::enums::AnnotationIcon::HELP);// Save to file
document.saveToFile("output.pdf");
} catch (const pdf::excepts::Exception& e) {
// Print the exception name and description in case one occurred
std::cout << e.getFullDescription() << std::endl;
}return 0;
}
```## Compilation
For MacOS, you first need to install [Homebrew](https://brew.sh).
After installing, you should install [libharu](https://formulae.brew.sh/formula/libharu) using:
```sh
brew install libharu
```Then, you can compile your program by running:
```sh
g++ -std=c++17 -o output -O2 -Wall program.cpp NewHaru/src/*.cpp -I$(brew --prefix)/include/ -L$(brew --prefix)/lib/ -lhpdf -lpng -lz -lm
```