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

Post your working scripts, libraries and tools
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

20 Dec 2018, 23:39

Hey all,
Many thanks to the libHaru authors and Thrawn for the original wrapper [here: https://autohotkey.com/board/topic/4065 ... 009-05-11/], I have made minimal changes to allow support from all versions of AutoHotkey, Unicode 32-bit, Unicode 64-bit, and Ansi 32-bit:

Minimally tested working with libhpdf.dll v2.2.1 (see attached for libhpdf.dll, needs libpng15.dll) as well as v2.1.0 (needs zlib.dll and libpng13.dll) on Windows 7 and XP, feedback appreciated on issues

Example scripts to come...

Code: Select all

;----------------------------------------------------
;-- HPDF - libHaru Wrapper          - Thrawn  2009 --
;--      + Unicode 32&64bit support - gwarble 2018 --
;----------------------------------------------------

HPDF_LoadDLL(dll) {
   return, DllCall("LoadLibrary", "Str", dll)
}
HPDF_UnloadDLL(hDll) {
   DllCall("FreeLibrary", "UPtr", hDll)
}
HPDF_New(user_error_fn,user_data) {
   Return, DllCall("libhpdf\HPDF_New", "UPtr", user_error_fn, "UPtr", user_data, "Cdecl ptr")
}
HPDF_NewEx(user_error_fn,user_data) {
   Return, DllCall("libhpdf\HPDF_New", "UPtr", user_error_fn, "UPtr", user_data, "Cdecl ptr")
}
HPDF_Free(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_Free", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_NewDoc(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_NewDoc", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_FreeDoc(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_FreeDoc", "UPtr", hDoc, "Cdecl ptr")
} 
HPDF_FreeDocAll(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_FreeDocAll", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_SaveToFile(ByRef hDoc, filename) {
   Return, DllCall("libhpdf\HPDF_SaveToFile", "UPtr", hDoc, "AStr", filename, "Cdecl ptr")
}
HPDF_HasDoc(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_HasDoc", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_SetErrorHandler(ByRef hDoc, ByRef errorhandler) {
   Return, DllCall("libhpdf\HPDF_SetErrorHandler", "UPtr", hDoc, "UPtr", errorhandler, "Cdecl ptr")
}
HPDF_GetError(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetError", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_ResetError(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_ResetError", "UPtr", hDoc, "Cdecl ptr")
}

;----------------------------------------------------
;---- Pages -----------------------------------------
;----------------------------------------------------
HPDF_SetPagesConfiguration(ByRef hDoc, page_per_pages) {
   Return, DllCall("libhpdf\HPDF_SetPagesConfiguration", "UPtr", hDoc, "Ptr", page_per_pages, "Cdecl ptr")
}
HPDF_SetPageLayout(ByRef hDoc, layout) {
   Return, DllCall("libhpdf\HPDF_SetPageLayout", "UPtr", hDoc, "Ptr", layout, "Cdecl ptr")
}
HPDF_GetPageLayout(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetPageLayout", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_SetPageMode(ByRef hDoc, mode) {
   HPDF_PAGE_MODE_USE_NONE := 0
   HPDF_PAGE_MODE_USE_OUTLINE := 1
   HPDF_PAGE_MODE_USE_THUMBS := 2
   HPDF_PAGE_MODE_FULL_SCREEN := 3
   thisMode := HPDF_PAGE_MODE_%mode%
   Return, DllCall("libhpdf\HPDF_SetPageMode", "UPtr", hDoc, "Ptr", thisMode, "Cdecl ptr")
}
HPDF_GetPageMode(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetPageMode", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_SetOpenAction(ByRef hDoc, ByRef open_action) {
   Return, DllCall("libhpdf\HPDF_SetOpenAction", "UPtr", hDoc, "UPtr", open_action, "Cdecl ptr")
}
HPDF_GetCurrentPage(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetCurrentPage", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_AddPage(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_AddPage", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_InsertPage(ByRef hDoc, ByRef target) {
   Return, DllCall("libhpdf\HPDF_InsertPage", "UPtr", hDoc, "UPtr", target, "Cdecl ptr")
}

;----------------------------------------------------
;---- Page ------------------------------------------
;----------------------------------------------------
HPDF_Page_SetWidth(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetWidth", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetHeight(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetHeight", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetSize(ByRef hPage, size, direction) {
   HPDF_PAGE_SIZE_LETTER = 0
   HPDF_PAGE_SIZE_LEGAL = 1
   HPDF_PAGE_SIZE_A3 = 2
   HPDF_PAGE_SIZE_A4 = 3
   HPDF_PAGE_SIZE_A5 = 4
   HPDF_PAGE_SIZE_B4 = 5
   HPDF_PAGE_SIZE_B5 = 6
   HPDF_PAGE_SIZE_EXECUTIVE = 7
   HPDF_PAGE_SIZE_US4x6 = 8
   HPDF_PAGE_SIZE_US4x8 = 9
   HPDF_PAGE_SIZE_US5x7 = 10
   HPDF_PAGE_SIZE_COMM10 = 11
   HPDF_PAGE_SIZE_EOF = 12
   HPDF_PAGE_PORTRAIT = 0
   HPDF_PAGE_LANDSCAPE = 1
   thisSize := HPDF_PAGE_SIZE_%size%
   thisDirection := HPDF_PAGE_%direction%
   Return, DllCall("libhpdf\HPDF_Page_SetSize", "UPtr", hPage, "UPtr", thisSize, "UPtr", thisDirection, "Cdecl ptr")
}
HPDF_Page_SetRotate(ByRef hPage, angle) {
   Return, DllCall("libhpdf\HPDF_Page_SetRotate", "UPtr", hPage, "Ptr", angle, "Cdecl ptr")
}
HPDF_Page_GetWidth(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetWidth", "UPtr", hPage, "Cdecl Float")
}
HPDF_Page_GetHeight(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetHeight", "UPtr", hPage, "Cdecl Float")
}
HPDF_Page_CreateDestination(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_CreateDestination", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_CreateTextAnnot(ByRef hPage, rect, text, encoder) {
   Return, DllCall("libhpdf\HPDF_Page_CreateTextAnnot", "UPtr", hPage, "UPtr", rect, "AStr", text, "UPtr", encoder, "Cdecl ptr")
}
HPDF_Page_CreateLinkAnnot(ByRef hPage, ByRef rect, ByRef dst) {
   Return, DllCall("libhpdf\HPDF_Page_CreateLinkAnnot", "UPtr", hPage, "UPtr", &rect, "UPtr", dst, "Cdecl ptr")
}
HPDF_Page_CreateURILinkAnnot(ByRef hPage, ByRef rect, uri) {
   Return, DllCall("libhpdf\HPDF_Page_CreateURILinkAnnot", "UPtr", hPage, "UPtr", rect, "AStr", uri, "Cdecl ptr")
}
HPDF_Page_TextWidth(ByRef hPage, text) {
   Return, DllCall("libhpdf\HPDF_Page_TextWidth", "UPtr", hPage, "AStr", text, "Cdecl Float")
}
HPDF_Page_MeasureText(ByRef hPage, text, width, wordwrap, real_width) {
   if real_width = 0
      Return, DllCall("libhpdf\HPDF_Page_MeasureText", "UPtr", hPage, "AStr", text, "Float", width, "Ptr", wordwrap, "Ptr", 0, "Cdecl ptr")
   else
      Return, DllCall("libhpdf\HPDF_Page_MeasureText", "UPtr", hPage, "AStr", text, "Float", width, "Ptr", wordwrap, "Float", real_width, "Cdecl ptr")
}
HPDF_Page_GetGMode(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetGMode", "UPtr", hPage, "Cdecl Char")
}
HPDF_Page_GetCurrentPos(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCurrentPos", "UPtr", hPage, "Cdecl Uint")
}
HPDF_Page_GetCurrentTextPos(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCurrentTextPos", "UPtr", hPage, "Cdecl Uint")
}
HPDF_Page_GetCurrentFont(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCurrentFont", "UPtr", hPage)
}
HPDF_Page_GetCurrentFontSize(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCurrentFontSize", "UPtr", hPage, "Cdecl Float")
}
HPDF_Page_GetTransMatrix(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetTransMatrix", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetLineWidth(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetLineWidth", "UPtr", hPage, "Cdecl Float")
}
HPDF_Page_GetLineCap(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetLineCap", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetLineJoin(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetLineJoin", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetMiterLimit(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetMiterLimit", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetDash(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetDash", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetFlat(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetFlat", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetCharSpace(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCharSpace", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetWordSpace(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetWordSpace", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetHorizontalScalling(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetHorizontalScalling", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetHorizontalScaling(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetHorizontalScalling", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetTextLeading(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetTextLeading", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetTextRenderingMode(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetTextRenderingMode", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetTextRise(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetTextRise", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetRGBFill(ByRef hPage) {
   return, DllCall("libhpdf\HPDF_Page_GetRGBFill", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetRGBStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetRGBStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetCMYKFill(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCMYKFill", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetCMYKStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetCMYKStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetGrayFill(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetGrayFill", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetGrayStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetGrayStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetStrokingColorSpace(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetStrokingColorSpace", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetFillingColorSpace(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetFillingColorSpace", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetTextMatrix(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetTextMatrix", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GetGStateDepth(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GetGStateDepth", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_SetSlideShow(ByRef hPage, type, disp_time, trans_time) {
   HPDF_TS_WIPE_RIGHT = 0
   HPDF_TS_WIPE_UP = 1
   HPDF_TS_WIPE_LEFT = 2
   HPDF_TS_WIPE_DOWN = 3
   HPDF_TS_BARN_DOORS_HORIZONTAL_OUT = 4
   HPDF_TS_BARN_DOORS_HORIZONTAL_IN = 5
   HPDF_TS_BARN_DOORS_VERTICAL_OUT = 6
   HPDF_TS_BARN_DOORS_VERTICAL_IN = 7
   HPDF_TS_BOX_OUT = 8
   HPDF_TS_BOX_IN = 9
   HPDF_TS_BLINDS_HORIZONTAL = 10
   HPDF_TS_BLINDS_VERTICAL = 11
   HPDF_TS_DISSOLVE = 12
   HPDF_TS_GLITTER_RIGHT = 13
   HPDF_TS_GLITTER_DOWN = 14
   HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT = 15
   HPDF_TS_REPLACE = 16
   HPDF_TS_EOF = 17
   thisType := HPDF_TS_%type%
   Return, DllCall("libhpdf\HPDF_Free", "UPtr", hPage, "Ptr", thisType, "Float", disp_time, "Float", trans_time, "Cdecl ptr")
}

;----------------------------------------------------
;---- Destination -----------------------------------
;----------------------------------------------------
HPDF_Destination_SetXYZ(ByRef dst, left, top, zoom) {
   Return, DllCall("libhpdf\HPDF_Destination_SetXYZ", "UPtr", dst, "Float", left, "Float", top, "Float", zoom, "Cdecl ptr")
}
HPDF_Destination_SetFit(ByRef dst) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFit", "UPtr", dst, "Cdecl ptr")
}
HPDF_Destination_SetFitH(ByRef dst, top) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitH", "UPtr", dst, "Float", top, "Cdecl ptr")
}
HPDF_Destination_SetFitV(ByRef dst, left) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitV", "UPtr", dst, "Float", left, "Cdecl ptr")
}
HPDF_Destination_SetFitR(ByRef dst, left, bottom, right, top) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitR", "UPtr", dst, "Float", left, "Float", bottom, "Float", right, "Float", top, "Cdecl ptr")
}
HPDF_Destination_SetFitB(ByRef dst) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitB", "UPtr", dst, "Cdecl ptr")
}
HPDF_Destination_SetFitBH(ByRef dst, top) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitBH", "UPtr", dst, "Float", top, "Cdecl ptr")
}
HPDF_Destination_SetFitBV(ByRef dst, top) {
   Return, DllCall("libhpdf\HPDF_Destination_SetFitBV", "UPtr", dst, "Float", top, "Cdecl ptr")
}

;----------------------------------------------------
;---- Encodings -------------------------------------
;----------------------------------------------------
HPDF_GetEncoder(ByRef hDoc, encoding_name) {
   Return, DllCall("libhpdf\HPDF_GetEncoder", "UPtr", hDoc, "AStr", encoding_name, "Cdecl ptr")
}
HPDF_GetCurrentEncoder(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetCurrentEncoder", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_SetCurrentEncoder(ByRef hDoc, encoding_name) {
   Return, DllCall("libhpdf\HPDF_SetCurrentEncoder", "UPtr", hDoc, "AStr", encoding_name, "Cdecl ptr")
}
HPDF_UseJPEncodings(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseJPEncodings", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseKREncodings(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseKREncodings", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseCNSEncodings(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseCNSEncodings", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseCNTEncodings(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseCNTEncodings", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseUTFEncodings(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseUTFEncodings", "UPtr", hDoc, "Cdecl ptr")
}
;----------------------------------------------------
;---- Font ------------------------------------------
;----------------------------------------------------
HPDF_AddPageLabel(ByRef hDoc, page_num, style, first_page, prefix) {
   HPDF_PAGE_NUM_STYLE_DECIMAL = 0
   HPDF_PAGE_NUM_STYLE_UPPER_ROMAN = 1
   HPDF_PAGE_NUM_STYLE_LOWER_ROMAN = 2
   HPDF_PAGE_NUM_STYLE_UPPER_LETTERS = 3
   HPDF_PAGE_NUM_STYLE_LOWER_LETTERS = 4
   HPDF_PAGE_NUM_STYLE_EOF = 5
   thisStyle := HPDF_PAGE_NUM_STYLE_%style%
   Return, DllCall("libhpdf\HPDF_AddPageLabel", "UPtr", hDoc, "Ptr", page_num, "Ptr", thisStyle, "Ptr", first_page, "AStr", prefix, "Cdecl ptr")
}

HPDF_GetFont(ByRef hDoc, font_name, encoding_name) {
   if encoding_name = 0
      Return, DllCall("libhpdf\HPDF_GetFont", "UPtr", hDoc, "AStr", font_name, "Ptr", 0)
   else
      Return, DllCall("libhpdf\HPDF_GetFont", "UPtr", hDoc, "AStr", font_name, "AStr", encoding_name, "Cdecl ptr")
}
HPDF_GetFont2(ByRef hDoc, ByRef font_name, encoding_name) {
   if encoding_name = 0
      Return, DllCall("libhpdf\HPDF_GetFont", "UPtr", hDoc, "UPtr", font_name, "Ptr", 0)
   else
      Return, DllCall("libhpdf\HPDF_GetFont", "UPtr", hDoc, "UPtr", font_name, "AStr", encoding_name, "Cdecl ptr")
}
HPDF_LoadType1FontFromFile(ByRef hDoc, afmfilename, pfmfilename) {
   Return, DllCall("libhpdf\HPDF_LoadType1FontFromFile", "UPtr", hDoc, "AStr", afmfilename, "AStr", pfmfilename, "Cdecl ptr")
}
HPDF_LoadTTFontFromFile(ByRef hDoc, file_name, embedding) {
   Return, DllCall("libhpdf\HPDF_LoadTTFontFromFile", "UPtr", hDoc, "AStr", file_name, "Ptr", embedding, "Cdecl ptr")
}
HPDF_LoadTTFontFromFile2(ByRef hDoc, file_name, index, embedding) {
   Return, DllCall("libhpdf\HPDF_LoadTTFontFromFile2", "UPtr", hDoc, "AStr", file_name, "Ptr", index, "Ptr", embedding, "Cdecl ptr")
}
HPDF_UseJPFonts(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseJPFonts", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseKRFonts(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseKRFonts", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseCNSFonts(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseCNSFonts", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_UseCNTFonts(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_UseCNTFonts", "UPtr", hDoc, "Cdecl ptr")
}

;----------------------------------------------------
;---- Attributes ------------------------------------
;----------------------------------------------------
HPDF_SetInfoAttr(ByRef hDoc, type, value) {
   HPDF_INFO_AUTHOR = 2
   HPDF_INFO_CREATOR = 3
   HPDF_INFO_PRODUCER = 4
   HPDF_INFO_TITLE = 5
   HPDF_INFO_SUBJECT = 6
   HPDF_INFO_KEYWORDS = 7
   HPDF_INFO_EOF = 8
   thisType := HPDF_INFO_%type%
   Return, DllCall("libhpdf\HPDF_SetInfoAttr", "UPtr", hDoc, "Ptr", thisType, "AStr", value, "Cdecl ptr")
}
HPDF_GetInfoAttr(ByRef hDoc, type) {
   HPDF_INFO_CREATION_DATE = 0
   HPDF_INFO_MOD_DATE = 1
   HPDF_INFO_AUTHOR = 2
   HPDF_INFO_CREATOR = 3
   HPDF_INFO_PRODUCER = 4
   HPDF_INFO_TITLE = 5
   HPDF_INFO_SUBJECT = 6
   HPDF_INFO_KEYWORDS = 7
   HPDF_INFO_EOF = 8
   thisType := HPDF_INFO_%type%
   Return, DllCall("libhpdf\HPDF_GetInfoAttr", "UPtr", hDoc, "Ptr", thisType, "Cdecl ptr")
}
HPDF_SetPassword(ByRef hDoc, owner_passwd, user_passwd) {
   Return, DllCall("libhpdf\HPDF_SetPassword", "UPtr", hDoc, "AStr", owner_passwd, "AStr", user_passwd, "Cdecl ptr")
}
HPDF_SetPermission(ByRef hDoc, permission) {
   StringReplace, permission, permission, READ, 0
   StringReplace, permission, permission, PRINT, 4
   StringReplace, permission, permission, EDIT_ALL, 8
   StringReplace, permission, permission, COPY, 16
   StringReplace, permission, permission, EDIT, 32
   Return, DllCall("libhpdf\HPDF_SetPermission", "UPtr", hDoc, "Ptr", permission, "Cdecl ptr")
}
HPDF_SetEncryptionMode(ByRef hDoc, mode, key_len) {
   HPDF_ENCRYPT_R2 = 2
   HPDF_ENCRYPT_R3 = 3
   thisMode := HPDF_ENCRYPT_%mode%
   Return, DllCall("libhpdf\HPDF_SetEncryptionMode", "UPtr", hDoc, "Ptr", thisMode, "Ptr", key_len, "Cdecl ptr")
}
HPDF_SetCompressionMode(ByRef hDoc, mode) {
   HPDF_COMP_NONE = 0
   HPDF_COMP_TEXT = 1
   HPDF_COMP_IMAGE = 2
   HPDF_COMP_METADATA = 4
   HPDF_COMP_ALL = 15
   thisMode := HPDF_COMP_%mode%
   Return, DllCall("libhpdf\HPDF_SetCompressionMode", "UPtr", hDoc, "Ptr", thisMode)
}

;----------------------------------------------------
;---- Graphics --------------------------------------
;----------------------------------------------------
HPDF_Page_Arc(ByRef hPage, x, y, radius, ang1, ang2) {
   Return, DllCall("libhpdf\HPDF_Page_Arc", "UPtr", hPage, "Float", x, "Float", y, "Float", radius, "Float", ang1, "Float", ang2, "Cdecl ptr")
}
HPDF_Page_BeginText(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_BeginText", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_Circle(ByRef hPage, x, y, radius) {
   Return, DllCall("libhpdf\HPDF_Page_Circle", "UPtr", hPage, "Float", x, "Float", y, "Float", radius, "Cdecl ptr")
}
HPDF_Page_ClosePath(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_ClosePath", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_ClosePathStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_ClosePathStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_ClosePathEofillStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_ClosePathEofillStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_ClosePathFillStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_ClosePathFillStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_Concat(ByRef hPage, a, b, c, d, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_Concat", "UPtr", hPage, "Float", a, "Float", b, "Float", c, "Float", d, "Float", x, "Float", y, "Cdecl ptr")
}
HPDF_Page_CurveTo(ByRef hPage, x1, y1, x2, y2, x3, y3) {
   Return, DllCall("libhpdf\HPDF_Page_CurveTo", "UPtr", hPage, "Float", x1, "Float", y1, "Float", x2, "Float", y2, "Float", x3, "Float", y3, "Cdecl ptr")
}
HPDF_Page_CurveTo2(ByRef hPage, x2, y2, x3, y3) {
   Return, DllCall("libhpdf\HPDF_Page_CurveTo2", "UPtr", hPage, "Float", x2, "Float", y2, "Float", x3, "Float", y3, "Cdecl ptr")
}
HPDF_Page_CurveTo3(ByRef hPage, x1, y1, x3, y3) {
   Return, DllCall("libhpdf\HPDF_Page_CurveTo3", "UPtr", hPage, "Float", x1, "Float", y1, "Float", x3, "Float", y3, "Cdecl ptr")
}
HPDF_Page_DrawImage(ByRef hPage, ByRef hImage, x, y, width, height) {
   Return, DllCall("libhpdf\HPDF_Page_DrawImage", "UPtr", hPage, "UPtr", hImage, "Float", x, "Float", y, "Float", width, "Float", height, "Cdecl ptr")
}
HPDF_Page_Ellipse(ByRef hPage, x, y, x_radius, y_radius) {
   Return, DllCall("libhpdf\HPDF_Page_Ellipse", "UPtr", hPage, "Float", x, "Float", y, "Float", x_radius, "Float", y_radius, "Cdecl ptr")
}
HPDF_Page_EndPath(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_EndPath", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_EndText(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_EndText", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_Eofill(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_Eofill", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_EofillStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_EofillStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_ExecuteXObject(ByRef hPage, ByRef obj) {
   Return, DllCall("libhpdf\HPDF_Page_ExecuteXObject", "UPtr", hPage, "UPtr", obj, "Cdecl ptr")
}
HPDF_Page_Fill(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_Fill", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_FillStroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_FillStroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GRestore(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GRestore", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_GSave(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_GSave", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_LineTo(ByRef hPage, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_LineTo", "UPtr", hPage, "Float", x, "Float", y)
}
HPDF_Page_MoveTextPos(ByRef hPage, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_MoveTextPos", "UPtr", hPage, "Float", x, "Float", y)
}
HPDF_Page_MoveTextPos2(ByRef hPage, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_MoveTextPos2", "UPtr", hPage, "Float", x, "Float", y)
}
HPDF_Page_MoveTo(ByRef hPage, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_MoveTo", "UPtr", hPage, "Float", x, "Float", y, "Cdecl ptr")
}
HPDF_Page_MoveToNextLine(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_MoveToNextLine", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_Rectangle(ByRef hPage, x, y, width, height) {
   Return, DllCall("libhpdf\HPDF_Page_Rectangle", "UPtr", hPage, "Float", x, "Float", y, "Float", width, "Float", height, "Cdecl ptr")
}
HPDF_Page_SetCharSpace(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetCharSpace", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetCMYKFill(ByRef hPage, c, m, y, k) {
   Return, DllCall("libhpdf\HPDF_Page_SetCMYKFill", "UPtr", hPage, "Float", c, "Float", m, "Float", y, "Float", k, "Cdecl ptr")
}
HPDF_Page_SetCMYKStroke(ByRef hPage, c, m, y, k) {
   Return, DllCall("libhpdf\HPDF_Page_SetCMYKStroke", "UPtr", hPage, "Float", c, "Float", m, "Float", y, "Float", k, "Cdecl ptr")
}
HPDF_Page_SetDash(ByRef hPage, ByRef dash_ptn, num_elem, phase) {
   Return, DllCall("libhpdf\HPDF_Page_SetDash", "UPtr", hPage, "UPtr", dash_ptn, "Ptr", num_elem, "Ptr", phase, "Cdecl ptr")
}
HPDF_Page_SetExtGState(ByRef hPage, ByRef ext_gstate) {
   Return, DllCall("libhpdf\HPDF_Page_SetExtGState", "UPtr", hPage, "UPtr", ext_gstate, "Cdecl ptr")
}
HPDF_Page_SetFontAndSize(ByRef hPage, ByRef font, size) {
   Return, DllCall("libhpdf\HPDF_Page_SetFontAndSize", "UPtr", hPage, "UPtr", font, "Float", size, "Cdecl ptr")
}
HPDF_Page_SetGrayFill(ByRef hPage, gray) {
   Return, DllCall("libhpdf\HPDF_Page_SetGrayFill", "UPtr", hPage, "Float", gray, "Cdecl ptr")
}
HPDF_Page_SetGrayStroke(ByRef hPage, gray) {
   Return, DllCall("libhpdf\HPDF_Page_SetGrayStroke", "UPtr", hPage, "Float", gray, "Cdecl ptr")
}
HPDF_Page_SetHorizontalScalling(ByRef hPage, value) {     ; not a typo scalling = scaling
   Return, DllCall("libhpdf\HPDF_Page_SetHorizontalScalling", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetHorizontalScaling(ByRef hPage, value) {     ; fixed typo scalling = scaling
   Return, DllCall("libhpdf\HPDF_Page_SetHorizontalScalling", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetLineCap(ByRef hPage, line_cap) {
   HPDF_BUTT_END = 0
   HPDF_ROUND_END = 1
   HPDF_PROJECTING_SCUARE_END = 2
   HPDF_LINECAP_EOF = 3
   thisLine_cap := HPDF_%line_cap%
   Return, DllCall("libhpdf\HPDF_Page_SetLineCap", "UPtr", hPage, "Ptr", thisLine_cap, "Cdecl ptr")
}
HPDF_Page_SetLineJoin(ByRef hPage, line_join) {
   HPDF_MITER_JOIN = 0
   HPDF_ROUND_JOIN = 1
   HPDF_BEVEL_JOIN = 2
   HPDF_LINEJOIN_EOF = 3
   thisLine_join := HPDF_%line_join%
   Return, DllCall("libhpdf\HPDF_Page_SetLineJoin", "UPtr", hPage, "Ptr", thisLine_join, "Cdecl ptr")
}
HPDF_Page_SetLineWidth(ByRef hPage, line_width) {
   Return, DllCall("libhpdf\HPDF_Page_SetLineWidth", "UPtr", hPage, "Float", line_width, "Cdecl ptr")
}
HPDF_Page_SetMiterLimit(ByRef hPage, miter_limit) {
   Return, DllCall("libhpdf\HPDF_Page_SetMiterLimit", "UPtr", hPage, "Float", miter_limit, "Cdecl ptr")
}
HPDF_Page_SetRGBFill(ByRef hPage, r, g, b) {
   Return, DllCall("libhpdf\HPDF_Page_SetRGBFill", "UPtr", hPage, "Float", r, "Float", g, "Float", b)
}
HPDF_Page_SetRGBStroke(ByRef hPage, r, g, b) {
   Return, DllCall("libhpdf\HPDF_Page_SetRGBStroke", "UPtr", hPage, "Float", r, "Float", g, "Float", b, "Cdecl ptr")
}
HPDF_Page_SetTextLeading(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetTextLeading", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetTextRenderingMode(ByRef hPage, mode) {
   HPDF_FILL = 0
   HPDF_STROKE = 1
   HPDF_FILL_THEN_STROKE = 2
   HPDF_INVISIBLE = 3
   HPDF_FILL_CLIPPING = 4
   HPDF_STROKE_CLIPPING = 5
   HPDF_FILL_STROKE_CLIPPING = 6
   HPDF_CLIPPING = 7
   HPDF_RENDERING_MODE_EOF = 8
   thisMode := HPDF_%mode%
   Return, DllCall("libhpdf\HPDF_Page_SetTextRenderingMode", "UPtr", hPage, "Ptr", thisMode, "Cdecl ptr")
}
HPDF_Page_SetTextRise(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetTextRise", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_SetWordSpace(ByRef hPage, value) {
   Return, DllCall("libhpdf\HPDF_Page_SetWordSpace", "UPtr", hPage, "Float", value, "Cdecl ptr")
}
HPDF_Page_ShowText(ByRef hPage, text) {
   Return, DllCall("libhpdf\HPDF_Page_ShowText", "UPtr", hPage, "AStr", text, "Cdecl ptr")
}
HPDF_Page_ShowTextNextLine(ByRef hPage, text) {
   Return, DllCall("libhpdf\HPDF_Page_ShowTextNextLine", "UPtr", hPage, "AStr", text, "Cdecl ptr")
}
HPDF_Page_ShowTextNextLineEx(ByRef hPage, word_space, char_space, text) {
   Return, DllCall("libhpdf\HPDF_Page_ShowTextNextLineEx", "UPtr", hPage, "Float", word_space, "Float", char_space, "AStr", text, "Cdecl ptr")
}
HPDF_Page_Stroke(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_Stroke", "UPtr", hPage, "Cdecl ptr")
}
HPDF_Page_TextOut(ByRef hPage, xpos, ypos, text) {
   Return, DllCall("libhpdf\HPDF_Page_TextOut", "UPtr", hPage, "Float", xpos, "Float", ypos, "AStr", text, "Cdecl ptr")
}
HPDF_Page_TextRect(ByRef hPage, left, top, right, bottom, text, align, ByRef len) {
   HPDF_TALIGN_LEFT = 0
   HPDF_TALIGN_RIGHT = 1
   HPDF_TALIGN_CENTER = 2
   HPDF_TALIGN_JUSTIFY = 3
   thisAlignment := HPDF_TALIGN_%align%
   Return, DllCall("libhpdf\HPDF_Page_TextRect", "UPtr", hPage, "Float", left, "Float", top, "Float", right, "Float", bottom, "AStr", text, "Ptr", thisAlignment, "UIntP", len, "Cdecl ptr")
}
HPDF_Page_SetTextMatrix(ByRef hPage, a, b, c, d, x, y) {
   Return, DllCall("libhpdf\HPDF_Page_SetTextMatrix", "UPtr", hPage, "Float", a, "Float", b, "Float", c, "Float", d, "Float", x, "Float", y, "Cdecl ptr")
}
;HPDF_Page_ExecuteXObject()
;HPDF_Page_Eoclip()
HPDF_Page_Clip(ByRef hPage) {
   Return, DllCall("libhpdf\HPDF_Page_Clip", "UPtr", hPage, "Cdecl ptr")
}

;----------------------------------------------------
;---- Images ----------------------------------------
;----------------------------------------------------
HPDF_LoadPngImageFromFile(ByRef hDoc, filename) {
   Return, DllCall("libhpdf\HPDF_LoadPngImageFromFile", "UPtr", hDoc, "AStr", filename, "Cdecl ptr")
}
HPDF_LoadPngImageFromFile2(ByRef hDoc, filename) {
   Return, DllCall("libhpdf\HPDF_LoadPngImageFromFile2", "UPtr", hDoc, "AStr", filename, "Cdecl ptr")
}
HPDF_LoadPngImageFromMem(ByRef hDoc, BufAdr, BufSize) { ; v2.2.0+  ; return hImage
	Return,  DllCall("libhpdf\HPDF_LoadPngImageFromMem", "UPtr", hDoc, "UPtr", BufAdr, "UPtr", BufSize, "Cdecl ptr")
}
HPDF_LoadRawImageFromFile(ByRef hDoc, filename, width, height, color_space) {
   HPDF_CS_DEVICE_GRAY := 0
   HPDF_CS_DEVICE_RGB := 1
   HPDF_CS_DEVICE_CMYK := 2
   thisColor_space := HPDF_CS_DEVICE_%color_space%
   Return, DllCall("libhpdf\HPDF_LoadRawImageFromFile", "UPtr", hDoc, "AStr", filename, "UPtr", width, "UPtr", height, "Ptr", thisColor_space, "Cdecl ptr")
}
HPDF_LoadRawImageFromMem(ByRef hDoc, buf, width, height, color_space, bits_per_component) {
   HPDF_CS_DEVICE_GRAY = 0
   HPDF_CS_DEVICE_RGB = 1
   HPDF_CS_DEVICE_CMYK = 2
   thisColor_space := HPDF_CS_DEVICE_%color_space%
   Return, DllCall("libhpdf\HPDF_LoadRawImageFromMem", "UPtr", hDoc, "UPtr", buf, "Ptr", width, "Ptr", height, "Ptr", color_space, "Ptr", bits_per_component, "Cdecl ptr")
}
HPDF_LoadJpegImageFromFile(ByRef hDoc, filename) {
   Return, DllCall("libhpdf\HPDF_LoadJpegImageFromFile", "UPtr", hDoc, "AStr", filename, "Cdecl ptr")
}
HPDF_LoadJpegImageFromMem(ByRef hDoc, BufAdr, BufSize) { ; v2.2.0+  ; return hImage
	Return,  DllCall("libhpdf\HPDF_LoadJpegImageFromMem", "UPtr", hDoc, "UPtr", BufAdr, "UPtr", BufSize, "Cdecl ptr")
}
HPDF_Image_GetSize(ByRef image) {
   Return, DllCall("libhpdf\HPDF_Image_GetSize", "UPtr", image, "Cdecl ptr")
}
HPDF_Image_GetWidth(ByRef image) {
   Return, DllCall("libhpdf\HPDF_Image_GetWidth", "UPtr", image, "Cdecl ptr")
}
HPDF_Image_GetHeight(ByRef image) {
   Return, DllCall("libhpdf\HPDF_Image_GetHeight", "UPtr", image, "Cdecl ptr")
}
HPDF_Image_GetBitsPerComponent(ByRef image) {
   Return, DllCall("libhpdf\HPDF_Image_GetBitsPerComponent", "UPtr", image, "Cdecl ptr")
}
HPDF_Image_GetColorSpace(ByRef image) {
   Return, DllCall("libhpdf\HPDF_Image_GetColorSpace", "UPtr", image, "Cdecl ptr")
}
HPDF_Image_SetColorMask(ByRef image, rmin, rmax, gmin, gmax, bmin, bmax) {
   Return, DllCall("libhpdf\HPDF_Image_SetColorMask", "UPtr", image, "Ptr", rmin, "Ptr", rmax, "Ptr", gmin, "Ptr", gmax, "Ptr", bmin, "Ptr", bmax)
}
HPDF_Image_SetMaskImage(ByRef image, ByRef mask_image) {
   Return, DllCall("libhpdf\HPDF_Image_SetMaskImage", "UPtr", image, "UPtr", mask_image, "Cdecl ptr")
}

;----------------------------------------------------
;---- Outlines --------------------------------------
;----------------------------------------------------
HPDF_CreateOutline(ByRef hDoc, ByRef parent, title, ByRef encoder) {
   if parent = 0
   {
      if encoder = 0
         Return, DllCall("libhpdf\HPDF_CreateOutline", "UPtr", hDoc, "Ptr", 0, "AStr", title, "Ptr", 0, "Cdecl ptr")
      else
         Return, DllCall("libhpdf\HPDF_CreateOutline", "UPtr", hDoc, "Ptr", 0, "AStr", title, "UPtr", encoder, "Cdecl ptr")
   }
   else
   {
      if encoder = 0
         Return, DllCall("libhpdf\HPDF_CreateOutline", "UPtr", hDoc, "UPtr", parent, "AStr", title, "Ptr", 0, "Cdecl ptr")
      else
         Return, DllCall("libhpdf\HPDF_CreateOutline", "UPtr", hDoc, "UPtr", parent, "AStr", title, "UPtr", encoder, "Cdecl ptr")
   }
}
HPDF_Outline_SetOpened(ByRef outline, opened) {
   Return, DllCall("libhpdf\HPDF_Outline_SetOpened", "UPtr", outline, "Ptr", opened)
}
HPDF_Outline_SetDestination(ByRef outline, ByRef dst) {
   Return, DllCall("libhpdf\HPDF_Outline_SetDestination", "UPtr", outline, "UPtr", dst, "Cdecl ptr")
}

;----------------------------------------------------
;--- Annotations ------------------------------------
;----------------------------------------------------
HPDF_LinkAnnot_SetHighlightMode(ByRef annot,mode) {
   HPDF_ANNOT_NO_HIGHTLIGHT := 0
   HPDF_ANNOT_INVERT_BOX := 1
   HPDF_ANNOT_INVERT_BORDER := 2
   HPDF_ANNOT_DOWN_APPEARANCE := 3
   this_mode := HPDF_ANNOT_%mode%
   Return, DllCall("libhpdf\HPDF_LinkAnnot_SetHighlightMode", "UPtr", annot, "Ptr", thisMode)
}

HPDF_LinkAnnot_SetBorderStyle(ByRef annot,width,dash_on,dash_off) {
   Return, DllCall("libhpdf\HPDF_LinkAnnot_SetBorderStyle", "UPtr", annot, "Float", width, "UPtr", dash_on, "UPtr", dash_off)
}

HPDF_TextAnnot_SetIcon(ByRef annot,icon) {
   HPDF_ANNOT_ICON_COMMENT := 0
   HPDF_ANNOT_ICON_KEY := 1
   HPDF_ANNOT_ICON_NOTE := 2
   HPDF_ANNOT_ICON_HELP := 3
   HPDF_ANNOT_ICON_NEW_PARAGRAPH := 4
   HPDF_ANNOT_ICON_PARAGRAPH := 5
   HPDF_ANNOT_ICON_INSERT := 6
   thisIcon := HPDF_ANNOT_ICON_%icon%
   Return, DllCall("libhpdf\HPDF_TextAnnot_SetIcon", "UPtr", annot, "Ptr", thisIcon)
}

HPDF_TextAnnot_SetOpened(ByRef annot,open) {
   Return, DllCall("libhpdf\HPDF_TextAnnot_SetOpened", "UPtr", annot, "Ptr", open)
}

HPDF_Annotation_SetBorderStyle(ByRef annot,subtype,width,dash_on,dash_off,dash_phase) {
   HPDF_BS_SOLID := 0
   HPDF_BS_DASHED := 1
   HPDF_BS_BEVELED := 2
   HPDF_BS_INSET := 3
   HPDF_BS_UNDERLINED := 4
   thisSubtype := HPDF_BS_%subtype%
   Return, DllCall("libhpdf\HPDF_Annotation_SetBorderStyle", "UPtr", annot, "Ptr", thisSubtype, "Float", width, "UPtr", dash_on, "UPtr", dash_off, "UPtr", dash_phase)
}

;----------------------------------------------------
;---- Structures ------------------------------------
;----------------------------------------------------
HPDF_CreateRect(ByRef rect,left,bottom,right,top) {
   VarSetCapacity(rect, 16, 0)
   Numput(left,rect,0,"Float")
   Numput(bottom,rect,4,"Float")
   Numput(right,rect,8,"Float")
   Numput(top,rect,12,"Float")
}
HPDF_ReadRect(ByRef rect,Byref left,Byref bottom,Byref right,Byref top) {
   left := NumGet(rect,0,"Float")
   bottom := NumGet(rect,4,"Float")
   right := NumGet(rect,8,"Float")
   top := NumGet(rect,12,"Float")
}
HPDF_GetPoint(ByRef point, ByRef x, ByRef y) {
   x := NumGet(&NumGet(point,0,"UPtr")+0,0,"Float")
   y := NumGet(point,4,"UFloat")
}

;----------------------------------------------------
;---- Helpers ---------------------------------------
;----------------------------------------------------
print_grid(ByRef pdf, ByRef page,inc=5,stepsize=2,bigstep=2) {
    height := HPDF_Page_GetHeight(page)
    width := HPDF_Page_GetWidth(page)
    font := HPDF_GetFont(pdf, "Helvetica", 0)
    HPDF_Page_SetFontAndSize(page, font, 5)
    HPDF_Page_SetGrayFill(page, 0.5)
    HPDF_Page_SetGrayStroke(page, 0.8)
    ;Draw horizontal lines
    y := 0
    while (y < height)
    {
        if(mod(y,inc*stepsize) == 0)
            HPDF_Page_SetLineWidth(page, 0.5)
        else
        {
            if (HPDF_Page_GetLineWidth(page) != 0.25)
                HPDF_Page_SetLineWidth(page, 0.25)
        }
        HPDF_Page_MoveTo(page, 0, y)
        HPDF_Page_LineTo(page, width, y)
        HPDF_Page_Stroke(page)
        if (mod(y,inc*stepsize*bigstep) == 0 && y > 0)
        {
            HPDF_Page_SetGrayStroke(page, 0.5)
            HPDF_Page_MoveTo(page, 0, y)
            HPDF_Page_LineTo(page, 5, y)
            HPDF_Page_Stroke(page)
            HPDF_Page_MoveTo(page, width, y)
            HPDF_Page_LineTo(page, width-5, y)
            HPDF_Page_Stroke(page)
            HPDF_Page_SetGrayStroke(page, 0.8)
        }
        y += inc
    }
    ;Draw vertical lines
    x := 0
    while (x < width)
    {
        if (mod(x,inc*stepsize) == 0)
            HPDF_Page_SetLineWidth(page, 0.5)
        else
        {
            if(HPDF_Page_GetLineWidth(page) != 0.25)
                HPDF_Page_SetLineWidth(page, 0.25)
        }
        HPDF_Page_MoveTo(page, x, 0)
        HPDF_Page_LineTo(page, x, height)
        HPDF_Page_Stroke(page)
        if(mod(x,inc*stepsize*bigstep) == 0 && x > 0)
        {
            HPDF_Page_SetGrayStroke(page, 0.5)
            HPDF_Page_MoveTo(page, x, 0)
            HPDF_Page_LineTo(page, x, 5)
            HPDF_Page_Stroke(page)
            HPDF_Page_MoveTo(page, x, height)
            HPDF_Page_LineTo(page, x, height - 5)
            HPDF_Page_Stroke(page)
            HPDF_Page_SetGrayStroke(page, 0.8)
        }
        x += inc
    }
    ;Draw horizontal text
    y := 0
    while (y < height)
    {
        if (mod(y,inc*stepsize*bigstep) == 0 && y > 0)
        {
            HPDF_Page_BeginText(page)
            HPDF_Page_MoveTextPos(page, 5, y - 2)
            HPDF_Page_ShowText(page, y)
            HPDF_Page_EndText(page)

            HPDF_Page_BeginText(page)
            HPDF_Page_MoveTextPos(page, width - 15, y - 2)
            HPDF_Page_ShowText(page, y)
            HPDF_Page_EndText(page)
        }

        y += inc
    }
    ;Draw vertical text
    x := 0
    while (x < width)
    {
        if (mod(x,inc*stepsize*bigstep) == 0 && x > 0)
        {
            HPDF_Page_BeginText(page)
            HPDF_Page_MoveTextPos(page, x, 5)
            HPDF_Page_ShowText(page, x)
            HPDF_Page_EndText(page)

            HPDF_Page_BeginText(page)
            HPDF_Page_MoveTextPos(page, x, height - 10)
            HPDF_Page_ShowText(page, x)
            HPDF_Page_EndText(page)
        }

        x += inc
    }
    HPDF_Page_SetGrayFill(page, 0)
    HPDF_Page_SetGrayStroke(page, 0)
}


;----------------------------------------------------
;--- Unused ? ---------------------------------------
;----------------------------------------------------
HPDF_SaveToStream(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_SaveToStream", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_GetStreamSize(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_GetStreamSize", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_ReadFromStream(ByRef hDoc, ByRef buffer, ByRef buffer_size) {
   Return, DllCall("libhpdf\HPDF_ReadFromStream", "UPtr", hDoc, "UPtr", buffer, "UPtr", buffer_size,  "Cdecl ptr")
}
HPDF_ResetStream(ByRef hDoc) {
   Return, DllCall("libhpdf\HPDF_ResetStream", "UPtr", hDoc, "Cdecl ptr")
}
HPDF_HasDoc(ByRef hDoc)
HPDF_SetErrorHandler(ByRef hDoc, user_error_fn)
HPDF_GetError(ByRef hDoc)
HPDF_ResetError(ByRef hDoc)
Attachments
libhpdf221.zip
(1.31 MiB) Downloaded 70 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

22 Dec 2018, 14:39

You're welcome... it was the last library keeping me on the ansi version for a few projects

Still to do: compile latest version of the dll, v2.3.0, with no dependencies on msvcrt0 or libpng dlls, then get it working with MemoryLibrary
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

02 Jan 2019, 13:33

Here are some example scripts using the library, if anyone has the original examples from the old forum please let me know

Raw text to multiple pages:

Code: Select all

Text2Pdf(A_ScriptFullPath)
Return


Text2Pdf(filename,target="")
{
   SplitPath, fileName, fileNameNoPath, targetDir,,noExt
   Fileread, text, %filename%

   remaining := textLength := StrLen(text)

   if targetDir =
      targetDir = .

   if target =
      target := targetDir "\" noExt ".pdf"

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

   ;create new document in memory
   hDoc := HPDF_New("error","000")

   ;Load a Standard-font
   encoding := "WinAnsiEncoding"
   fontName := HPDF_LoadTTFontFromFile(hDoc, A_WinDir "\Fonts\arial.ttf", 0)
   font := HPDF_GetFont2(hDoc, fontName, encoding)
   MAX_TEXT_POST := 25000

   ;if there are characters left to print, write them to a new page
   while remaining > 0
   {
      ;Creating a page, A4, Landscape
      ;+get dimensions for further usage
      page := HPDF_AddPage(hDoc)
      HPDF_Page_SetSize(page, "A4", "PORTRAIT")
      height := HPDF_Page_GetHeight(page)
      width := HPDF_Page_GetWidth(page)

      ;Writing the header
      HPDF_Page_BeginText(page)
      HPDF_Page_SetFontAndSize(page, font, 11)
      header := fileNameNoPath " (Page " A_Index ")"
      tw := HPDF_Page_TextWidth(page, header)
      HPDF_Page_MoveTextPos(page, (width-tw)/2, height-20)

      HPDF_Page_ShowText(page, header)
      HPDF_Page_EndText(page)


      ;Write the text to the page
      HPDF_Page_BeginText(page)
      HPDF_Page_SetFontAndSize(page, font, 11)

      ;text-dimensions on the page
      rect_left := 20
      rect_top := height-40
      rect_right := width-40
      rect_bottom := 20

      HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, SubStr(text,textLength-remaining+1,MAX_TEXT_POST), "LEFT", charsWritten)
      remaining := remaining - charsWritten

      HPDF_Page_EndText(page)
   }

   ;saving to file
   HPDF_SaveToFile(hDoc, target)

   ;unload dll
   HPDF_UnloadDLL(hDll)
}
Text formatting example 1:

Code: Select all

page_title := "Text Demo"
samp_text := "abcdefgABCDEFG123!#$%&[email protected]?"
samp_text2 := "The quick brown fox jumps over the lazy dog."


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

;create new document in memory
hDoc := HPDF_New("error","000")

;set compression mode
HPDF_SetCompressionMode(hDoc, "COMP_ALL")

;create default-font
font := HPDF_GetFont(hDoc, "Helvetica", 0)


   ;Creating a page, A4, Portrait
   page := HPDF_AddPage(hDoc)
   HPDF_Page_SetSize(page, "A4", "PORTRAIT")

   ;draw a grid (see libhpdf_helpers.ahk)
   print_grid(hDoc, page)

   ;print the title of the page (with positioning center).
   HPDF_Page_SetFontAndSize(page, font, 24)
   tw := HPDF_Page_TextWidth(page, page_title)
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page,(HPDF_Page_GetWidth(page) - tw) / 2, HPDF_Page_GetHeight(page) - 50, page_title)
   HPDF_Page_EndText(page)

   HPDF_Page_BeginText(page)
   HPDF_Page_MoveTextPos(page, 60, HPDF_Page_GetHeight(page) - 60)


   ;font size
   fsize = 8
   while fsize < 60
   {
      ;set style and size of font.
      HPDF_Page_SetFontAndSize(page, font, fsize)

      ;set the position of the text.
      HPDF_Page_MoveTextPos(page, 0, -5 - fsize)

      ;measure the number of characters which included in the page.
      buf := samp_text
      len := HPDF_Page_MeasureText(page, samp_text, HPDF_Page_GetWidth(page) - 120, 0, 0)

      ;truncate the text.
      buf := SubStr(buf,1,len)
      HPDF_Page_ShowText(page, buf)

      ; print the description.
      HPDF_Page_MoveTextPos(page, 0, -10)
      HPDF_Page_SetFontAndSize(page, font, 8)

      buf := "Fontsize=" Round(fsize,1)

      HPDF_Page_ShowText(page, buf)

      fsize *= 1.5
   }

   ;font color
   HPDF_Page_SetFontAndSize(page, font, 8)
   HPDF_Page_MoveTextPos(page, 0, -30)
   HPDF_Page_ShowText(page, "Font color")

   HPDF_Page_SetFontAndSize(page, font, 18)
   HPDF_Page_MoveTextPos(page, 0, -20)

   len := strlen(samp_text)

   loop, %len%
   {
      i := A_Index

      r := i / len
      g := 1 - i / len

      buf := SubStr(samp_text,i,1)

      HPDF_Page_SetRGBFill(page, r, g, 0.0)
      HPDF_Page_ShowText(page, buf)
   }

   HPDF_Page_MoveTextPos(page, 0, -25)

   loop, %len%
   {
      i := A_Index

      r := i / len
      b := 1 - i / len

      buf := SubStr(samp_text,i,1)

      HPDF_Page_SetRGBFill(page, r, 0.0, b)
      HPDF_Page_ShowText(page, buf)
   }

   HPDF_Page_MoveTextPos(page, 0, -25)


   loop, %len%
   {
      i := A_Index

      b := i / len
      g := 1 - i / len

      buf := SubStr(samp_text,i,1)

      HPDF_Page_SetRGBFill(page, 0.0, g, b)
      HPDF_Page_ShowText(page, buf)
   }

   HPDF_Page_EndText(page)

   ypos := 450


   ;-----------------------------------------------
   ;Font rendering mode
   ;-----------------------------------------------
   HPDF_Page_SetFontAndSize(page, font, 32)
   HPDF_Page_SetRGBFill(page, 1, 1, 0.0)
   HPDF_Page_SetLineWidth(page, 1.5)

   ;PDF_FILL
   show_description(page, 60, ypos, "RenderingMode=PDF_FILL")
   HPDF_Page_SetTextRenderingMode(page, "FILL")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos, "ABCabc123")
   HPDF_Page_EndText(page)

   ;PDF_STROKE
   show_description(page, 60, ypos - 50, "RenderingMode=PDF_STROKE")
   HPDF_Page_SetTextRenderingMode(page, "STROKE")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos - 50, "ABCabc123")
   HPDF_Page_EndText(page)

   ;PDF_FILL_THEN_STROKE
   show_description(page, 60, ypos - 100, "RenderingMode=PDF_FILL_THEN_STROKE")
   HPDF_Page_SetTextRenderingMode(page, "FILL_THEN_STROKE")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos - 100, "ABCabc123")
   HPDF_Page_EndText(page)

   ;PDF_FILL_CLIPPING
   show_description(page, 60, ypos - 150, "RenderingMode=PDF_FILL_CLIPPING")
   HPDF_Page_GSave(page)
   HPDF_Page_SetTextRenderingMode(page, "FILL_CLIPPING")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos - 150, "ABCabc123")
   HPDF_Page_EndText(page)
   show_stripe_pattern(page, 60, ypos - 150)
   HPDF_Page_GRestore(page)

   ;PDF_STROKE_CLIPPING
   show_description(page, 60, ypos - 200, "RenderingMode=PDF_STROKE_CLIPPING")
   HPDF_Page_GSave(page)
   HPDF_Page_SetTextRenderingMode(page, "STROKE_CLIPPING")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos - 200, "ABCabc123")
   HPDF_Page_EndText(page)
   show_stripe_pattern(page, 60, ypos - 200)
   HPDF_Page_GRestore(page)

   ;PDF_FILL_STROKE_CLIPPING
   show_description(page, 60, ypos - 250, "RenderingMode=PDF_FILL_STROKE_CLIPPING")
   HPDF_Page_GSave(page)
   HPDF_Page_SetTextRenderingMode(page, "FILL_STROKE_CLIPPING")
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, ypos - 250, "ABCabc123")
   HPDF_Page_EndText(page)
   show_stripe_pattern(page, 60, ypos - 250)
   HPDF_Page_GRestore(page)

   ;Reset text attributes
   HPDF_Page_SetTextRenderingMode(page, "FILL")
   HPDF_Page_SetRGBFill(page, 0, 0, 0)
   HPDF_Page_SetFontAndSize(page, font, 30)

   ;Rotating text
   angle1 := 30                   ; A rotation of 30 degrees.
   rad1 := angle1 / 180 * 3.141592 ; Calcurate the radian value.

   show_description(page, 320, ypos - 60, "Rotating text")
   HPDF_Page_BeginText(page)
   HPDF_Page_SetTextMatrix(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 330, ypos - 60)
   HPDF_Page_ShowText(page, "ABCabc123")
   HPDF_Page_EndText(page)

   ;Skewing text.
   show_description(page, 320, ypos - 120, "Skewing text")
   HPDF_Page_BeginText(page)

   angle1 := 10
   angle2 := 20
   rad1 := angle1 / 180 * 3.141592
   rad2 := angle2 / 180 * 3.141592

   HPDF_Page_SetTextMatrix(page, 1, tan(rad1), tan(rad2), 1, 320, ypos - 120)
   HPDF_Page_ShowText(page, "ABCabc123")
   HPDF_Page_EndText(page)


   ;scaling text(X direction)
   show_description(page, 320, ypos - 175, "Scaling text(X direction)")
   HPDF_Page_BeginText(page)
   HPDF_Page_SetTextMatrix(page, 1.5, 0, 0, 1, 320, ypos - 175)
   HPDF_Page_ShowText(page, "ABCabc12")
   HPDF_Page_EndText(page)


   ;scaling text(Y direction)
   show_description(page, 320, ypos - 250, "Scaling text(Y direction)")
   HPDF_Page_BeginText(page)
   HPDF_Page_SetTextMatrix(page, 1, 0, 0, 2, 320, ypos - 250)
   HPDF_Page_ShowText(page, "ABCabc123")
   HPDF_Page_EndText(page)


   ;char spacing, word spacing
   show_description(page, 60, 140, "char-spacing 0")
   show_description(page, 60, 100, "char-spacing 1.5")
   show_description(page, 60, 60, "char-spacing 1.5, word-spacing 2.5")

   HPDF_Page_SetFontAndSize(page, font, 20)
   HPDF_Page_SetRGBFill(page, 0.1, 0.3, 0.1)

   ; char-spacing 0
   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, 140, samp_text2)
   HPDF_Page_EndText(page)

   ; char-spacing 1.5
   HPDF_Page_SetCharSpace(page, 1.5)

   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, 100, samp_text2)
   HPDF_Page_EndText(page)

   ; char-spacing 1.5, word-spacing 3.5
   HPDF_Page_SetWordSpace(page, 2.5)

   HPDF_Page_BeginText(page)
   HPDF_Page_TextOut(page, 60, 60, samp_text2)
   HPDF_Page_EndText(page)

;saving to file
SplitPath, A_ScriptFullPath, , , , noExt
HPDF_SaveToFile(hDoc, noExt ".pdf")

;unload dll
HPDF_UnloadDLL(hDll)

ExitApp





show_stripe_pattern(ByRef page, x, y)
{
    iy := 0

    while iy < 50
    {
        HPDF_Page_SetRGBStroke(page, 0.0, 0.0, 0.5)
        HPDF_Page_SetLineWidth(page, 1)
        HPDF_Page_MoveTo(page, x, y + iy)
        HPDF_Page_LineTo(page, x + HPDF_Page_TextWidth(page, "ABCabc123"),  y + iy)
        HPDF_Page_Stroke(page)
        iy += 3
    }

    HPDF_Page_SetLineWidth(page, 2.5)
}



show_description(ByRef page, x, y, text)
{
   fsize := HPDF_Page_GetCurrentFontSize(page)
   font := HPDF_Page_GetCurrentFont(page)


   /*
   RGB := HPDF_Page_GetRGBFill(page)

   r := NumGet(RGB,0,"Float")
   g := NumGet(RGB,4,"Float")
   b := NumGet(RGB,8,"Float")
   ;msgbox % r " - " g " - " b
   */

   r := 0.43
   g := 0.44
   b := 0.0

   HPDF_Page_BeginText(page)
   HPDF_Page_SetRGBFill(page, 0, 0, 0)
   HPDF_Page_SetTextRenderingMode(page, "FILL")
   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, x, y - 12, text)
   HPDF_Page_EndText(page)

   HPDF_Page_SetFontAndSize(page, font, fsize)
   HPDF_Page_SetRGBFill(page, r, g, b)


}
Text formatting example 2:

Code: Select all

page_title := "Text Demo 2"
samp_text := "The quick brown fox jumps over the lazy dog."


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

;create new document in memory
hDoc := HPDF_New("error","000")

;set compression mode
HPDF_SetCompressionMode(hDoc, "COMP_ALL")


   ;Creating a page, A4, Portrait
   page := HPDF_AddPage(hDoc)
   HPDF_Page_SetSize(page, "A5", "PORTRAIT")

   ;draw a grid (see libhpdf_helpers.ahk)
   print_grid(hDoc, page)

   page_height = HPDF_Page_GetHeight (page);

   ;create default-font
   font := HPDF_GetFont(hDoc, "Helvetica", 0)
   HPDF_Page_SetTextLeading(page, 20)

   ;text_rect method

   ;HPDF_TALIGN_LEFT
   rect_left := 25
   rect_top := 545
   rect_right := 200
   rect_bottom := rect_top - 40

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "LEFT")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "LEFT", void)

   HPDF_Page_EndText(page)

   ; HPDF_TALIGN_RIGTH
   rect_left := 220
   rect_right := 395

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "RIGTH")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "RIGHT", NULL)

   HPDF_Page_EndText(page)

   ; HPDF_TALIGN_CENTER
   rect_left := 25
   rect_top := 475
   rect_right := 200
   rect_bottom := rect_top - 40

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "CENTER")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "CENTER", NULL)

   HPDF_Page_EndText(page)

   ; HPDF_TALIGN_JUSTIFY
   rect_left := 220
   rect_right := 395

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "JUSTIFY")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "JUSTIFY", NULL)

   HPDF_Page_EndText(page)

   ; Skewed coordinate system
   HPDF_Page_GSave(page)

   angle1 := 5
   angle2 := 10
   rad1 := angle1 / 180 * 3.141592
   rad2 := angle2 / 180 * 3.141592

   HPDF_Page_Concat(page, 1, tan(rad1), tan(rad2), 1, 25, 350)
   rect_left := 0
   rect_top := 40
   rect_right := 175
   rect_bottom := 0

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "Skewed coordinate system")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "LEFT", NULL)

   HPDF_Page_EndText(page)

   HPDF_Page_GRestore(page)


   ; Rotated coordinate system
   HPDF_Page_GSave(page)

   angle1 := 5
   rad1 := angle1 / 180 * 3.141592

   HPDF_Page_Concat(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 220, 350)
   rect_left := 0
   rect_top := 40
   rect_right := 175
   rect_bottom := 0

   HPDF_Page_Rectangle(page, rect_left, rect_bottom, rect_right - rect_left, rect_top - rect_bottom)
   HPDF_Page_Stroke(page)

   HPDF_Page_BeginText(page)

   HPDF_Page_SetFontAndSize(page, font, 10)
   HPDF_Page_TextOut(page, rect_left, rect_top + 3, "Rotated coordinate system")

   HPDF_Page_SetFontAndSize(page, font, 13)
   HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, samp_text, "LEFT", NULL)

   HPDF_Page_EndText(page)

   HPDF_Page_GRestore(page)

   ; text along a circle
   samp_text := "The quick brown fox jumps over the lazy dog. "
   HPDF_Page_SetGrayStroke(page, 0)
   HPDF_Page_Circle(page, 210, 190, 145)
   HPDF_Page_Circle(page, 210, 190, 113)
   HPDF_Page_Stroke(page)

   angle1 := 360 /(strlen(samp_text))
   angle2 := 180

   HPDF_Page_BeginText(page)
   font := HPDF_GetFont(hDoc, "Courier-Bold", 0)
   HPDF_Page_SetFontAndSize(page, font, 30)

   loop, % StrLen(samp_text)
   {
      i := A_Index

      rad1 := (angle2 - 90) / 180 * 3.141592
      rad2 := angle2 / 180 * 3.141592

      x := 210 + cos(rad2) * 122
      y := 190 + sin(rad2) * 122

      HPDF_Page_SetTextMatrix(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y)

      HPDF_Page_ShowText(page, SubStr(samp_text,i,1))
      angle2 -= angle1
   }

   HPDF_Page_EndText(page)


