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
  • Great!

    I have been able to generate a pdf file and add some paragraph...

    I have a new problem concerning the transposition in vc of a java part of an itext example :

    In java, we have this example :

    package part1.chapter01;
     
    import java.io.FileOutputStream;
    import java.io.IOException;
     
    import com.itextpdf.text.Document;
    import com.itextpdf.text.DocumentException;
    import com.itextpdf.text.Element;
    import com.itextpdf.text.PageSize;
    import com.itextpdf.text.Paragraph;
    import com.itextpdf.text.pdf.PdfWriter;
     
    /** * Examples with mirrored margins. */
    public class HelloWorldMirroredMargins {
     
        /** Path to the resulting PDF file. */
        public static final String RESULT
            = "results/part1/chapter01/hello_mirrored_margins.pdf";
     
        /** * Creates a PDF file: hello_mirrored_margins.pdf * @param args no arguments needed */
        public static void main(String[] args)
            throws DocumentException, IOException {
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter.getInstance(document, new FileOutputStream(RESULT));
            document.setPageSize(PageSize.A5);
            document.setMargins(36, 72, 108, 180);
            document.setMarginMirroring(true);
            // step 3
            document.open();
            // step 4
            document.add(new Paragraph(
                "The left margin of this odd page is 36pt (0.5 inch); "  
                "the right margin 72pt (1 inch); "  
                "the top margin 108pt (1.5 inch); "  
                "the bottom margin 180pt (2.5 inch)."));
            Paragraph paragraph = new Paragraph();
            paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
            for (int i = 0; i < 20; i  ) {
                paragraph.add("Hello World! Hello People! "  
                		"Hello Sky! Hello Sun! Hello Moon! Hello Stars!");
            }
            document.add(paragraph);
            document.add(new Paragraph(
                "The right margin of this even page is 36pt (0.5 inch); "  
                "the left margin 72pt (1 inch)."));
            // step 5
            document.close();
        }
    }
    
    With your help, it was easily transposed in cobol except for the part in red. In java, Element is not declared explicitely. And I have found how to transfer it in cobol :

          $set sourceformat"free"
          $set ilusing "java.lang"
          $set ilusing "java.io"
          $set ilusing "com.itextpdf.text"
          $set ilusing "com.itextpdf.text.pdf"
          $set ilusing "com.itextpdf.text.Document"
          $set ilusing "com.itextpdf.text.DocumentException"
          $set ilusing "com.itextpdf.text.Element"
          $set ilusing "com.itextpdf.text.PageSize"
          $set ilusing "com.itextpdf.text.Paragraph"
          $set ilusing "com.itextpdf.text.pdf.PdfWriter"
     
    class-id HelloWorld public.

    working-storage section.
    1 RESULT String value "HelloWorldMargins.pdf" static.

    method-id. main static.
    local-storage section.
    procedure division using by value args as type String occurs any.
    invoke type HelloWorld::new()::createPdf(RESULT)
    goback.
    end method.

    method-id createPdf.
    local-storage section.
    1 i pic 99.
    procedure division using by value filename as type String.

        declare document as type Document
        declare myParagraph as type Paragraph

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

        *> step 2
        invoke type PdfWriter::getInstance(document, new FileOutputStream(filename))
        *>invoke document::SetPageSize(PageSize.A5)
        invoke document::setMargins(36,72,108,180)
        invoke document::setMarginMirroring(true)
        
        *> step 3
        invoke document::open()

        *> step 4
        invoke document::add(new Paragraph(
                "The left margin of this odd page is 36pt (0.5 inch); "
                & "the right margin 72pt (1 inch); "
                & "the top margin 108pt (1.5 inch); "
                & "the bottom margin 180pt (2.5 inch)."))
        set myParagraph to type Paragraph::new()
        *>invoke myParagraph::setAlignment(Element.ALIGN_JUSTIFIED)
        perform varying i from 1 by 1 until i > 20
          invoke myParagraph::add("Hello World! Hello People! "
                        & "Hello Sky! Hello Sun! Hello Moon! Hello Stars!")
        end-perform    
        invoke document::add(myParagraph)
        invoke document::add(new Paragraph(
                "The right margin of this even page is 36pt (0.5 inch); "
                &"the left margin 72pt (1 inch)."))
                
        *> step 5
        invoke document::close()

    end method.

    end class.

    If you have another good advise, i'll be grateful!

    Regards,

    Alain


