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

Post your working scripts, libraries and tools for AHK v1.1 and older
Albireo
Posts: 1821
Joined: 16 Oct 2013, 13:53

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

Post by Albireo » 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...)

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 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: 1747
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 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: 1747
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 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 177 times

Albireo
Posts: 1821
Joined: 16 Oct 2013, 13:53

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

Post by Albireo » 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

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 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 . . . .

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 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: 224
Joined: 26 Mar 2014, 14:03
Contact:

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

Post by list » 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 :)

User avatar
labrint
Posts: 386
Joined: 14 Jun 2017, 05:06
Location: Malta

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

Post by labrint » 12 Mar 2024, 09:34

Guys, can anyone produce a script that can print out these characters Aa Bb Ċċ Dd Ee Ff Ġġ Gg Għgħ Hh Ħħ Ii Ieie Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Zz Żż (Maltese character set) on a pdf using libharu?

I'm having trouble printing anything other than the English alphabet. I already use libharu wrapper and dlls.

Code: Select all

	font := HPDF_GetFont(hDoc, "Helvetica-Bold", 0)
	HPDF_Page_SetFontAndSize(page, font, 8)  ; Convert font size from mm to points


	text := "this is a test"

	HPDF_Page_BeginText(page)
	HPDF_Page_MoveTextPos(page, leftMargin, pageHeight - topMargin - mmToPoints(3))  ; Adjust Y position for font size, converted to points
	HPDF_Page_ShowText(page, text)
	HPDF_Page_EndText(page)
I want to be able to print the text also if it has the Maltese Characters above.

I tried loading a different font from the windows font folder such as Arial and encoding it to iso-8859-3
https://www.marxists.org/admin/charsets/iso-8859-3.htm

I tried encoding my ahk text file to UTF 8 and UTF 8 bom yet no success.
I tried converting the text from ansi to utf and then processing the utf string.
Spent a lot of hours trying to do this to no success.

Please help

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 12 Mar 2024, 13:57

I've not used unicode/extended characters like that and only get ?s in my current app, but I am able to use a custom barcode font.

Did you try HPDF_SetCurrentEncoder(hDoc, encoding_name)?

Note to self for next attempt to compile dll of new version 2.4.4 with zlib and libpng:
https://github.com/libharu/libharu/issues/135
https://www.freshports.org/print/libharu/
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 12 Mar 2024, 16:11

doesn't work with your characters ĊċĠġħħĦħ, but if I use this third parameter it works for these characters àèìòù:
font := HPDF_GetFont(hDoc, "Helvetica", "WinAnsiEncoding") or ISO8859-3
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

User avatar
labrint
Posts: 386
Joined: 14 Jun 2017, 05:06
Location: Malta

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

Post by labrint » 13 Mar 2024, 02:52

Exactly. Check out this
image.png
image.png (319.74 KiB) Viewed 1851 times
The characters you mentioned don't have a special number at the bottom, but my Maltese characters do. Maybe that has something to do with it.
Do you know how to use UTF-8 as an encoding?

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 13 Mar 2024, 09:57

I'm not sure but I will play around with it

Code: Select all

HPDF_SetCurrentEncoder(pdf, "UTF-8")
HPDF_GetFont(pdf, HPDF_LoadTTFontFromFile(pdf, "arial.ttf", HPDF_TRUE), "UTF-8")
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

list
Posts: 224
Joined: 26 Mar 2014, 14:03
Contact:

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

Post by list » 13 Mar 2024, 15:21

Perhaps a newer version of the DLL is needed - if you look at the changelog libHaru 2.3.0RC1
* Added support for 1- and 2-byte UTF8 codes. (Clayman)

I do see "HPDF_SetCurrentEncoder" when I do a simple search in the DLL so it might just be included.

Did find this "instruction" to compile 2.3.0 using visualstudio 2019 https://github.com/mryssng/libharu-VisualStudio2019

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 13 Mar 2024, 16:43

thanks for the link, the libharu site says 2.3.0 is the latest but the linked github goes up to 2.4.4

I'd love to get a compiled version of the latest including libpng and zlib dependencies compiled all in one dll (well one 32bit and one 64bit), i failed last time I tried but will attempt again
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

User avatar
labrint
Posts: 386
Joined: 14 Jun 2017, 05:06
Location: Malta

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

Post by labrint » 14 Mar 2024, 09:24

I have libhpdf.dll libpng15.dll and libpng64-15.dll Does anyone have the newer ones or know where I can download them?

Edit: I think someone knowledgable in C needs to compile them using the compiler (MinGW) from my very limited understanding (and chatgpt).

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 15 Mar 2024, 19:48

this comment in the library confirms:
HPDF_UseUTFEncodings(&hDoc) { ; v2.3.0+
you might want to reach out on other forums for help compiling the newest version (and if you do, try to get 32 and 64 bit versions compiled without dependencies on zlib, libpng, or msvcrt0
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

vmech
Posts: 467
Joined: 25 Aug 2019, 13:03

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

Post by vmech » 16 Mar 2024, 07:58

gwarble wrote:
15 Mar 2024, 19:48
and if you do, try to get 32 and 64 bit versions compiled without dependencies on zlib, libpng, or msvcrt
А в чём, по Вашему мнению, могут заключаться сложности ?
MinGW прекрасно компилирует библиотеки обеих разрядностей. И без каких либо зависимостей.

[Mod edit: Added translation:]
DeepL wrote:What do you think could be the problem?
MinGW compiles libraries of both bit sizes perfectly. And without any dependencies.
Please post your script code inside [code] ... [/code] block. Thank you.

User avatar
gwarble
Posts: 530
Joined: 30 Sep 2013, 15:01

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

Post by gwarble » 17 Mar 2024, 01:42

Only that I don't know what I'm doing... I think I tried it with GCC years ago, I'll try MinGW next time but thanks for answering, I see that you have already solved it in the v2 forum a few months ago! (I've not started using v2 yet but I just converted the library to be v2 compatible yesterday, tomorrow I will try the .dlls you posted (and probably the new library I assume its better) I only started looking at this library that I use hundreds of times a week because of the question asked above.

great news

labrint: check out this thread, seems like the problem is solved
viewtopic.php?f=82&t=122731&p=547608&hilit=zlib.dll#p547608

first attempt and the last .dll you posted works for me but not with .png, I'll play around with it tomorrow but I was hoping libpng was compiled in.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

User avatar
labrint
Posts: 386
Joined: 14 Jun 2017, 05:06
Location: Malta

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

Post by labrint » 17 Mar 2024, 02:50

Does it have to be v2.0? I have many v 1 scripts that could become broken if I upgrade to V2.0

Post Reply

Return to “Scripts and Functions (v1)”