;saving to file
SplitPath, A_ScriptFullPath, , , , noExt
HPDF_SaveToFile(hDoc,  noExt ".pdf")

;unload dll
HPDF_UnloadDLL(hDll)

ExitApp
Invoice example, needs attached .png logo:

Code: Select all

#NoEnv
SetWorkingDir, %A_ScriptDir%
Compile()

 LogoSize := Resource_Read(LogoData,"ahk.png")

 hDll := HPDF_LoadDLL("libhpdf.dll")
 hDoc := HPDF_New("error","000")
 page := HPDF_AddPage(hDoc)
         HPDF_SetCompressionMode(hDoc, "ALL")
 font := HPDF_GetFont(hDoc, "Helvetica", 0)
         HPDF_Page_SetSize(page, "Letter", "PORTRAIT")
 ph   := HPDF_Page_GetHeight(page)
 pw   := HPDF_Page_GetWidth(page)
 dst  := HPDF_Page_CreateDestination(page)
         HPDF_Destination_SetXYZ(dst, 0, ph, 1)
         HPDF_SetOpenAction(hDoc, dst)

 hImg := HPDF_LoadPngImageFromMem(hDoc, &LogoData, LogoSize)
         HPDF_Page_DrawImage(page, hImg, 10, ph - 146, 10 + 232, 10 + 136)

         HPDF_Page_Rectangle(page, 20,  20,  572, 600)
         HPDF_Page_Rectangle(page, 20,  620, 572, 30)
         HPDF_Page_Rectangle(page, 472, 680, 120, 60)
         HPDF_Page_Rectangle(page, 472, 740, 120, 30)
         HPDF_Page_Stroke(page)

         HPDF_Page_SetFontAndSize(page, font, 10)
         HPDF_Page_BeginText(page)
 tw   := HPDF_Page_TextWidth(page, page_title)
         HPDF_Page_MoveTextPos(page, (pw-tw)/2, 40)
         HPDF_Page_ShowText(page, page_footer)
         HPDF_Page_EndText(page)
         HPDF_Page_SetFontAndSize(page, font, 24)
 tw   := HPDF_Page_TextWidth(page, PDF_Title)
         HPDF_Page_BeginText(page)
         HPDF_Page_TextOut(page,(pw - tw) / 2, ph - 50, PDF_Title)
         HPDF_Page_TextOut(page,490, ph - 80, A_DD * 322)
         HPDF_Page_SetFontAndSize(page, font, 12)
         HPDF_Page_TextOut(page,60, ph - 160, "Part")
         HPDF_Page_TextOut(page,300, ph - 160, "Material")
         HPDF_Page_TextOut(page,400, ph - 160, "Finish")
         HPDF_Page_TextOut(page,525, ph - 160, "Qty")
 Loop, 16 {
         HPDF_Page_TextOut(page,60,  ph - 200 - (A_Index*20), "Part " A_Index)
         HPDF_Page_TextOut(page,300, ph - 200 - (A_Index*20), "Aluminum")
         HPDF_Page_TextOut(page,400, ph - 200 - (A_Index*20), "Clear Chromate")
         HPDF_Page_TextOut(page,525, ph - 200 - (A_Index*20), A_Index*3)
 }
         HPDF_Page_TextOut(page,480, ph - 40, "Packing Slip")
         HPDF_Page_TextOut(page,325,ph - 50, "Company Name")
         HPDF_Page_TextOut(page,325,ph - 65, "9876 Commercial Way")
         HPDF_Page_TextOut(page,325,ph - 80, "Petaluma, Calif. 94954")
         HPDF_Page_TextOut(page,325,ph - 95, "415.555.5555")
         HPDF_Page_TextOut(page,440,ph - 130, "Shipped: " A_MM "/" A_DD "/" A_Year)
         HPDF_Page_TextOut(page,340,ph - 130, "PO: " 1234)
         HPDF_Page_SetFontAndSize(page, font, 20)
         HPDF_Page_TextOut(page,90,ph - 750, "Thank you for your business!")
         HPDF_Page_EndText(page)

         HPDF_SaveToFile(hDoc, A_Now ".pdf")
         HPDF_UnloadDLL(hDll)
