Skip to main content

[Migrated content. Thread originally posted on 06 January 2012]

Hello,

I have problems using a C library under RHEL5, serverexpress 5.
I installed the libharu library to be able to create pdf files. Very easy : from the libharu.org/.../Downloads I downloaded the last stable version, then configure, make, make install and the library is installed. I checked with C examples from the libharu site : a simple compile using
gcc font_demo.c -l hpdf
does the job and the program generates the pdf file.

I used h2cpy to generate properly the types according to libharu .h files. In fact, most of the functions work with pointers (maybe, that's my problem).
I created a small cobol sample program which is the translation of a C demo file font_demo.cbl.
No problem at compliation time using :
cob -x font_demo.cbl -l hpdf
It even runs without problem, except that the final results are completly wrong!! At the beginning of the program, it asks for the size of the page which should be (841, 595) and I find negative values... And the file is not generated...

I suspect that the problem resides in the pointer use. But I can't find the origin of the problem.
If there are any suggestions...

Best regards and thanks.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. 'fontdemo'.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       DATA DIVISION.
       FILE SECTION.
      $set sourceformat"free"
       working-storage section.
       *>copy "ctypes.cpy".
       copy "hpdf_types.cpy".
       1 HPDF-Doc          is typedef       usage pointer.
       1 HPDF-Font         is typedef       usage pointer.
       1 HPDF-Page         is typedef       usage pointer.

       1 page-title  pic x(50) value z"Font Demo".
       1 fname       pic x(256).
       1 def-font    usage HPDF-Font.
       1 tw          usage HPDF-REAL.
       1 myheight    usage HPDF-REAL.
       1 mywidth     usage HPDF-REAL.
       1 myheight1   usage HPDF-REAL.
       1 mywidth1    usage HPDF-REAL.
       1 i           usage HPDF-UINT.
       1 mypage      usage HPDF-Page.
       1 pdf         usage HPDF-Doc.
       1 pdfstatus   usage HPDF-STATUS.
       
       1 aa          pic 99999.9999.
       1 txt         pic x(256).
       
      $set sourceformat"free"
       procedure division.

         call "HPDF_New" using NULL, NULL returning pdf
         display "HPDF_New " pdf
         if (pdf = NULL) then
            display "error: cannot create PdfDoc object"
            exit program
         end-if
         *>HPDF_STATUS HPDF_GetError (HPDF_Doc pdf);
         call "HPDF_GetError" using by value pdf returning pdfstatus
         display "status " pdfstatus         

         *> Add a new page object. */
         *>page = HPDF_AddPage (pdf);
         call "HPDF_AddPage" using by value pdf returning mypage

         *> Should be height : 841.000000  width : 595.000000
         *>myheight = HPDF_Page_GetHeight (mypage);
         call "HPDF_Page_GetHeight" using by value mypage returning myheight
         *>mywidth = HPDF_Page_GetWidth (mypage);
         call "HPDF_Page_GetWidth" using by value mypage returning mywidth

         *> Print the lines of the page. */
         *>HPDF_Page_SetLineWidth (mypage, 1);
         call "HPDF_Page_SetLineWidth" using by value mypage, 1
         *>HPDF_Page_Rectangle (mypage, 50, 50, mywidth - 100, myheight - 110);
         compute mywidth1 = mywidth - 100
         compute myheight1 = myheight - 110
         call "HPDF_Page_Rectangle" using by value mypage, 50, 50, mywidth1, myheight1
         *>HPDF_Page_Stroke (mypage);
         call "HPDF_Page_Stroke" using mypage

         *> output subtitle. */
         *>HPDF_Page_BeginText (mypage);
         call "HPDF_Page_BeginText" using by value mypage
         *>HPDF_Page_SetFontAndSize (mypage, def_font, 16);
         *>HPDF_Page_TextOut (mypage, 60, myheight - 80, "");
         compute myheight1 = myheight - 80
         move z"" to txt
         call "HPDF_Page_TextOut" using by value mypage, 60, myheight1, by reference txt
         *>HPDF_Page_EndText (mypage);
         call "HPDF_Page_EndText" using by value mypage         

         *>HPDF_SaveToFile (pdf, fname);
         move z'cblfontdemo.pdf' to fname
         call "HPDF_SaveToFile" using by value pdf, by reference fname

         *> clean up */
         *>HPDF_Free (pdf);
         call "HPDF_Free" using by value pdf

         exit program
         stop run
         .