cups-pdf, with some options

GNU Cobol
2014-04-16
2014-04-21
  • Brian Tiffin
    Brian Tiffin
    2014-04-16

    Wanted to try running some Report Writer output through cups-pdf.

    Turns out the default 10cpi with 132 columns makes for cutoff pages. So, finally had to sit down and figure out at least a little bit about the options array. Not overly documented, but found a page at http://www.cups.org/documentation.php/options.html#OPTIONS

    From the cups-pdf site, there is also information on option control through a .PPD file, but for this pass, didn't dig very far. http://www.cups-pdf.de/documentation.shtml

    So, this set of options worked, but experimenting was limited, once it seemed reasonable. In the real world, this code may get you laughed out of the print shop.

    GNU    >>SOURCE FORMAT IS FIXED
    Cobol *> ***************************************************************
          *> Author:    Brian Tiffin
          *> Date:      10-Aug-2009, 16-Apr-2014
          *> Purpose:   CUPS quick print (to PDF)
          *> Tectonics: cobc -lcups -x cupscob.cob
          *> ***************************************************************
           identification division.
           program-id. cupspdf.
    
           data division.
           working-storage section.
           01 result               usage binary-long.
           01 cupsError            usage binary-long.
           01 msgPointer           usage pointer.
           01 msgBuffer            pic   x(1024) based.
           01 msgDisplay           pic   x(132).
    
           01 cups-options         usage pointer.
           01 num-options          usage binary-long.
    
          *> ***************************************************************
           procedure division.
    
          *> Note: addOption takes a ** to the options array, so
          *>       pass the cups-options pointer BY REFERENCE
          *>       cupsPrintFile takes a * to the options array, so
          *>       pass the cups-options pointer BY VALUE
    
          *> set the characters per inch to teeny
           call "cupsAddOption"
               using
                   z"cpi"
                   z"17"
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
          *> try and fit on a page
           call "cupsAddOption"
               using
                   z"fit-to-page"
                   z""
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
          *> request print control filenames and dates
           call "cupsAddOption"
               using
                   z"prettyprint"
                   z""
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
          *> set nowrap
           call "cupsAddOption"
               using
                   z"nowrap"
                   z""
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
          *> set margins, 1/2 inch in 1/72nds
           call "cupsAddOption"
               using
                   z"page-left"
                   z"36"
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
           call "cupsAddOption"
               using
                   z"page-right"
                   z"36"
                   by value num-options
                   by reference cups-options
               returning num-options
               on exception
                   display "cupsAddOption failure" upon syserr end-display
           end-call
    
          *> print the file, directed to the cups-pdf driver
           call "cupsPrintFile"
             using
               "Cups-PDF" & x"00"
               "SYSPRINT" & x"00"
               "report06.pdf" & x"00"
               by value num-options
               by value cups-options
             returning result
           end-call
    
           if result equals zero
               call "cupsLastError" returning cupsError end-call
               display "Err: " cupsError end-display
    
               call "cupsLastErrorString" returning msgPointer end-call
               set address of msgBuffer to msgPointer
               string
                   msgBuffer delimited by x"00"
                 into msgDisplay
               end-string
               display function trim(msgDisplay) end-display
           else
               display "Job: " result end-display
           end-if
    
          *> free the options array
           call "cupsFreeOptions" using
               by value num-options
               by value cups-options
               returning omitted
           end-call
    
           goback.
           end program cupspdf.
    

    This uses hard coded options and filenames. The tutorial Report Writer programs by Jay Moseley http://www.jaymoseley.com/hercules/compiling/cobolrw.htm use SYSPRINT as the output DD name. On GNU/Linux, that gets saved as a file called "SYSPRINT" (as it's a DD name, SYSPRINT=someotherfile.txt ./rwex06 could be used for finer control). In this run, that was left as is, and "SYSPRINT" is sent to CUPS, using the cups-pdf device, with an output name of "report06.pdf" (under Fedora cups-pdf output ends up in the ~/Desktop folder).

    Should the filenames and options be command line parameters? Probably. ;-)

    Cheers,
    Brian

     
    Last edit: Brian Tiffin 2014-04-19
    • Brian Tiffin
      Brian Tiffin
      2014-04-19

      Edit; Attached. 500k pdf from 4.4k of text. ;-)

      This is a little bit voodoo on details as I rarely print things, and I'm pretty sure most of the options set in cups-options are ignored/conflicting/misspelled. Setting PDFSettings=/screen versus /prepress seemed to have no effect on the output size, so there is something amiss in this particular print chain cups-pdf setup.

      Cheers,
      Brian

       
      Last edit: Brian Tiffin 2014-04-19
      • Simon Sobisch
        Simon Sobisch
        2014-04-19

        Looks nice, good to see what you were talking about :-)
        Formatting within the text would be the next step ;-)

         
  • Simon Sobisch
    Simon Sobisch
    2014-04-17

    Sounds interesting. Please come up with uploads for SYSPRINT and report06.pdf - just to show the difference.

    The even more interesting thing would be real formatting (you know bold/italic/different sizes) within the file (headlines bold, foot notes italic, ...).

    Simon

     
  • All you guys that have contributed to Gnu-Cobol, you've done so much for Cobol! Much appreciated!

    I recently thought that formatting reports using HTML & CSS could be the best option. But in the end I find that browsers are not good at real printing, page breaks and similar issues. PDF is so far the best option for reports, especially the type of reports that we commonly develop using Cobol. Over the past five years or more I've used the Cups PDF printer for on-the-fly PDF creation. It's so easy to create a PDF from any printable document. Since Cobol has always generated reports using simple ASCII text, I could use a “system” call to send text to the PDF printer, and then allow the user to view and/or send it to a real printer. In most cases users don't really want to print it, they usually just view, save, or email it. But when they do want to print it, PDF is the best option as far as I see.

    To go a step further, to actually create a real PDF directly from Cobol, I've used PDF4TCL to do line drawing, font/color selection, inserting images. Now I'm looking at Haru, AKA libharu, a ANSI C pdf library. One day, when I have time, I plan on creating a 'libcobharu' to enable line drawing, font/color selection, inserting images, directly from Cobol.

    https://sourceforge.net/projects/libharu/

    Curious, How difficult would it be to incorporate libharu into Gnu-Cobol, as an option to plain ASCII output. Instead a plain PDF, incorporating simple things like “ORGANIZATION IS PDF” to output the ANSI C calls to libharu, where “WRITE” and “AFTER ADVANCING” would make the right calls to libharu. Maybe have some new reserved variables like TEXT-FONT, TEXT-SIZE, TEXT-FGCOLOR, TEXT-BGCOLOR, or similar.

    Later, in the report writer, maybe add something like “USAGE IS BOX, BORDER-RADIUS is nn” or “USAGE IS IMAGE” or “USAGE IS LINE” or “USAGE IS CHART”.

    Just thinking, I don't know.

     
    Last edit: Michael Anderson 2014-04-20
  • Brian Tiffin
    Brian Tiffin
    2014-04-20

    I was pondering nearly the same thing, how to get fancier output. Wondering if LaTeX backslash controls could be snuck into Report Writer field, and break condition definitions; without too much grief with LINE and COLUMN. Might place too much burden on application developer to be of practical use.

    Intermediates may help. Sphinx, make latexpdf, from ReStructuredText perhaps.

    libharu looks very interesting Michael, thanks for the link. It's in the Fedora repos too. Good sign. Means that for the now, if someone needs to dig in with fine detail, a path seems open.

    How this may ever fold into GNU Cobol?, the compiler proper, ummm, it might not be until Draft Spec 202x, :-)

    Cheers,
    Brian

     
  • Bruce Martin
    Bruce Martin
    2014-04-21

    With regards Cobol-Reporting, Many years ago I created FFReport (http://ffreport.sourceforge.net/FFReport02.html). There are some images of the
    report-output produced by FFReports at the web site.

    Basically I wrote interfaces to Jasper-Report + IReport-Designer packages that lets
    Cobol-Data-Files (with Cobol Copybooks) be used as Report data-sources.

    IReports is a Drag and drop style Report designer; it also has wizards for common report types.

    Project made it easy to create Fancy reports from a Cobol-Data file.

    I stopped work on the project 3 years ago because:

    • There seemed to be no interest in the FFReport project
    • I had no use for the project myself
    • I was getting sick of IReports - every version fixed some problems but introduced some new ones. I wanted a more stable base product.
    • IReports is huge package.

    Currently the connection between FFReport and the Record-Editor will not work, but the Cobol connection should
    If there is enough interest I could have another look at a Cobol only version of FFReport (Also I think IBM/Eclipse has a different Java reporting tool).