Return
Attachments
ahk.png
ahk.png (15.33 KiB) Viewed 1799 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
burque505
Posts: 1020
Joined: 22 Jan 2017, 19:37

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

03 Jan 2019, 10:15

@gwarble, thanks, that's very nice!
The main script isn't in the zip archive, so I copied it, named it "hpdf.ahk" and put it in the libhpdf221 folder.
For my 64-bit Win7 setup with 64-bit AHK_L 1.1.30.01, I moved the 64-bit dlls out of their folder into the main script dir, added "#Include hpdf.ahk" at the top of each of your examples, and I was good to go.
Attached is the text demo pdf created, very nice once again.
EDIT: I just tried to run the invoice example - the function

Code: Select all

Compile()
seems to be missing. Is that a new function that wasn't in the OP? Also missing is the function called in the code below:

Code: Select all

LogoSize := Resource_Read(LogoData,"ahk.png")
Regards,
burque505
libharu-test.GIF
libharu-test.GIF (71.18 KiB) Viewed 1771 times
Attachments
libharu-2s.pdf
(5.38 KiB) Downloaded 25 times
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

03 Jan 2019, 17:26

Thanks

Oops, you can take out the call to Compile(), comment out the Resource_Read() call and uncomment the FileRead call... Inwas playing around with PngFromMemory

