LuaHPDF is a Lua module that lets you programmatically create PDF files using Lua. It does this by binding to the Haru Free PDF Library, an open-source library that manages the details of PDF generation.
With this module, you can write Lua programs that will produce PDF files that include
This module works on POSIX and Windows platforms.
LuaHPDF conforms to the Lua 5.1 module standard. It provides a thin binding to the libharu library for PDF generation. The differences to the Haru application programming interface are minor, so you should be able to write Lua scripts using the documentation that is provided with the Haru library.
The most recent version of the software is available from LuaForge. The change log summarizes the release history for the software.
The Haru library and Lua must be properly installed on your system to build LuaHPDF. Each can be compiled easily from source code. Alternatively, each is available in binary form for a wide variety of platforms. See their respective websites for more details.
Notes on building LuaHPDF guide you through compiling and installing the module on your system. Check out some of the features of the Haru library by generating demonstration PDFs.
The steps in creating a basic PDF file with LuaHPDF include
Here is a short example.
require "hpdf"
local pdf = hpdf.New()
if pdf then
local page = hpdf.AddPage(pdf)
local height = hpdf.Page_GetHeight(page)
local width = hpdf.Page_GetWidth(page)
local font = hpdf.GetFont(pdf, "Helvetica")
hpdf.Page_SetFontAndSize(page, font, 24)
hpdf.Page_BeginText(page)
hpdf.Page_TextOut(page, 60, height - 60, "Hello from Haru")
hpdf.Page_EndText(page)
hpdf.SaveToFile(pdf, "hello.pdf")
hpdf.Free(pdf)
else
io.write("Error creating PDF object\n")
end
Other demonstration scripts are provided in the download package.
You're encouraged to provide comments, questions and suggestions about LuaHPDF in this software's open discussion forum.
LuaHPDF depends on other software. In particular, I am grateful to
The authors of Lua, Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes.
The orignal author of the Haru Free PDF Library, Takeshi Kanno, and to Antony Dovgal, who currently provides fixes and improvements to this library.
The author of Markdown, John Gruber, and the author of markdown.lua, Niklas Frykholm. This documentation is written in Markdown.
Andrea D'Amore who provided Makefile tips for compiling on OS X.
Like Lua, this software is released under the MIT license.