haru
Tcl bindings for libharu PDF library.
My motivation was to be able to integrate a 3D file in a pdf, unfortunately for me this pure Tcl library
pdf4tcl can not do it. That’s why this library was born...
Another similar project had already written this in Tcl, without dependencies. You can find here, functions are the same, but it does not include the latest libharu
updates.
package require haru
set page_title "haru Tcl bindings for libharu..."
# init haru pdf...
set pdf [HPDF_New]
# add a new page object.
set page [HPDF_AddPage $pdf]
# page format
HPDF_Page_SetSize $page HPDF_PAGE_SIZE_A4 HPDF_PAGE_PORTRAIT
# page size
set height [HPDF_Page_GetHeight $page]
set width [HPDF_Page_GetWidth $page]
# set font and size
set def_font [HPDF_GetFont $pdf "Helvetica" ""]
HPDF_Page_SetFontAndSize $page $def_font 24
# get text size
set tw [HPDF_Page_TextWidth $page [haru::hpdf_encode $page_title]]
# write text
HPDF_Page_BeginText $page
HPDF_Page_TextOut $page [expr {($width - $tw) / 2}] [expr {$height - 50}] [haru::hpdf_encode $page_title]
HPDF_Page_EndText $page
# save the document to a file
HPDF_SaveToFile $pdf haru.pdf
# free...
HPDF_Free $pdf
Some characters may not display correctly when you want to add text for certain functions HPDF_Page_TextOut
, HPDF_Page_ShowText
...
For this, use this pure Tcl
function haru::hpdf_encode arg1 ?arg2
:
arg1
- textarg2
(optional argument) - type encoding (see list here) by default is set toStandardEncoding (cp1252)
See demo folder for more examples...
Not really... But for libharu
there is this one.
To Ashok P. Nadkarni for helping me understand Tcl cffi
package and libharu
.
haru is covered under the terms of the MIT license.
- 10-02-2022 : 1.0
- Initial release.