I'll update the post tonight
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
burque505
Posts: 1020
Joined: 22 Jan 2017, 19:37

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

03 Jan 2019, 18:43

Thanks, gwarble. This code worked for me.
Spoiler
libharu-invoice.GIF
libharu-invoice.GIF (23.29 KiB) Viewed 1735 times
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

03 Jan 2019, 18:50

Nice... As you see its nothing fancy, but a good practical use-case

Another way would be leave it as LoadPNGFromMem... and put a FileRead, *c, Logo.png before it, that way you don't have to read the png from disk every time
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
burque505
Posts: 1020
Joined: 22 Jan 2017, 19:37

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

03 Jan 2019, 19:11

Cool. This code worked too.
Spoiler

Code: Select all

         
         FileGetSize, LogoSize, ahk.png
         FileRead, LogoData, *c ahk.png
         hImg := HPDF_LoadPngImageFromMem(hDoc, &LogoData, LogoSize)
is what I changed.
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

03 Jan 2019, 19:45

Yup exactly, and if you go back to the originally posted way, you can FileInstall the png, then load it from resource when compiled :)
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Albireo
Posts: 839
Joined: 16 Oct 2013, 13:53

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

08 Jan 2019, 11:00

Excuse me!
But how is this version of Libharu installed?
Where should the * .dll files be placed, etc.?

