GithubHelp home page GithubHelp logo

luahpdf's Introduction

LuaHPDF

LuaHPDF is a 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

  • lines, text and graphics
  • PNG and JPEG images
  • compression
  • encryption
  • Type1 and TrueType fonts
  • various character sets
  • outlines
  • links

This module works on POSIX and Windows platforms.

Implementation

LuaHPDF conforms to the Lua 5.2 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.

Building and installing LuaHPDF

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.

Creating PDF files

The steps in creating a basic PDF file with LuaHPDF include

  • loading the module with the 'require' function
  • creating a document
  • adding one or more pages
  • obtaining a font and registering it with a page
  • writing text
  • saving the file
  • freeing the document

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.

Reporting issues

You're encouraged to provide suggestions and bug reports about LuaHPDF in this software's issue tracker.

Thanks

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.

  • Andrea D'Amore who provided tips for compiling on OS X and packaging.

  • Clerk Ma who provided instructions and makefiles for building with Visual Studio.

License

Like Lua, this software is released under the MIT license.

luahpdf's People

Contributors

doub avatar jung-kurt avatar msva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

luahpdf's Issues

error: unknown type name ‘HPDF_Error’

hi,
now i am using Ubuntu 12.04 in x_86_64. gcc 4.6.3. I just download libharu-RELEASE_2_2_0.tar.gz and complie it from source.
when i try to complie your LuaHPDF, it says that the "HPDF_Error" is an unknown type.

compile output:
In file included from hpdf.c:10:0:
/usr/local/include/hpdf.h:166:19: error: unknown type name ‘HPDF_Error’
hpdf.c: In function ‘luaopen_hpdf’:
hpdf.c:3944:3: warning: implicit declaration of function ‘luaL_setfuncs’ [-Wimplicit-function-declaration]

thanks

malloc issue on OS X

What steps will reproduce the problem?
2. start the Lua interpreter
2. load built hpdf.so
3. quit the Lua interpreter (ctrl-D)

What is the expected output? What do you see instead?
Nothing. An error about freeing a non allocated pointer.

What version of the product are you using? On what operating system?
1.0 on OS X 10.6.5

Please provide any additional information below.

Here's full output:
$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(package.cpath)
./?.so;/opt/local/lib/lua/5.1/?.so;/opt/local/lib/lua/5.1/loadall.so
> require'hpdf'
> print(hpdf.VERSION_TEXT)
2.2.0
> 
lua(86919) malloc: *** error for object 0x100232520: pointer being freed was 
not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap
$ 


Original issue reported on code.google.com by [email protected] on 17 Nov 2010 at 9:51

Doesn't generate single quotes

While generating PDFs using luahpdf, i noticed this strange behavior where single quotes would randomly not show up in the PDF, being replaced with a space.

It doesn't happen for double quotes, and it doesn't seems to be a font problem either (I'm using Lato Regular, which does have the single quote character).

MacOSX install

Hi Kurt,

This is a bit of a longshot, but is there any chance you have some advice for building luahpdf on MacOSX?

I'm getting this error:
hpdf.c:257:4 error: use of undeclared identifier 'HPDF_ARRAY_COUNT_ERR'
Plus a bunch more errors that follow the same pattern, saying there are undeclared identifiers.

I've tried changing the Makefile in a variety of ways, but nothing is working.
I've managed to get luahpdf installed on a linux machine, but for some reason can't get it working on OSX at all.

Thanks for your time

SaveToFile error when there's no write permission

What steps will reproduce the problem?
1. install luahpdf systemwide
2. change working directory to source tree
3. chmod -x demo/
4. cd demo
5. lua font_demo.lua

Program exit with error 1, it should give a warning about not having write 
permission and exit gracefully.
Actual output is:
{{{
lua: HPDF error 0x1017, detail 13
stack traceback:
    [C]: in function 'SaveToFile'
    font_demo.lua:93: in main chunk
    [C]: ?
}}}

I'm on OS X 10.7 using luahpdf 1.1 with libharu 2.2.1 and lua 5.1.4, all 
installed with MacPorts.

Original issue reported on code.google.com by [email protected] on 27 Feb 2012 at 11:43

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.