hot.eye
2012-01-06 13:40:19 UTC
Hi all,
I've been playing around and I can get a pdf created, but no text on
it.
My code is based on the HaruPDF.prg source from the Harbour sample.
I have put the dll file and Arial.ttf in the working directory. The
fact it
is making a pdf means that it is loading the dll and calling it.
I have tried changing the paper size to A5 and orientation those
changes are
reflected in the pdf as Acrobat shows the page size.
Any ideas why no text is appearing? Do I need to pass some parameters
by
reference, if so how is that done in the dll calls?
Am I on the right track? Has anybody got it to work? What did I miss?
Kind regards
Philip
dllPDF:=LoadLibrary('libhpdf.dll')
if dllPDF>0
pdf := PDF_New()
IF pdf == NIL
alert( " Pdf could not been created!" )
RETURN NIL
ENDIF
PDF_SetCompressionMode( pdf, HPDF_COMP_ALL )
PDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE)
page := HPDF_AddPage(pdf)
PDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT)
height := PDF_Page_GetHeight(page)
width := PDF_Page_GetWidth(page)
font_Arial:=PDF_LoadTTFontFromFile( pdf, 'Arial.ttf', HPDF_TRUE)
def_font := PDF_GetFont( pdf, font_Arial, 'StandardEncoding' )
PDF_Page_SetFontAndSize( page, def_font, 12 )
PDF_Page_SetRGBFill(page, 0, 0, 0)
PDF_Page_BeginText( page )
for i:=1 to 1000 step 100
HPDF_Page_TextOut( page, i, i, alltrim(str(i)) )
next
PDF_Page_EndText( page )
PDF_SaveToFile( pdf, cFileToSave )
PDF_Free( pdf )
endif
//----------------------------------------------------------------------//
// wrapper functions to call a DLL loaded above
function PDF_New
return DllCall(dllPDF, DC_CALL_CDECL, "HPDF_New")
function PDF_SetCompressionMode( pdf, xMode )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SetCompressionMode', pdf,
xMode )
function PDF_AddPage(pdf)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_AddPage', pdf)
function PDF_Page_GetHeight(page)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_GetHeight', page)
function PDF_Page_GetWidth(page)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_GetWidth', page)
function PDF_GetFont( pdf, cFont, cCodePage )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_GetFont', pdf, cFont,
cCodePage )
function PDF_Page_SetFontAndSize( page, def_font, nSize )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetFontAndSize',
page,
def_font, nSize )
function PDF_Page_TextWidth( page, page_title )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_TextWidth', page,
page_title )
function PDF_Page_SetSize (page, nPageSize, nOrientation)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetSize', page,
nPageSize,
nOrientation)
function PDF_Page_BeginText( page )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_BeginText', page )
function PDF_Page_TextOut( page, nWidth, nHeight, page_title )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_TextOut', page,
nWidth,
nHeight, page_title )
function PDF_Page_EndText( page )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_EndText', page )
function PDF_LoadTTFontFromFile( pdf, cFilename, lEmbed)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_LoadTTFontFromFile', pdf,
cFilename, lEmbed)
function PDF_Page_MoveTextPos( page, nX, nY )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_MoveTextPos', page,
nX,
nY )
function PDF_SaveToFile( pdf, cFileToSave )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SaveToFile', pdf,
cFileToSave )
function PDF_Free( pdf )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Free', pdf )
function PDF_Page_ShowText( page, cFont )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_ShowText', page,
cFont )
function PDF_SetPageMode(pdf, nPageMode)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SetPageMode', pdf,
nPageMode)
function PDF_Page_SetRGBFill(page, nR, nG, nB)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetRGBFill', page,
nR, nG,
nB)
//----------------------------------------------------------------------//
I've been playing around and I can get a pdf created, but no text on
it.
My code is based on the HaruPDF.prg source from the Harbour sample.
I have put the dll file and Arial.ttf in the working directory. The
fact it
is making a pdf means that it is loading the dll and calling it.
I have tried changing the paper size to A5 and orientation those
changes are
reflected in the pdf as Acrobat shows the page size.
Any ideas why no text is appearing? Do I need to pass some parameters
by
reference, if so how is that done in the dll calls?
Am I on the right track? Has anybody got it to work? What did I miss?
Kind regards
Philip
dllPDF:=LoadLibrary('libhpdf.dll')
if dllPDF>0
pdf := PDF_New()
IF pdf == NIL
alert( " Pdf could not been created!" )
RETURN NIL
ENDIF
PDF_SetCompressionMode( pdf, HPDF_COMP_ALL )
PDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE)
page := HPDF_AddPage(pdf)
PDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT)
height := PDF_Page_GetHeight(page)
width := PDF_Page_GetWidth(page)
font_Arial:=PDF_LoadTTFontFromFile( pdf, 'Arial.ttf', HPDF_TRUE)
def_font := PDF_GetFont( pdf, font_Arial, 'StandardEncoding' )
PDF_Page_SetFontAndSize( page, def_font, 12 )
PDF_Page_SetRGBFill(page, 0, 0, 0)
PDF_Page_BeginText( page )
for i:=1 to 1000 step 100
HPDF_Page_TextOut( page, i, i, alltrim(str(i)) )
next
PDF_Page_EndText( page )
PDF_SaveToFile( pdf, cFileToSave )
PDF_Free( pdf )
endif
//----------------------------------------------------------------------//
// wrapper functions to call a DLL loaded above
function PDF_New
return DllCall(dllPDF, DC_CALL_CDECL, "HPDF_New")
function PDF_SetCompressionMode( pdf, xMode )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SetCompressionMode', pdf,
xMode )
function PDF_AddPage(pdf)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_AddPage', pdf)
function PDF_Page_GetHeight(page)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_GetHeight', page)
function PDF_Page_GetWidth(page)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_GetWidth', page)
function PDF_GetFont( pdf, cFont, cCodePage )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_GetFont', pdf, cFont,
cCodePage )
function PDF_Page_SetFontAndSize( page, def_font, nSize )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetFontAndSize',
page,
def_font, nSize )
function PDF_Page_TextWidth( page, page_title )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_TextWidth', page,
page_title )
function PDF_Page_SetSize (page, nPageSize, nOrientation)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetSize', page,
nPageSize,
nOrientation)
function PDF_Page_BeginText( page )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_BeginText', page )
function PDF_Page_TextOut( page, nWidth, nHeight, page_title )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_TextOut', page,
nWidth,
nHeight, page_title )
function PDF_Page_EndText( page )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_EndText', page )
function PDF_LoadTTFontFromFile( pdf, cFilename, lEmbed)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_LoadTTFontFromFile', pdf,
cFilename, lEmbed)
function PDF_Page_MoveTextPos( page, nX, nY )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_MoveTextPos', page,
nX,
nY )
function PDF_SaveToFile( pdf, cFileToSave )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SaveToFile', pdf,
cFileToSave )
function PDF_Free( pdf )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Free', pdf )
function PDF_Page_ShowText( page, cFont )
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_ShowText', page,
cFont )
function PDF_SetPageMode(pdf, nPageMode)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_SetPageMode', pdf,
nPageMode)
function PDF_Page_SetRGBFill(page, nR, nG, nB)
return DllCall(dllPDF, DC_CALL_CDECL, 'HPDF_Page_SetRGBFill', page,
nR, nG,
nB)
//----------------------------------------------------------------------//