[stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

Post your working scripts, libraries and tools
Albireo
Posts: 1311
Joined: 16 Oct 2013, 13:53

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

08 Jan 2019, 21:06

Can it be something with hpdf.ahk?
I use for example .:
- HPDF_SetPageMode
- HPDF_CreateOutline
- HPDF_Outline_SetOpened
and so on...

Code: Select all

PageNo := A_Index - 1
Page[%PageNo%] := HPDF_AddPage(hDoc)
HPDF_Page_SetSize(Page[%PageNo%], "A4", "PORTRAIT")
PapW := HPDF_Page_GetWidth(Page[%PageNo%])	; A4 => 595,276001
PapH := HPDF_Page_GetHeight(Page[%PageNo%])	; A4 => 841,890015
In the example above
PageNo .: 0
No value in the PapW and PapH….

Has something happend to AHK version 1.1.30 ?
(The problems with Libharu began when AHK was upgraded.
Now I only get empty pages with the old AHK...)
gwarble
Posts: 461
Joined: 30 Sep 2013, 15:01

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

08 Jan 2019, 21:19

Could be, I haven't fully tested every function/option

Start by stripping out what you can and see if you can get it to generate reliably, then add back in options until you find the culprit? Or start with a working example and add/adapt into your end result step by step and try to figure out where it breaks
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
burque505
Posts: 1398
Joined: 22 Jan 2017, 19:37

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

09 Jan 2019, 09:17

@Albireo, possibly. I had a similar occurrence, as I recall, which I ended up solving with this snippet from my post above:

Code: Select all

         FileGetSize, LogoSize, ahk.png
         FileRead, LogoData, *c ahk.png
         hImg := HPDF_LoadPngImageFromMem(hDoc, &LogoData, LogoSize)
or in another instance:

Code: Select all

hImg := HPDF_LoadPngImageFromFile(hDoc, "ahk.png")
 ;hImg := HPDF_LoadPngImageFromMem(hDoc, &LogoData, LogoSize)
but I have no clue whether either of these will apply for you.
Good luck!
Regards,
burque505
burque505
Posts: 1398
Joined: 22 Jan 2017, 19:37

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

09 Jan 2019, 11:02

@gwarble, I was able to compile a 32-bit libhpdf.dll for v2.30, but it doesn't work for me yet so far. I can see all the functions with NirSoft's dllexp.exe, though.
Neither libpng or zlib was included in the compile, unfortunately.
I'm attaching it in case you have some luck with it. I'll try to compile a 64-bit version when I get some time, too.
libhpdf.zip
(443.99 KiB) Downloaded 42 times
Albireo
Posts: 1311
Joined: 16 Oct 2013, 13:53

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

09 Jan 2019, 19:22

Information!
Now to create my PDF:s works with the AHK ANSI 32-bit 1.1.25.01 and LibHaru-2.0.8 again!
(the solution was change from Page[%PageNo%] to Page_%PageNo% - no idea why!)

But if I use AHK UNICODE 64-bit 1.1.30.01 and LibHaru-2.0.8 I got nothing!

Code: Select all

; load the library
hpdfDllFile := A_ScriptDir "\LibHaru\libhpdf.dll"
hDll := HPDF_LoadDLL(hpdfDllFile)

;create new document in memory
hDoc := HPDF_New("error","000")
The result was .:
hDoc =
hDll = 0
gwarble
Posts: 461
Joined: 30 Sep 2013, 15:01

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

10 Jan 2019, 08:44

Burque:
Thanks i'll try it out

Albireo:
The dll has to be 64bit to work with AHK U64

I think []'s were disallowed in normal variable names at some point
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
gwarble
Posts: 461
Joined: 30 Sep 2013, 15:01

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

01 Nov 2019, 15:05

Has anyone had any luck loading external fonts?

fontname := HPDF_LoadTTFontFromFile(hDoc,"C:\3of9.ttf",1)

should load up the TrueType font and return the font name for use with

font := HPDF_GetFont(hDoc, fontname, 0)

so in this case it should return "3 of 9 Barcode" but its only returning 0 for any TTF fonts I try, in Ansi or Unicode, any thoughts?

Code: Select all

HPDF_LoadTTFontFromFile(ByRef hDoc, file_name, embedding) {
   Return, DllCall("libhpdf\HPDF_LoadTTFontFromFile", UPtr, hDoc, AStr, file_name, "Ptr", embedding, "Cdecl ptr")
}
Edit: just saw this, but dont understand it:
Haru can use only TrueType fonts which has cmap of unicode and following tables.

"OS/2", "cmap", "cvt ", "fpgm", "glyf", "head", "hhea", "hmtx", "loca", "maxp", "name", "post", "prep"


Edit: ok, so the library needs updating the last parameter to the DllCall above "Cdecl AStr" to get the returned name! update to library needed
also the font needs the cmap, which mine didn't have, but I was able to load it into FontForge and save a copy with the cmap and it works

Code: Select all

 fontname := HPDF_LoadTTFontFromFile(hDoc,"3of9Barcode.ttf", 1)
 font := HPDF_GetFont(hDoc, fontname, 0)
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
list
Posts: 197
Joined: 26 Mar 2014, 14:03
Contact:

Re: [stdlib] Wrapper for libHaru (creates PDFs) - now with Unicode 32 and 64-bit support

28 Nov 2020, 09:19

Just a bump to say thanks. I had a need for it last week, I had to create unique footers in a large number of PDFs so I prepared one page PDFs with the correct text with this library and then used pdftk to "merge" the footer with the original PDF. Only a few minutes work in total :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: gwarble and 35 guests