Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tavikukko/lua-resty-hpdf
https://github.com/tavikukko/lua-resty-hpdf
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/tavikukko/lua-resty-hpdf
- Owner: tavikukko
- Created: 2013-12-31T14:41:46.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-08T00:45:57.000Z (almost 11 years ago)
- Last Synced: 2024-02-14T05:34:04.230Z (9 months ago)
- Language: Lua
- Size: 234 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-resty - lua-resty-hpdf - based libHaru (PDF) library for OpenResty (Libraries)
README
lua-resty-hpdf
==============
LuaJIT FFI-based libHaru (PDF) library for OpenResty.usage
--------------local hpdf = require "hpdf"
local left = 25;
local top = 545;
local right = 200;
local bottom = top - 40;
local text = "The quick brown fox jumps over the lazy dog."
local pdf = hpdf.new()
pdf.encoder:use('utf')
pdf.font:labels(0, "LOWER_ROMAN", 1, "")local fontname = pdf.font:load("/usr/local/openresty/nginx/lua/DejaVuSans.ttf", true)
local font = pdf.font:get(fontname, "UTF-8")
local page = pdf.pages:add()
page:set_size("A5", "PORTRAIT")
page:text_leading(20)grid(pdf, page)
-- LEFT
page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "demo align LEFT")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "LEFT", nil)
page:end_text()-- RIGTH
left = 220;
right = 395;
page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "demo align LEFT")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "RIGHT", nil)
page:end_text()-- CENTER
left = 25;
top = 475;
right = 200;
bottom = top - 40;page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "demo align CENTER")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "CENTER", nil)
page:end_text()-- JUSTIFY
left = 220
right = 395page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "demo align JUSTIFY")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "JUSTIFY", nil)
page:end_text()-- Skewed coordinate system
local angle1 = 5
local angle2 = 10
local rad1 = angle1 / 180 * 3.141592
local rad2 = angle2 / 180 * 3.141592left = 0
top = 40
right = 175
bottom = 0page:gsave()
page:concat(1, math.tan(rad1), math.tan(rad2), 1, 25, 350)
page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "Skewed coordinate system")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "LEFT", nil)
page:end_text()
page:grestore()-- Rotated coordinate system
page:gsave()angle1 = 5
rad1 = angle1 / 180 * 3.141592
left = 0
top = 40
right = 175
bottom = 0page:concat(math.cos(rad1), math.sin(rad1), -math.sin(rad1), math.cos(rad1), 220, 350)
page:rectangle(left, bottom, right - left, top - bottom)
page:stroke()
page:set_font_and_size(font, 8)
page:begin_text()
page:text_out(left, top + 3, "Rotated coordinate system")
page:set_font_and_size(font, 10)
page:text_rect(left, top, right, bottom, text, "LEFT", nil)
page:end_text()
page:grestore()-- text along a circle
angle1 = 360 / string.len(text)
angle2 = 180page:gray_stroke(0)
page:circle(210, 190, 145)
page:circle(210, 190, 113)
page:stroke()
page:begin_text()
page:set_font_and_size(font, 15)for i = 0, string.len(text) - 1, 1 do
rad1 = (angle2 - 90) / 180 * 3.141592
rad2 = angle2 / 180 * 3.141592
local x = 210 + math.cos(rad2) * 122
local y = 190 + math.sin(rad2) * 122
page:text_matrix(math.cos(rad1), math.sin(rad1), -math.sin(rad1), math.cos(rad1), x, y)
local chr = text:sub(i,i)
page:text_show(chr)
angle2 = angle2 - angle1
endpage:end_text()
pdf:save('document.pdf')
pdf:free()