Reply
  • Great!

    I have been able to generate a pdf file and add some paragraph...

    I have a new problem concerning the transposition in vc of a java part of an itext example :

    In java, we have this example :

    package part1.chapter01;
     
    import java.io.FileOutputStream;
    import java.io.IOException;
     
    import com.itextpdf.text.Document;
    import com.itextpdf.text.DocumentException;
    import com.itextpdf.text.Element;
    import com.itextpdf.text.PageSize;
    import com.itextpdf.text.Paragraph;
    import com.itextpdf.text.pdf.PdfWriter;
     
    /** * Examples with mirrored margins. */
    public class HelloWorldMirroredMargins {
     
        /** Path to the resulting PDF file. */
        public static final String RESULT
            = "results/part1/chapter01/hello_mirrored_margins.pdf";
     
        /** * Creates a PDF file: hello_mirrored_margins.pdf * @param args no arguments needed */
        public static void main(String[] args)
            throws DocumentException, IOException {
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter.getInstance(document, new FileOutputStream(RESULT));
            document.setPageSize(PageSize.A5);
            document.setMargins(36, 72, 108, 180);
            document.setMarginMirroring(true);
            // step 3
            document.open();
            // step 4
            document.add(new Paragraph(
                "The left margin of this odd page is 36pt (0.5 inch); "  
                "the right margin 72pt (1 inch); "  
                "the top margin 108pt (1.5 inch); "  
                "the bottom margin 180pt (2.5 inch)."));
            Paragraph paragraph = new Paragraph();
            paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
            for (int i = 0; i < 20; i  ) {
                paragraph.add("Hello World! Hello People! "  
                		"Hello Sky! Hello Sun! Hello Moon! Hello Stars!");
            }
            document.add(paragraph);
            document.add(new Paragraph(
                "The right margin of this even page is 36pt (0.5 inch); "  
                "the left margin 72pt (1 inch)."));
            // step 5
            document.close();
        }
    }
    
    With your help, it was easily transposed in cobol except for the part in red. In java, Element is not declared explicitely. And I have found how to transfer it in cobol :

          $set sourceformat"free"
          $set ilusing "java.lang"
          $set ilusing "java.io"
          $set ilusing "com.itextpdf.text"
          $set ilusing "com.itextpdf.text.pdf"
          $set ilusing "com.itextpdf.text.Document"
          $set ilusing "com.itextpdf.text.DocumentException"
          $set ilusing "com.itextpdf.text.Element"
          $set ilusing "com.itextpdf.text.PageSize"
          $set ilusing "com.itextpdf.text.Paragraph"
          $set ilusing "com.itextpdf.text.pdf.PdfWriter"
     
    class-id HelloWorld public.

    working-storage section.
    1 RESULT String value "HelloWorldMargins.pdf" static.

    method-id. main static.
    local-storage section.
    procedure division using by value args as type String occurs any.
    invoke type HelloWorld::new()::createPdf(RESULT)
    goback.
    end method.

    method-id createPdf.
    local-storage section.
    1 i pic 99.
    procedure division using by value filename as type String.

        declare document as type Document
        declare myParagraph as type Paragraph

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

        *> step 2
        invoke type PdfWriter::getInstance(document, new FileOutputStream(filename))
        *>invoke document::SetPageSize(PageSize.A5)
        invoke document::setMargins(36,72,108,180)
        invoke document::setMarginMirroring(true)
        
        *> step 3
        invoke document::open()

        *> step 4
        invoke document::add(new Paragraph(
                "The left margin of this odd page is 36pt (0.5 inch); "
                & "the right margin 72pt (1 inch); "
                & "the top margin 108pt (1.5 inch); "
                & "the bottom margin 180pt (2.5 inch)."))
        set myParagraph to type Paragraph::new()
        *>invoke myParagraph::setAlignment(Element.ALIGN_JUSTIFIED)
        perform varying i from 1 by 1 until i > 20
          invoke myParagraph::add("Hello World! Hello People! "
                        & "Hello Sky! Hello Sun! Hello Moon! Hello Stars!")
        end-perform    
        invoke document::add(myParagraph)
        invoke document::add(new Paragraph(
                "The right margin of this even page is 36pt (0.5 inch); "
                &"the left margin 72pt (1 inch)."))
                
        *> step 5
        invoke document::close()

    end method.

    end class.

    If you have another good advise, i'll be grateful!

    Regards,

    Alain


Children
No Data