This module allows Godot Engine to create PDF files using LibHARU. Its provides an API to create PDF documents in the Godot Engine. It also offers bindings for using the API in GDScript.
Revisions up to commit [[https://github.com/francogarcia/GD-PDF/commit/183216b1815d5e564c07b0fbf24bc2e073ea2cab][183216b1815d5e564c07b0fbf24bc2e073ea2cab]] work with Godot 2.
Revisions starting from commit [[https://github.com/francogarcia/GD-PDF/commit/e2d45984026d8b4ed1dcbd86e33e19c9aa82f3d6][e2d45984026d8b4ed1dcbd86e33e19c9aa82f3d6]] work with Godot 3.5 -- thanks to [[https://github.com/Frodo-tech][Frodo-tech]], who has kindly updated this project.
Revisions starting from commit [[https://github.com/francogarcia/GD-PDF/commit/8e765c9a63fbe5947e11a7de214fe23030141d4c][8e765c9a63fbe5947e11a7de214fe23030141d4c]] work with Godot 4.0.
var pdf = PDF.new() pdf.create_document("/tmp/DejaVuSans.ttf", "/tmp/DejaVuSerif.ttf")
pdf.add_new_page() pdf.add_title("Document Title")
pdf.add_body_text("The quick brown fox jumps over the lazy dog.") pdf.add_body_text("The quick brown fox jumps over the lazy dog. 0123456789") pdf.add_body_text("Short sentence.") pdf.add_body_text("Longer sentence...")
pdf.add_header("My Section") pdf.add_body_text("Section 1")
pdf.add_header("Another Section") pdf.add_body_text("Section 2 with some text.")
pdf.add_new_page() pdf.add_title("Write 10 times...") for i in range(10): pdf.add_body_text(str(i + 1) + " The quick brown fox jumps over the lazy dog.")
pdf.save_document("/tmp/my_doc.pdf") pdf.finish_document()
This project has been originally implemented for Godot 2, which required plug-ins to be compiled with the engine. As such, support for Godot 3.5 still requires compiling the engine. For more information, refer to the section "Compiling" pages in the [[https://docs.godotengine.org/en/stable/development/compiling/index.html][Godot Engine Documentation]].
To fetch the source code:
git clone -b 3.5 --single-branch https://github.com/godotengine/godot.git
Clone or extract this project into Godot's ~modules~ directory. For better support, consider removing the hyphen from the default directory name.
cd modules/ git clone https://github.com/francogarcia/GD-PDF gdpdf
Then follow the instructions to build LibHARU in your platform. It is important that the header =libharu/include/hpdf_config.h= exists; otherwise, the compilation will fail.
For all platforms bellow, the steps assumes that LibHARU's source code is in this modules' =libharu= directory. To speed Godot's compilation, it is recommended to use the option =-j N=, to use =N= cores in the building process.
** Linux (X11)
In a shell, run:
git clone https://github.com/libharu/libharu libharu cd libharu
cmake .
Then build Godot:
scons platform=x11
** Windows
First fetch the source code for LibHARU.
git clone https://github.com/libharu/libharu libharu cd libharu
Then, to generate the configuration file, use Cmake.
In the root directory, move =win32/include/hpdf_config.h= to =include/hpdf_config.h=.
Then build Godot:
scons platform=windows
Compile the export templates using the steps outlined in the wiki. See the section "Compiling" in the [[https://docs.godotengine.org/en/stable/development/compiling/index.html][Godot Engine Documentation]] for more information.
** Linux
scons platform=x11 tools=no target=release bits=32 scons platform=x11 tools=no target=release_debug bits=32
scons platform=x11 tools=no target=release bits=64 scons platform=x11 tools=no target=release_debug bits=64
Afterwards, move the resulting files to =/home/youruser/.godot/templates= (=~/.godot/templates=), with the followig names:
** Windows
scons platform=windows tools=no target=release bits=32 scons platform=windows tools=no target=release_debug bits=32
scons platform=windows tools=no target=release bits=64 scons platform=windows tools=no target=release_debug bits=64
Afterwards, move the resulting files to =C:\USERS\YOURUSER\AppData\Roaming\Godot\Templates= (=%APPDATA%/Godot/templates=), with the followig names:
=windows_32_debug.exe=;
=windows_32_release.exe=;
=windows_64_debug.exe=;
=windows_64_release.exe=.
Issues
** TODO Error handler is currently undefined
LibHARU error handler function currently does nothing.
** TODO Forward LibHARU's return codes