hbHPDF Library - Petewg/harbour-core GitHub Wiki

🔙 Home

The hbhpdf contrib library (a blessed work by Pritpal Bedi) is a Harbour wrapper library for the Haru Free PDF Library. It includes a great set of functions which are one-to-one bindings to (almost) all HaruPDF functions, using exactly the same name for convenience. See the quite complete official Haru Documentation wiki for detailed reference on syntax, parameters and returned values of these functions (also, take a look at the old documentation). Although a very basic C knowledge required (basically about C-datatypes and calling convention), the content is quite easily understandable and conceptually applicable to Harbour.
A probably important note (made by Maurizio la Cecilia in this post) regarding hbHPDF library usage: "... if hbhpdf is linked with hbwin and/or xhb it needs that hbhpdf is referenced before each of the latter in hbp/hbc file."

Reference list of the available functions in hbhpdf library.

  • HPDF_New() ➜ hPdf
    syntax: hPdf := HPDF_New()
    returns: handler to created PDF doc or errorcode on failure.

  • HPDF_AddPage(<hPdf>) ➜ hPage
    syntax: hPage := HPDF_AddPage( hPdf )

  • HPDF_NewDoc(<hPdf>) ➜ nResult
    creates a new document. If <hPdf> object already has a document, the current document is revoked.
    returns zero (0) on success, non-zero value on error.

  • HPDF_AddPageLabel() ➜ nResult

  • HPDF_Annotation_SetBorderStyle ➜ nResult

  • HPDF_Annot_Set3DView

  • HPDF_Annot_SetCMYKColor

  • HPDF_Annot_SetGrayColor

  • HPDF_Annot_SetNoColor

  • HPDF_Annot_SetRGBColor

  • HPDF_AttachFile

  • HPDF_CheckError

  • HPDF_CreateExtGState

  • HPDF_CreateOutline

  • HPDF_Destination_SetFit

  • HPDF_Destination_SetFitB

  • HPDF_Destination_SetFitBH

  • HPDF_Destination_SetFitBV

  • HPDF_Destination_SetFitH

  • HPDF_Destination_SetFitR

  • HPDF_Destination_SetFitV

  • HPDF_Destination_SetXYZ

  • HPDF_Encoder_GetByteType

  • HPDF_Encoder_GetType

  • HPDF_Encoder_GetUnicode

  • HPDF_Encoder_GetWritingMode

  • HPDF_ExtGState_SetAlphaFill

  • HPDF_ExtGState_SetAlphaStroke

  • HPDF_ExtGState_SetBlendMode

  • HPDF_Font_GetAscent

  • HPDF_Font_GetBBox

  • HPDF_Font_GetCapHeight

  • HPDF_Font_GetDescent

  • HPDF_Font_GetEncodingName

  • HPDF_Font_GetFontName

  • HPDF_Font_GetUnicodeWidth

  • HPDF_Font_GetXHeight

  • HPDF_Font_MeasureText

  • HPDF_Font_TextWidth

  • HPDF_Free(<hPdf>) ➜ NIL
    this function must be called always when the hPdf document object is no more needed, in order to free all resources that had been allocated for it.

  • HPDF_FreeDoc

  • HPDF_FreeDocAll

  • HPDF_FreeTextAnnot_Set2PointCalloutLine

  • HPDF_FreeTextAnnot_Set3PointCalloutLine

  • HPDF_FreeTextAnnot_SetDefaultStyle

  • HPDF_FreeTextAnnot_SetLineEndingStyle

  • HPDF_GetContents

  • HPDF_GetCurrentEncoder

  • HPDF_GetCurrentPage

  • HPDF_GetEncoder

  • HPDF_GetError

  • HPDF_GetErrorDetail

  • HPDF_GetFont

  • HPDF_GetInfoAttr

  • HPDF_GetPageLayout

  • HPDF_GetPageMode

  • HPDF_GetStreamSize

  • HPDF_HasDoc

  • HPDF_ICC_LoadIccFromMem

  • HPDF_Image_AddSMask

  • HPDF_Image_GetBitsPerComponent

  • HPDF_Image_GetColorSpace

  • HPDF_Image_GetHeight

  • HPDF_Image_GetSize

  • HPDF_Image_GetWidth

  • HPDF_Image_SetColorMask

  • HPDF_Image_SetMaskImage

  • HPDF_InsertPage

  • HPDF_LineAnnot_SetCaption

  • HPDF_LineAnnot_SetLeader

  • HPDF_LineAnnot_SetPosition

  • HPDF_LinkAnnot_SetBorderStyle

  • HPDF_LinkAnnot_SetHighlightMode

  • HPDF_LoadIccProfileFromFile

  • HPDF_LoadJpegImageFromFile

  • HPDF_LoadJpegImageFromMem

  • HPDF_LoadPngImageFromFile

  • HPDF_LoadPngImageFromFile2

  • HPDF_LoadPngImageFromMem

  • HPDF_LoadRawImageFromFile

  • HPDF_LoadRawImageFromMem

  • HPDF_LoadTTFontFromFile(<hPdf>, <cFontFileName>, <lEmbedded>) ➜ cFontName
    Loads a truetype font (.ttf) to be used in the created document.
    • <hPdf>, hanlde to pdf document
    • <cFontFileName>, complete (with path and extention) filename of font to be loaded.
    • <lEmbedded>, boolean flag specifying whether the subset loaded font will be embedded into pdf document or not.
      Important: to embed correctly non-latin fonts (Greek, Cyrilic etc.) use UTF-8 encoding, like this:
       HPDF_UseUTFEncodings( hPdf )
       HPDF_SetCurrentEncoder( hPdf, "UTF-8" )
       cFontName := HPDF_LoadTTFontFromFile( hPdf, "/fonts/arial.ttf", HPDF_TRUE)
       hFont := HPDF_GetFont ( hPdf, cFontName, "UTF-8"`)
       hPage := HPDF_AddPage( hPdf )
       HPDF_Page_SetFontAndSize ( hPage, hFont, 10) // (10=size)
      // Of course, the text to be stored in the PDF document, must also be "UTF-8" encoded! (use hb_Translate() if needed..)

  • HPDF_LoadTTFontFromFile2

  • HPDF_LoadType1FontFromFile

  • HPDF_MarkupAnnot_SetCloudEffect

  • HPDF_MarkupAnnot_SetCreationDate

  • HPDF_MarkupAnnot_SetIntent

  • HPDF_MarkupAnnot_SetInteriorCMYKColor

  • HPDF_MarkupAnnot_SetInteriorGrayColor

  • HPDF_MarkupAnnot_SetInteriorRGBColor

  • HPDF_MarkupAnnot_SetInteriorTransparent

  • HPDF_MarkupAnnot_SetPopup

  • HPDF_MarkupAnnot_SetRectDiff

  • HPDF_MarkupAnnot_SetSubject

  • HPDF_MarkupAnnot_SetTitle

  • HPDF_MarkupAnnot_SetTransparency

  • HPDF_Outline_SetDestination

  • HPDF_Outline_SetOpened

  • HPDF_Page_Arc

  • HPDF_Page_BeginText

  • HPDF_Page_Circle

  • HPDF_Page_Clip

  • HPDF_Page_ClosePath

  • HPDF_Page_ClosePathEofillStroke

  • HPDF_Page_ClosePathFillStroke

  • HPDF_Page_ClosePathStroke

  • HPDF_Page_Concat

  • HPDF_Page_Create3DView

  • HPDF_Page_CreateCircleAnnot

  • HPDF_Page_CreateDestination

  • HPDF_Page_CreateFreeTextAnnot

  • HPDF_Page_CreateHighlightAnnot

  • HPDF_Page_CreateLineAnnot

  • HPDF_Page_CreateLinkAnnot

  • HPDF_Page_CreatePopupAnnot

  • HPDF_Page_CreateSquareAnnot

  • HPDF_Page_CreateSquigglyAnnot

  • HPDF_Page_CreateStampAnnot

  • HPDF_Page_CreateStrikeOutAnnot

  • HPDF_Page_CreateTextAnnot

  • HPDF_Page_CreateUnderlineAnnot

  • HPDF_Page_CreateURILinkAnnot

  • HPDF_Page_CurveTo

  • HPDF_Page_CurveTo2

  • HPDF_Page_CurveTo3

  • HPDF_Page_DrawImage

  • HPDF_Page_Ellipse

  • HPDF_Page_EndPath

  • HPDF_Page_EndText

  • HPDF_Page_Eoclip

  • HPDF_Page_Eofill

  • HPDF_Page_EofillStroke

  • HPDF_Page_ExecuteXObject

  • HPDF_Page_Fill

  • HPDF_Page_FillStroke

  • HPDF_Page_GetCharSpace

  • HPDF_Page_GetCMYKFill

  • HPDF_Page_GetCMYKStroke

  • HPDF_Page_GetCurrentFont

  • HPDF_Page_GetCurrentFontSize

  • HPDF_Page_GetCurrentPos

  • HPDF_Page_GetCurrentTextPos

  • HPDF_Page_GetDash

  • HPDF_Page_GetFillingColorSpace

  • HPDF_Page_GetFlat

  • HPDF_Page_GetGMode

  • HPDF_Page_GetGrayFill

  • HPDF_Page_GetGrayStroke

  • HPDF_Page_GetGStateDepth

  • HPDF_Page_GetHeight

  • HPDF_Page_GetHorizontalScalling

  • HPDF_Page_GetLineCap

  • HPDF_Page_GetLineJoin

  • HPDF_Page_GetLineWidth

  • HPDF_Page_GetMiterLimit

  • HPDF_Page_GetRGBFill

  • HPDF_Page_GetRGBStroke

  • HPDF_Page_GetStrokingColorSpace

  • HPDF_Page_GetTextLeading

  • HPDF_Page_GetTextMatrix

  • HPDF_Page_GetTextRenderingMode

  • HPDF_Page_GetTextRise

  • HPDF_Page_GetTransMatrix

  • HPDF_Page_GetWidth

  • HPDF_Page_GetWordSpace

  • HPDF_Page_GRestore

  • HPDF_Page_GSave

  • HPDF_Page_LineTo

  • HPDF_Page_MeasureText

  • HPDF_Page_MoveTextPos

  • HPDF_Page_MoveTextPos2

  • HPDF_Page_MoveTo

  • HPDF_Page_MoveToNextLine

  • HPDF_Page_Rectangle

  • HPDF_Page_SetCharSpace

  • HPDF_Page_SetCMYKFill

  • HPDF_Page_SetCMYKStroke

  • HPDF_Page_SetDash

  • HPDF_Page_SetExtGState

  • HPDF_Page_SetFontAndSize

  • HPDF_Page_SetGrayFill

  • HPDF_Page_SetGrayStroke

  • HPDF_Page_SetHeight

  • HPDF_Page_SetHorizontalScalling

  • HPDF_Page_SetLineCap

  • HPDF_Page_SetLineJoin

  • HPDF_Page_SetLineWidth

  • HPDF_Page_SetMiterLimit

  • HPDF_Page_SetRGBFill

  • HPDF_Page_SetRGBStroke

  • HPDF_Page_SetRotate

  • HPDF_Page_SetSize

  • HPDF_Page_SetSlideShow

  • HPDF_Page_SetTextLeading

  • HPDF_Page_SetTextMatrix

  • HPDF_Page_SetTextRenderingMode

  • HPDF_Page_SetTextRise

  • HPDF_Page_SetWidth

  • HPDF_Page_SetWordSpace

  • HPDF_Page_SetZoom

  • HPDF_Page_ShowText

  • HPDF_Page_ShowTextNextLine

  • HPDF_Page_ShowTextNextLineEx

  • HPDF_Page_Stroke

  • HPDF_Page_TextOut

  • HPDF_Page_TextRect

  • HPDF_Page_TextWidth

  • HPDF_PDFA_SetPDFAConformance

  • HPDF_PopupAnnot_SetOpened

  • HPDF_ReadFromStream

  • HPDF_ResetError

  • HPDF_ResetStream

  • HPDF_SaveToFile(<hPdf>, <cFileName>) ➜ nResult
    saves the current document to a file.
    hPdf - The handle of a document object.
    cFileName - The name of file to save.
    Returns zero (0) on success, non-zero value on error.

  • HPDF_SaveToStream

  • HPDF_SetCompressionMode

  • HPDF_SetCurrentEncoder

  • HPDF_SetEncryptionMode

  • HPDF_SetErrorHandler

  • HPDF_SetInfoAttr

  • HPDF_SetInfoDateAttr

  • HPDF_SetOpenAction

  • HPDF_SetPageLayout

  • HPDF_SetPageMode

  • HPDF_SetPagesConfiguration

  • HPDF_SetPassword

  • HPDF_SetPermission

  • HPDF_TextAnnot_SetIcon

  • HPDF_TextAnnot_SetOpened

  • HPDF_TextMarkupAnnot_SetQuadPoints

  • HPDF_UseCNSEncodings

  • HPDF_UseCNSFonts

  • HPDF_UseCNTEncodings

  • HPDF_UseCNTFonts

  • HPDF_UseJPEncodings

  • HPDF_UseJPFonts

  • HPDF_UseKREncodings

  • HPDF_UseKRFonts

  • HPDF_UseUTFEncodings

  • HPDF_VERSION_TEXT

Harbour specific functions:

  • hb_HPDF_GetErrorString(<nErrorCode>) ➜ cErrorDefString
    returns the (barely informative) literal constant of <nErrorCode> as it's #define(d) into \harbour\contrib\hbhpdf\harupdf.ch header file. For a 'human-friendly' error description see List of error codes at official Haru PDF Library documentation wiki.

  • hb_HPDF_IsVersion(<nMajorVer>, <nMinorVer>, <nBugFixVer>) ➜ .T.|.F.
    returns .T. when the used Haru PDF Library version is equal to or greater than the given <nMajorVer>, <nMinorVer>, <nBugFixVer>, otherwise returns .F.

  • hb_HPDF_Version(<@nMajorVer>, <@nMinorVer>, <@nBugFixVer>) ➜ NIL
    retrieves version info of the used Haru PDF Library, into the corresponding variables that must be passed by reference.

Some randomly collected (possibly useful) notes and links about Haru PDF library

  • Note 1: All Haru units are printer's points (72 points/inch). Not pixels. PDF is independent of resolution. For example, 14400 units (points) is 200 inches, the maximum size of a PDF document.
  • Note 2: See how to simulate bold/italic font styles. (not personally tested, dunno whether it works or not..)
  • Haru-users group

Other useful PDF related tools

🔙 Home

⚠️ **GitHub.com Fallback** ⚠️