Something I missed?
This version doesn't want to work for me!
(I have a previous version of LibHaru installed on this computer)
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

08 Jan 2019, 11:42

The examples assume its in A_ScriptDir, but you can put it anywhere if you tell the library where to load it from

As far as i know, the libpng15.dll has to be in the same dir, or LoadLibrary'd seperately

Also your old version might work as is with the new library, i tested with 2.2 and 2.1
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Albireo
Posts: 839
Joined: 16 Oct 2013, 13:53

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

08 Jan 2019, 12:37

Tank you!
But….

A new directory TestLibh was created.
then I copied .:
- libhpdf.dll
- libpng64-15.dll
to directory TestLibh
Copied this example below and created an AHK-file.

Code: Select all

Text2Pdf(A_ScriptFullPath)
Return


Text2Pdf(filename,target="")
{
   SplitPath, fileName, fileNameNoPath, targetDir,,noExt
   Fileread, text, %filename%

   remaining := textLength := StrLen(text)

   if targetDir =
      targetDir = .

   if target =
      target := targetDir "\" noExt ".pdf"

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

   ;create new document in memory
   hDoc := HPDF_New("error","000")

   ;Load a Standard-font
   encoding := "WinAnsiEncoding"
   fontName := HPDF_LoadTTFontFromFile(hDoc, A_WinDir "\Fonts\arial.ttf", 0)
   font := HPDF_GetFont2(hDoc, fontName, encoding)
   MAX_TEXT_POST := 25000

   ;if there are characters left to print, write them to a new page
   while remaining > 0
   {
      ;Creating a page, A4, Landscape
      ;+get dimensions for further usage
      page := HPDF_AddPage(hDoc)
      HPDF_Page_SetSize(page, "A4", "PORTRAIT")
      height := HPDF_Page_GetHeight(page)
      width := HPDF_Page_GetWidth(page)

      ;Writing the header
      HPDF_Page_BeginText(page)
      HPDF_Page_SetFontAndSize(page, font, 11)
      header := fileNameNoPath " (Page " A_Index ")"
      tw := HPDF_Page_TextWidth(page, header)
      HPDF_Page_MoveTextPos(page, (width-tw)/2, height-20)

      HPDF_Page_ShowText(page, header)
      HPDF_Page_EndText(page)


      ;Write the text to the page
      HPDF_Page_BeginText(page)
      HPDF_Page_SetFontAndSize(page, font, 11)

      ;text-dimensions on the page
      rect_left := 20
      rect_top := height-40
      rect_right := width-40
      rect_bottom := 20

      HPDF_Page_TextRect(page, rect_left, rect_top, rect_right, rect_bottom, SubStr(text,textLength-remaining+1,MAX_TEXT_POST), "LEFT", charsWritten)
      remaining := remaining - charsWritten

      HPDF_Page_EndText(page)
   }

   ;saving to file
   HPDF_SaveToFile(hDoc, target)

   ;unload dll
   HPDF_UnloadDLL(hDll)
}
at last I run the AHK-program above with AHK-UNICODE 64-bit...
I got the Error.: Call to nonexistent function. at line 20 HPDF_LoadDLL(hpdfDllFile)
Albireo
Posts: 839
Joined: 16 Oct 2013, 13:53

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

