Skip to main content

Hello,

has anybody some experience with the C library pdflib (http://www.pdflib.com/), either version 9 or 7 (the previous free one) under RHEL ?

I have been trying to use them under Centos (=RHEL) 5.9 or 7.2, either 32 bits or 64 bits but encounter problems with "signal 11".

Regards,

 

Alain

Hello,

has anybody some experience with the C library pdflib (http://www.pdflib.com/), either version 9 or 7 (the previous free one) under RHEL ?

I have been trying to use them under Centos (=RHEL) 5.9 or 7.2, either 32 bits or 64 bits but encounter problems with "signal 11".

Regards,

 

Alain

I give a little more information :

I am trying to use pdflib 9 (and/or 7) with VC 2.3 under Centos 7.2 (64 bits) and VC 2.1 under Centos 5.9 (32 bits).

I created a little Cobol program translated from a C program working perfectly (hello.c) given ith pdflib.

When I create an executable standalone program with

$ cob -x hello.cbl -L./lib -lpdf -lm -lstdc

and execute it :
$  ./hello

I have the following error :
Execution error : file 'hello'
error code: 114, pc=0, call=1, seg=0
114     Attempt to access item beyond bounds of memory (Signal 11)

I generate a runtim :
$  cob -xo rtspdf -L./lib -lpdf -lm -lstdc -e ""
compile hello :
$  cob hello.cbl
and start it
$  ./rtspdf hello.int
and I have anothe error, not at the same point (!) :
Load error : file 'PDF_new'
error code: 173, pc=68, call=1, seg=0
173     Called program file not found in drive/directory

Same kind of problem with another program called pdfclock and translated to Cobol.

Calling C from Cobol does not seem so easy...

 

Regards

 

Alain

 

       $set sourceformat"free"
       *>
       *> PDFlib client: hello example in Cobol
       *>
       *> Compile with :
       *>   cob -x hello.cbl -L./lib -lpdf -lm -lstdc
       *>
       program-id. "hello".
       special-names.
       data division.
       working-storage section.
       *>copy "ctypes.cpy".
       1 return-status pic s9(9)  comp-5.
       1 p        usage pointer.
       1 font     pic s9(9) comp-5.
       1 a4width  comp-2 value 595.
       1 a4height comp-2 value 842.
       
       procedure division.
       *> create a new PDFlib object
       display "PDF_new"
       call "PDF_new" returning p
       if p = NULL then
        display "Couldn't create PDFlib object (out of memory)!"
        goback
       end-if

       *> This means we must check return values of load_font() etc.
       display "PDF_set_option"
       call "PDF_set_option" using by value p, by content z"errorpolicy=return"
       
       display "PDF_begin_document"
       call "PDF_begin_document" using by value p, by content z"hello.pdf", by value 0, by content z"" returning return-status
       if return-status = -1 then
           display "Error: "  *> PDF_get_errmsg(p)
           goback
       end-if

       *> This line is required to avoid problems on Japanese systems
       display "PDF_set_option"
       call "PDF_set_option" using by value p, by content z"hypertextencoding=host"
       
       display "PDF_set_info"
       call "PDF_set_info" using by value p, by content z"Creator", z"hello.c"
       call "PDF_set_info" using by value p, by content z"Author", z"Thomas Merz"
       call "PDF_set_info" using by value p, by content z"Title", z"Hello, world (C)!"
       
       move 595 to a4width
       move 842 to a4height
       display "PDF_begin_page_ext"
       call "PDF_begin_page_ext" using by value p, a4width, a4height, by content z""
       *>call "PDF_begin_page_ext" using by value p, 595, 842, by content z""
       
       *> Change "host" encoding to "winansi" or whatever you need!
       display "PDF_load_font"
       call "PDF_load_font" using by value p, by content z"Helvetica-Bold", by value 0, by content z"host", z"" returning font
       if (font = -1) then
           display "Error: "  *> PDF_get_errmsg(p)
           call "PDF_delete" using by value p
           goback
       end-if
       
       call "PDF_setfont" using by value p, font, 24
       call "PDF_set_text_pos" using by value p, 50, 700
       call "PDF_show" using by value p, by content z"Hello, world!"
       call "PDF_continue_text" using by value p, by content z"(says C)"
       call "PDF_end_page_ext" using by value p, by content z""
       
       call "PDF_end_document" using by value p, by content z""

       call "PDF_delete" using by value p
       goback
       .
       end program hello.

and the other program :

       $set sourceformat"free"
       *>
       *> A little PDFlib application to draw an analog clock.
       *>
       *> cob -x pdfclock.cbl -L./lib -lpdf -lm -lstdc
       *>

       program-id. "pdfclock".
       special-names.
          *>call-convention 8 is litlink.
       data division.
       working-storage section.
       copy "ctypes.cpy".
       78 RADIUS value 200.0.
       78 MARGIN value 20.0.
       1 return-status pic s9(9)  comp-5.
       1 p usage pointer.
       1 alpha usage is comp-2.
       1 x usage is comp-2.
       1 y usage is comp-2.
       1 z usage is comp-2.
       1 c1 usage is comp-2.
       1 c2 usage is comp-2.
       1 c3 usage is comp-2.
       1 c4 usage is comp-2.
       1 width usage is comp-2.
       1 height usage is comp-2.
       1 getopt usage is comp-2.
       1 myradius usage is comp-2.
       1 tm_hour usage is comp-2.
       1 tm_min usage is comp-2.
       1 tm_sec usage is comp-2.
       1 optlist pic x(100).

       *>----------------------------------------
       *>    date systeme
       *>----------------------------------------
       1 wrk-date.
         2 date-heure.
           3 date-jour.
             4 wrk-i4-aa                 pic 9(4).
             4 wrk-i2-mm                 pic 9(2).
             4 wrk-i2-jj                 pic 9(2).
           3 redefines date-jour.
             4 wrk-date-cc               PIC 99.
             4 wrk-date-yy               PIC 99.
             4 wrk-date-mm               PIC 99.
             4 wrk-date-dd               PIC 99.
           3 wrk-time.
             5 wrk-date-hh               PIC 99.
             5 wrk-date-min              PIC 99.
             5 wrk-date-sec              PIC 99.
             5                           PIC X(7).

       procedure division.
       *> call "CBL_DEBUGBREAK"
    
    display "Start program"
    
    set p to NULL
    call "PDF_new" returning p
    if p = NULL then
     display "Couldn't create PDFlib object (out of memory)!"
     goback
    end-if
    
    *>call "PDF_get_value" using by value p, by content z"major", by value 0 returning getopt

    display "PDF_set_parameter"
    call "PDF_set_parameter" using by value p, by content z"errorpolicy", z"return"
    
    display "PDF_begin_document"
    move 0 to z
    call "PDF_begin_document" using by value p, by content z"cbl_pdfclock.pdf", by value z, by content z""
    if return-status = -1 then
        display "Error: " *>PDF_get_errmsg(p))
        goback
    end-if
        
    *> This line is required to avoid problems on Japanese systems */
    display "PDF_set_parameter"
    call "PDF_set_parameter" using by value p, by content z"hypertextencoding", z"host"
    
    display "PDF_set_info"
    call "PDF_set_info" using by value p, by content z"Creator", z"pdfclock.c"
    call "PDF_set_info" using by value p, by content z"Author", z"Thomas Merz"
    call "PDF_set_info" using by value p, by content z"Title", z"PDF clock (C)"
    
    compute width = 2 * (RADIUS MARGIN)
    compute height = 2 * (RADIUS MARGIN)
    display "width =" width
    display "height=" height
    display "PDF_begin_page_ext"
    move z"" to optlist
    *>call "PDF_begin_page_ext" using by value p, by value width, height, by content z""
    call "PDF_begin_page_ext" using by value p, by value width, height, by content optlist
   
    compute x = RADIUS MARGIN
    compute y = RADIUS MARGIN
    display "PDF_translate"
    call "PDF_translate" using by value p, x, y
    move 0 to c1
    move 0 to c2
    move 1 to c3
    move 0 to c4
    display "PDF_setcolor"
    call "PDF_setcolor" using by value p, by content z"fillstroke", z"rgb", by value c1, c2, c3, c4
    display "PDF_save"
    call "PDF_save" using by value p
    
    *> minute strokes
    display "minute strokes"
    move 2 to width
    call "PDF_setlinewidth" using by value p, width
    perform varying alpha from 0 by 6 until alpha >= 360
        compute myRadius = 6
        call "PDF_rotate" using by value p, myRadius
        compute x = RADIUS
        compute y = 0
        call "PDF_moveto" using by value p, x, y
        compute x = RADIUS - MARGIN/3
        compute y = 0
        call "PDF_lineto" using by value p, x , y
        call "PDF_stroke" using by value p
    end-perform
    
    call "PDF_restore" using by value p
    call "PDF_save" using by value p
    
    *> 5 minute strokes
    display "5 minute strokes"
    move 3 to width
    call "PDF_setlinewidth" using by value p, width
    perform varying alpha from 0 by 30 until alpha >= 360
        compute myRadius = 30
        call "PDF_rotate" using by value p, myRadius
        compute x = RADIUS
        compute y = 0
        call "PDF_moveto" using by value p, x, y
        compute x = RADIUS - MARGIN
        compute y = 0
        call "PDF_lineto" using by value p, x , y
        call "PDF_stroke" using by value p
    end-perform
    
    move function current-date to wrk-date
    
    *> draw hour hand
    call "PDF_save" using by value p
    compute myRadius = -((wrk-date-min/60.0) wrk-date-hh - 3.0) * 30.0
    call "PDF_rotate" using by value p, myRadius
    compute x = - RADIUS/10
    compute y = - RADIUS/20
    call "PDF_moveto" using by value p, x , y
    compute x = RADIUS/2
    compute y = 0
    call "PDF_lineto" using by value p, x, y
    compute x = - RADIUS/10
    compute y =  RADIUS/20
    call "PDF_lineto" using by value p, x , y
    call "PDF_closepath" using by value p
    call "PDF_fill" using by value p
    call "PDF_restore" using by value p
    
    *> draw minute hand
    call "PDF_save" using by value p
    compute myRadius = -( (wrk-date-sec / 60.0) wrk-date-min - 15.0 ) * 6.0
    call "PDF_rotate" using by value p, myRadius
    compute x = - RADIUS/10
    compute y = - RADIUS/20
    call "PDF_moveto" using by value p, x, y
    compute x = RADIUS * 0.8
    compute y = 0
    call "PDF_lineto" using by value p, x , y
    compute x = - RADIUS/10
    compute y =   RADIUS/20
    call "PDF_lineto" using by value p, x, y
    call "PDF_closepath" using by value p
    call "PDF_fill" using by value p
    call "PDF_restore" using by value p
    
    *> draw second hand
    display "draw second hand"
    move 1 to c1
    move 0 to c2
    move 0 to c3
    move 0 to c4
    call "PDF_setcolor" using by value p, by content z"fillstroke", z"rgb", by value c1, c2, c3, c4
    move 2 to width
    call "PDF_setlinewidth" using by value p, width
    call "PDF_save" using by value p
    compute myRadius = -((wrk-date-sec - 15.0) * 6.0)
    call "PDF_rotate" using by value p, myRadius
    compute x = - RADIUS/5
    compute y = 0
    call "PDF_moveto" using by value p, x, y
    compute x = RADIUS
    compute y = 0
    call "PDF_lineto" using by value p, x, y
    call "PDF_stroke" using by value p
    call "PDF_restore" using by value p
    
    *> draw little circle at center
    move 0 to x y
    compute myRadius = RADIUS/30
    call "PDF_circle" using by value p, x, y, myradius
    call "PDF_fill" using by value p
    
    call "PDF_restore" using by value p
    
    call "PDF_end_page_ext" using by value p, by content z""
    call "PDF_end_document" using by value p, by content z""
    
    call "PDF_delete" using by value p

    goback
    .

All tests where done here with VC2.3 under RHEL7.2 with pdflib 9.

 

Regards,

Alain

 

 

 


Hello,

has anybody some experience with the C library pdflib (http://www.pdflib.com/), either version 9 or 7 (the previous free one) under RHEL ?

I have been trying to use them under Centos (=RHEL) 5.9 or 7.2, either 32 bits or 64 bits but encounter problems with "signal 11".

Regards,

 

Alain

I would try:

cob -x,CC -U hello.cbl -L./lib -lpdf -lm -lstdc

Hello,

has anybody some experience with the C library pdflib (http://www.pdflib.com/), either version 9 or 7 (the previous free one) under RHEL ?

I have been trying to use them under Centos (=RHEL) 5.9 or 7.2, either 32 bits or 64 bits but encounter problems with "signal 11".

Regards,

 

Alain

Hello,

This is a follow up to indicate that the problem has been solved.
Passing double precision parameters from Cobol to C can only happen by reference and not by value. The pdflib C API uses by default a transmission by value. Calling directly the API makes the program crash.
I wrote a very simple C "wrapper". Cobol calls a routine with parameters passed by reference, which then calls the corresponding pdflib routine. Most of the time, this is only one line :

/* Set the current point for graphics output. */
void CBLPDF_moveto(PDF *p, double *x, double *y) {
PDF_moveto(p, *x, *y);
}

/* Draw a circle. */
void CBLPDF_circle(PDF *p, double *x, double *y, double *r){
PDF_circle(p, *x, *y, *r);
}

Then from Cobol :
1 x comp-2.
1 y comp-2.
1 radius comp-2.
....
call "CBLPDF_circle" using by value ps, by reference x, y, radius

pdflib can the be used without any problem under Centos 5/7, 32 or 64 bits.
We are able to generate quite complex reports with texts and graphics, sometimes from hundreds of pages.

Regards,