Calling Java from VC 2.1

Hello,

We are quite new to Visual Cobol 2.1 for Eclipse under Linux.

We have an application in "classical cobol" and would like to be able to call the java library iText to generate pdf (or rtf) files. For example, we would like to read the content of file and generate a pdf report. The file is a MF cobol indexed file, accessed and updated with our cobol programs.

Visual Cobol offers the possibility to integrate both worlds.

But practically, how to proceed ?

A skeleton on how to start would be a great help. I'm sure that I'm not the only one with this kind of question!

Regards,

A.R.

Parents
  • Verified Answer

    Yes, you can do this... I guess the first part is to get familiar with the iText library and JVM COBOL.

    With this in mind.. below is the first example converted to COBOL, as you can see it is quite similar to Java version..

    $set sourceformat"free"
    $set ilusing "java.lang"
    $set ilusing "java.io"
    $set ilusing "com.itextpdf.text"
    $set ilusing "com.itextpdf.text.pdf"


    class-id HelloWorld.

    01 RESULT String value "HelloWorld.pdf" static.

    method-id. main static.
    procedure division using by value args as type String occurs any.

    invoke type HelloWorld::new()::createPdf(RESULT)
    end method.

    method-id createPdf.
    procedure division using by value filename as type String.

    declare document as type Document

    *> step 1
    set document to Type Document::new()

    *> step 2
    invoke type PdfWriter::getInstance(document,
    new FileOutputStream(filename))

    *> step 3
    invoke document::open()

    *> step 4
    invoke document::add(new Paragraph("Hello World!"))

    *> step 5
    invoke document::close()

    end method.
    end class.

Reply
  • Verified Answer

    Yes, you can do this... I guess the first part is to get familiar with the iText library and JVM COBOL.

    With this in mind.. below is the first example converted to COBOL, as you can see it is quite similar to Java version..

    $set sourceformat"free"
    $set ilusing "java.lang"
    $set ilusing "java.io"
    $set ilusing "com.itextpdf.text"
    $set ilusing "com.itextpdf.text.pdf"


    class-id HelloWorld.

    01 RESULT String value "HelloWorld.pdf" static.

    method-id. main static.
    procedure division using by value args as type String occurs any.

    invoke type HelloWorld::new()::createPdf(RESULT)
    end method.

    method-id createPdf.
    procedure division using by value filename as type String.

    declare document as type Document

    *> step 1
    set document to Type Document::new()

    *> step 2
    invoke type PdfWriter::getInstance(document,
    new FileOutputStream(filename))

    *> step 3
    invoke document::open()

    *> step 4
    invoke document::add(new Paragraph("Hello World!"))

    *> step 5
    invoke document::close()

    end method.
    end class.

Children
No Data