08 Jan 2019, 17:31

When I copy the democode above ( with SELECT ALL) and paste it to Notepad++, I got an error when the file is saving to eg. Demo.ahk.
The error window says .: Exception vector<T> too long. (Never received this message Before)
When I save the script to the "Demo.txt" file - no problem.
I don't know what it means.
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

08 Jan 2019, 17:50

Function not found: Make sure you put HPDF.ahk in a stdlib folder or #include it



Exception vector...: doesn't sound like an AHK or LibHaru problem to me
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
burque505
Posts: 1020
Joined: 22 Jan 2017, 19:37

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

08 Jan 2019, 18:27

@Albireo, check my post above and see if that helps. I don't think you have an #Include hpdf.ahk in your script. That's why your function isn't seen. I don't believe the script is in the zip file, so I've attached it.
hpdf.ahk
(36.69 KiB) Downloaded 19 times
gwarble
Posts: 385
Joined: 30 Sep 2013, 15:01

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

08 Jan 2019, 18:34

Hehe, thanks for helping out, i guess i'll add the #includes to the examples, and add hpdf.ahk and the example scripts to the zip (the library is in the first post, fyi, and i (erroneously) figured everyone used standard libraries, i haven't used #include in forever

Also, if anyone can help me compile a v2.3 dll it would be greatly appreciated
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
Albireo
Posts: 839
Joined: 16 Oct 2013, 13:53

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

08 Jan 2019, 19:54

Thanks!
(I also think that all that is needed should be in the same zip file - and preferably an install instruction.)
Do not know why, but after I restarted the computer, the examples I tested began to work…

Now I want to use Libharu for my old ahk program.
I think I've tried all the options, but ...
Sometime I got blank pages. Another time I got nothing …

Any idea what might be wrong?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot], TAC109 and 56 guests