Page 1 of 1

Create PDF in Mod_Harbour.

Posted: Sun Mar 01, 2020 7:22 pm
by byron.hopp
Is there any samples of printing to pdf using harupdf lib. I tried the TPdf print class from my newest version of Harbour but this does not work. I then created the code below by using the functions used in the class:

function main()
local hPdf := HPDF_New()
local hPage := HPDF_AddPage( hPdf )
HPDF_Page_BeginText( hPage )
HPDF_Page_TextOut( hPage,10,10,"Hello PDF" )
HPDF_Page_EndText( hPage )
HPDF_SaveToFile ( hPdf, "Hello.pdf" )
return NIL

This runs without errors, but cannot find the hello.pdf anywhere on the server.
Thanks,
Byron

Re: Create PDF in Mod_Harbour.

Posted: Mon Mar 02, 2020 7:43 am
by Antonio Linares
Byron,

Please change this line this way:

? HPDF_SaveToFile ( hPdf, "Hello.pdf" )

and lets see what return code you get

Re: Create PDF in Mod_Harbour.

Posted: Mon Mar 02, 2020 8:31 am
by byron.hopp
The function returns 4133.

Re: Create PDF in Mod_Harbour.

Posted: Mon Mar 02, 2020 10:50 am
by Antonio Linares
Byron,

This way it works fine:

Code: Select all

function main()

   local hPdf := HPDF_New()
   local hPage := HPDF_AddPage( hPdf )

   HPDF_Page_SetFontAndSize( hPage, HPDF_GetFont( hPdf, "Helvetica" ), 24 )

   HPDF_Page_BeginText( hPage )
   HPDF_Page_TextOut( hPage, 10, 10, "Hello PDF" )
   HPDF_Page_EndText( hPage )
   ? hb_NumToHex( HPDF_SaveToFile( hPdf, "c:\temp\Hello.pdf" ) )

return nil
You can check the error codes here:
https://github.com/harbour/core/blob/ma ... hpdferro.h

Re: Create PDF in Mod_Harbour.

Posted: Mon Mar 02, 2020 5:24 pm
by byron.hopp
I pasted this code into my program and run. The ? hb_NumToHex( HPDF_SaveToFile( hPdf, "c:\temp\Hello.pdf" ) ) returns 0, there is a Temp directory on my c: drive but no file is created. I am using IIS version of Mod_Harbour.

Thanks,

Re: Create PDF in Mod_Harbour.

Posted: Mon Mar 02, 2020 6:11 pm
by luiscambuston
Byron,

Try replacing c:\temp with c:\inetpub\wwwroot or the folder that your application is running or a sub folder under that....