8000 GitHub - francogarcia/GD-PDF: Create PDF files using Godot Game Engine.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

francogarcia/GD-PDF

Repository files navigation

Godot Engine PDF Creation Module

Information

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.

Support

Revisions up to commit 183216b1815d5e564c07b0fbf24bc2e073ea2cab work with Godot 2.

Revisions starting from commit e2d45984026d8b4ed1dcbd86e33e19c9aa82f3d6 work with Godot 3.5 – thanks to Frodo-tech, who has kindly updated this project.

Revisions starting from commit 8e765c9a63fbe5947e11a7de214fe23030141d4c work with Godot 4.0.

Example

var pdf = PDF.new()
pdf.create_document("/tmp/DejaVuSans.ttf", "/tmp/DejaVuSerif.ttf")

pdf.add_new_page()
pdf.add_title("Document Title")
# pdf.add_header("My Header")
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()

Installation

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 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 /pathTo/Godot3.5/godot/
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
# The next step generates the hpdf_config.h file.
# You may wish to configure the optional paths paths to ZLIB / LIBPNG.
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.

  • Source code directory: path/to/libharu.
  • Destination directory: path/to/libharu/win32.

In the root directory, move win32/include/hpdf_config.h to include/hpdf_config.h.

Then build Godot:

scons platform=windows

Exporting Projects

Compile the export templates using the steps outlined in the wiki. See the section “Compiling” in the Godot Engine Documentation for more information.

Linux

  • 32 bits:
scons platform=x11 tools=no target=release bits=32
scons platform=x11 tools=no target=release_debug bits=32
  • 64 bits:
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:

  • linux_x11_32_debug;
  • linux_x11_32_release;
  • linux_x11_64_debug;
  • linux_x11_64_release.

Windows

  • 32 bits:
scons platform=windows tools=no target=release bits=32
scons platform=windows tools=no target=release_debug bits=32
  • 64 bits:
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

Error handler is currently undefined

LibHARU error handler function currently does nothing.

Forward LibHARU’s return codes

About

Create PDF files using Godot Game Engine.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0