Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating PDF in Cobol

1,538 views
Skip to first unread message

Rene_Surop

unread,
Jan 25, 2009, 8:40:20 PM1/25/09
to
Hi, I thought of posting this sample Cobol application that I
downloaded somewhere. Can't remember where anymore BUT it is in
espanol with a Pedro (as an author). It is a very execellent
application that can be associated to all your web applications.

If anyone could enhance it, say adding a JPEG file into a PDF... then
it will be a big help to "open source" Cobol developers. Here it is;

identification division.
program-id. TxtApdf.
environment division.
input-output section.
file-control.

select Textfle-archive assign to TextArchive-name
organization line sequential
file status fileStatTxt.

select PDFfle-archive assign to PdfArchive-name
organization line sequential
file status fileStatPdf.

Data division.
File section.
fd Textfle-archive.
01 RegTxt pic X(240).

fd PDFfle-archive.
01 RegPdf pic X(255).

working-storage section.
01 wValues.
03 B pic 9(3).
03 L pic 9(3).
03 P pic 9(3).
03 X pic 9(4).
03 Y pic 9(3).
03 PA pic zzzz.99.
03 PL pic zzzz.99.
03 Nro18 pic z(18).
03 Pagemeter pic zzzz.
03 fileStatTxt pic x(2).
03 fileStatPdf pic x(2).
03 EndSw pic x.
03 TextArchive-name pic x(50).
03 PdfArchive-name pic x(50).
03 XrefDelObj pic 9(10) occurs 2000.
03 NroObj pic 9(5).
03 NroObjPage pic 9(5) occurs 2000.
03 StreamAccum pic 9(9).
03 PageAccum pic 9(9).
03 XrefAccum pic 9(9).
03 PageSum pic 9(5).
03 LinesPerPage pic 9(5).
03 LineLength pic 9(5).
03 ObjTypeOutlines pic 9(5).
03 ObjTypeFont pic 9(5).
03 ObjTypePages pic 9(5).
03 ObjProcSet pic 9(5).
03 ObjTypeCatalog pic 9(5).

*linkage section.
01 wLink-vars.
03 PageCateg-link pic 9.
03 Inputtxt-link pic x(50).
03 PDFtxt-link pic x(50).
03 PageOrientation pic x. *>H/V Horiz/Vertical
03 LinePerPage-link pic 9(5). *>in decimal
03 PointSize-link pic 99. *>in points
03 HorizPointScale-link pic 999. *>in percent
03 SpaceEntryChar-link pic xxxx. *>space entry char
03 SpaceEntryLine-link pic 9(3). *>in points
03 LeftMargin-link pic 9(4). *>in points
03 TopMargin-link pic 9(4). *>in points
03 PageWidth-link pic 9(4)v99. *>in points
03 PageLength-link pic 9(4)v99. *>in points
03 Titleslink. *>title
05 Title-link pic x(240) occurs 5.

procedure division.
*>--------------------------------------------------------------
perform TestPage-lengthCateg

initialize wValues
move Inputtxt-link to TextArchive-name
move PDFtxt-link to PdfArchive-name

open output PDFfle-archive

perform Start-procedure

perform Go-initial-page

open input Textfle-archive

perform until fileStatTxt not = "00"
read Textfle-archive next
not at end
if LinesPerPage = LinePerPage-link
perform Go-finalize-page
perform Go-initial-page
end-if

inspect RegTxt replacing all "(" by "{"
all ")" by "}"
all "\" by " "
move RegTxt to RegPdf

perform Count-lengthAcc

move spaces to RegPdf

if LineLength > 0
string "(" RegTxt(1:LineLength) ") Tj T*"
into RegPdf
else
move "( ) Tj T*" to RegPdf
end-if

perform Count-WriteAcc

add 1 to LinesPerPage
end-read
end-perform

perform Go-finalize-page

close Textfle-archive

perform Endof-PageWrite

close PDFfle-archive

exit program.

stop run.

*>--------------------------------------------------------------
Start-procedure.
move 1 to NroObj
move "%PDF-1.4" to RegPdf
perform Count-WriteAcc

perform Start-Object
move spaces to RegPdf
move "<< /Author (Anonymous) >>" to RegPdf
perform Count-WriteAcc
perform Finalize-Object.
*>--------------------------------------------------------------
Go-initial-page.
add 1 to PageSum
move PageSum to Pagemeter

add 1 to NroObj
move NroObj to NroObjPage (PageSum)
perform Start-Object

move "<< /Length " to regPdf
compute Nro18 = NroObj + 1
perform Long-baseProc
move Nro18(B:L) to RegPdf(12:L)
move " 0 R >>" to regPdf((L + 12):7)
perform Count-WriteAcc
move "stream" to regPdf
perform Count-WriteAcc

move "BT" to regPdf
perform Count-WriteAcc

move "/F1 " to regPdf
move PointSize-link to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(5:L)
move " Tf" to regPdf((L + 5):3)
perform Count-WriteAcc

move spaces to RegPdf
move LeftMargin-link to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(1:L)
move L to P
compute Nro18 = PageLength-link - TopMargin-link
perform Long-baseProc
move Nro18(B:L) to RegPdf((P + 2):L)
move " Td" to regPdf(((L + P + 2)):3)
perform Count-WriteAcc

move spaces to RegPdf
move SpaceEntryLine-link to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
move " TL" to regPdf((L + 1):3)
perform Count-WriteAcc

move spaces to RegPdf
move HorizPointScale-link to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
move " Tz" to regPdf((L + 1):3)
perform Count-WriteAcc

move spaces to RegPdf
string SpaceEntryChar-link " Tc" into RegPdf
perform Count-WriteAcc

if PageOrientation = "h" or "H"
string "0 1 -1 0 "
TopMargin-link " "
LeftMargin-link " Tm"
into RegPdf
perform Count-WriteAcc
end-if

move 0 to LinesPerPage
perform varying y from 1 by 1 until y > 5
if Title-link (y) not = spaces
move Title-link (y) to RegPdf
perform Count-lengthAcc
move spaces to RegPdf
string "(" Title-link(y)(1:LineLength) ") Tj T*"
into RegPdf
inspect RegPdf replacing all "####" by Pagemeter
perform Count-WriteAcc
add 1 to LinesPerPage
end-if
end-perform.

*>--------------------------------------------------------------
Go-finalize-page.
move "ET" to regPdf
perform Count-WriteAcc
move PageAccum to StreamAccum
move "endstream" to regPdf
perform Count-WriteAcc
perform Finalize-Object

add 1 to NroObj
perform Start-Object
move StreamAccum to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
perform Count-WriteAcc
perform Finalize-Object
move 0 to PageAccum.

*>--------------------------------------------------------------
Endof-PageWrite.
add 1 to NroObj
move NroObj to ObjTypeOutlines
perform Start-Object
move "<< /Type /Outlines /Count 0 >>" to RegPdf
perform Count-WriteAcc
perform Finalize-Object

add 1 to NroObj
move NroObj to ObjTypeFont
perform Start-Object
move "<< /Type /Font /Subtype /Type1 /Name /F1" to RegPdf
perform Count-WriteAcc

move "/BaseFont /Courier /Encoding /WinAnsiEncoding >>"
*>move "/BaseFont /Courier-Bold /Encoding /WinAnsiEncoding
>>"
to RegPdf
perform Count-WriteAcc
perform Finalize-Object

add 1 to NroObj
move NroObj to ObjTypePages
perform Start-Object
move "<< /Type /Pages /Kids [" to RegPdf
perform Count-WriteAcc
perform varying y from 1 by 1 until y > PageSum
compute Nro18 = NroObj + 1 + y
perform Long-baseProc
move Nro18(B:L) to RegPdf
move " 0 R" to regPdf((L + 1):4)
perform Count-WriteAcc
end-perform
move "]" to RegPdf
perform Count-WriteAcc
move "/Count " to regPdf
move PageSum to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(8:L)
move " >>" to regPdf((L + 8):3)
perform Count-WriteAcc
perform Finalize-Object

add 1 to NroObj
move NroObj to ObjProcSet
perform Start-Object
move "<< /ProcSet [ /PDF /Text] /Font << "
to RegPdf
perform Count-WriteAcc
move "/F1 " to regPdf
move ObjTypeFont to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(5:L)
move " 0 R >>" to regPdf((L + 5):7)
perform Count-WriteAcc
move ">>" to RegPdf
perform Count-WriteAcc
perform Finalize-Object

perform varying y from 1 by 1 until y > PageSum
add 1 to NroObj
perform Start-Object
move "<< /Type /Page" to RegPdf
perform Count-WriteAcc

move "/Parent " to regPdf
move ObjTypePages to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(9:L)
move " 0 R" to regPdf((L + 9):4)
perform Count-WriteAcc

move PageWidth-link to PA
move PageLength-link to PL
move spaces to RegPdf
string "/MediaBox [ 0 0 " PA PL " ]"
into RegPdf
perform Count-WriteAcc

move "/Contents " to regPdf
move NroObjPage (y) to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(11:L)
move " 0 R" to regPdf((L + 11):4)
perform Count-WriteAcc

move "/Resources " to RegPdf
move ObjProcSet to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(12:L)
move " 0 R" to RegPdf((L + 12):4)
perform Count-WriteAcc

if PageOrientation = "h" or "H"
move "/Rotate 90" to regPdf
perform Count-WriteAcc
end-if

move " >>" to RegPdf
perform Count-WriteAcc
perform Finalize-Object
end-perform

add 1 to NroObj
move NroObj to ObjTypeCatalog
perform Start-Object
move "<< /Type /Catalog" to RegPdf
perform Count-WriteAcc

move "/Pages " to regPdf
move ObjTypePages to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(8:L)
move " 0 R" to regPdf((L + 8):4)
perform Count-WriteAcc

move "/Outlines " to regPdf
move ObjTypeOutlines to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(11:L)
move " 0 R" to regPdf((L + 11):4)
perform Count-WriteAcc

move " >>" to RegPdf
perform Count-WriteAcc
perform Finalize-Object

move "xref" to RegPdf
write RegPdf
add 1 to NroObj
move "0 " to regPdf
move NroObj to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(3:L)
write RegPdf
move "0000000000 65535 f" to regPdf
write RegPdf
perform varying y from 1 by 1 until y = NroObj
move spaces to RegPdf
string XrefDelObj (y) " 00000 n" into RegPdf
write RegPdf
end-perform
move "trailer" to regPdf
write RegPdf
move "<< /Size " to regPdf
move NroObj to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(10:L)
write RegPdf
move "/Root " to RegPdf
move ObjTypeCatalog to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf(7:L)
move " 0 R" to regPdf((L + 7):4)
write RegPdf
move "/Info 1 0 R" to RegPdf
write RegPdf
move ">>" to RegPdf
write RegPdf
move "startxref" to RegPdf
write RegPdf
move XrefAccum to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
write RegPdf
move "%%EOF" to RegPdf
write RegPdf.

*>--------------------------------------------------------------
Start-Object.
move XrefAccum to XrefDelObj (NroObJ)
move NroObj to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
move " 0 obj" to regPdf((L + 1):6)
perform Count-WriteAcc.

*>--------------------------------------------------------------
Finalize-Object.
move "endobj" to regPdf
perform Count-WriteAcc.

*>--------------------------------------------------------------
Count-WriteAcc.
move "N" to EndSw
perform varying x from length of RegPdf by -1
*>perform varying x from 255 by -1
until EndSw = "S"
if RegPdf (x:1) not = space
add x to PageAccum
add x to XrefAccum
move x to LineLength
move "S" to EndSw
write RegPdf
end-if
end-perform.
*>--------------------------------------------------------------
Count-lengthAcc.
move 0 to LineLength
if RegPdf not = space
move "N" to EndSw
perform varying x from length of RegPdf by -1
*>perform varying x from 255 by -1
until EndSw = "S"
if RegPdf (x:1) not = space
move x to LineLength
move "S" to EndSw
end-if
end-perform
end-if.
*>--------------------------------------------------------------
Long-baseProc.
move "N" to EndSw
perform varying x from 1 by 1 until EndSw = "S"
if Nro18(x:1) not = space
move x to B
compute L = 19 - x
move "S" to EndSw
end-if
end-perform.

*>--------------------------------------------------------------
*> This section is only for testing
*>--------------------------------------------------------------
TestPage-lengthCateg.
initialize wLink-vars
move "CobolPDF.txt" to Inputtxt-link *>Txt archive
move "CobolPDF.pdf" to PDFtxt-link *>PDF archive

move 1 to PageCateg-link

evaluate PageCateg-link
when 1 perform 80Column-vertical
when 2 perform 130Column-vertical
when 3 perform 240Column-horizontal
end-evaluate.

perform CreateTextfile-archive.

*>--------------------------------------------------------------
80Column-vertical. *>80 vertical column
move 8 to P *>80 column
move "v" to PageOrientation
move 66 to LinePerPage-link
move 24 to TopMargin-link *>2 lines 24/72
move 12 to LeftMargin-link *> 12/72
move 12 to SpaceEntryLine-link *>6 per inch 12/72
move 10 to PointSize-link *>
move " 1" to SpaceEntryChar-link *>
move 100 to HorizPointScale-link *>percentage
move 595 to PageWidth-link *>A4
move 842 to PageLength-link *>A4
string "Testing of PDF file archive generator "
" Page No.####"
into Title-link (1)
string " col 01 col 02 col 03 col 04"
" col 05 col 06 col 07 col 08"
into Title-link (2)
string "----------------------------------------"
"----------------------------------------"
into Title-link (3).

*>--------------------------------------------------------------
130Column-vertical. *>130 vertical column
move 13 to P
move "v" to PageOrientation
move 66 to LinePerPage-link
move 24 to TopMargin-link *>2 lines 24/72
move 12 to LeftMargin-link *> 12/72
move 12 to SpaceEntryLine-link *>6 per inch 12/72
move 09 to PointSize-link *>
move "-0.9" to SpaceEntryChar-link *>
move 96 to HorizPointScale-link *>percentage
move 595 to PageWidth-link *>A4
move 842 to PageLength-link *>A4

string "Testing of PDF file archive generator "
" "
" "
" Page No.####"
into Title-link (1)
string " col 01 col 02 col 03 col 04"
" col 05 col 06 col 07 col 08"
" col 09 col 10 col 11 col 12"
" col 13"
into Title-link (2)
string "----------------------------------------"
"----------------------------------------"
"----------------------------------------"
"----------"
into Title-link (3).

*>--------------------------------------------------------------
240Column-horizontal. *>240 horiz columns
move 24 to P
move "h" to PageOrientation
move 60 to LinePerPage-link
move 24 to TopMargin-link *> 2 lines 24/72
move 5 to LeftMargin-link *> 5/72
move 09 to SpaceEntryLine-link *>8 per inch 9/72
move 08 to PointSize-link *>
move "-0.8" to SpaceEntryChar-link *>
move 85 to HorizPointScale-link *>percentage
move 595 to PageWidth-link *>A4
move 842 to PageLength-link *>A4
move "Testing of PDF archive generator " to Title-link (1)
move " Page No.####" to Title-link (1)(228:13)
string " col 01 col 02 col 03 col 04"
" col 05 col 06 col 07 col 08"
" col 09 col 10 col 11 col 12"
" col 13 col 14 col 15 col 16"
" col 17 col 18 col 19 col 20"
" col 21 col 22 col 23 col 24"
into Title-link (2)
move all "-" to Title-link (3).

*>--------------------------------------------------------------
CreateTextfile-archive.
move Inputtxt-link to TextArchive-name

open output Textfle-archive

move 0 to x

perform 9999 times
move spaces to RegTxt
add 1 to x
move 0 to y
perform P times
add 1 to y
move y to Nro18
string "L" x " C" Nro18(18:1)
into RegTxt(((y * 10) - 7):8)
end-perform
write RegTxt
end-perform.

close Textfle-archive.
*>--------------------------------------------------------------

Richard

unread,
Jan 25, 2009, 10:25:21 PM1/25/09
to

Rene_Surop wrote:
> Hi, I thought of posting this sample Cobol application that I
> downloaded somewhere. Can't remember where anymore BUT it is in
> espanol with a Pedro (as an author). It is a very execellent
> application that can be associated to all your web applications.

> If anyone could enhance it, say adding a JPEG file into a PDF... then
> it will be a big help to "open source" Cobol developers. Here it is;

That is doing it the hard way. Hard graft hand coding everything by
hand and hard graft everytime something needs changing.

It is far better to do it with templating. I create postscript
templates with tgif, a graphics editor. create the merge data in the
Cobol program and then merge the data into the postscript. For a PDF
there is ps2pdf which does this nicely.

Templating keeps the presentation format outside the business logic.
It also gives flexibility, want a different laylout: edit the
template; want XML or CSV or plain text: use a different template....

Templating is not particularly hard to do, and done correctly it can
be reused for many purposes, I used the same called routines to merge
data into HTML, XML, CSV, plain text, postscript (and thus PDF).

Rene_Surop

unread,
Jan 26, 2009, 4:59:07 AM1/26/09
to
The good side of the downloaded Cobol program is that it can be used
'within' a web-based (browser) application. Say an ASPX/ASP/PHP
accessing a Cobol COM/EJB that actually do the business logic and
'create' a PDF that can be viewed in return by the browser.

I do not know how templating works with it, maybe your approach is
better or as Mr Klein wrote:
"Your style may not be my style" concept.

It would be better if we could lay out the codes for us to see.

Richard

unread,
Jan 26, 2009, 3:35:00 PM1/26/09
to

I original developed my templating in the early 90s for web based
applications outputting HTML web pages, plain text or CSV. It easily
expanded to do merge data for postscript/PDF, XML, Zerba ZPL, or many
other formats.

One of the techniques used is that the template name can be passed
into the CGI and this can override the default. As the program neither
knows nor cares what the actual output is this can override the
default template and allows the user to choose.

For example: the default template may generate an HTML web page of
some data. Clickable links on that page may be: 'get a CSV copy of
this', and could be 'get a PDF of this data'. These would get the
program to generate the same data but the template name from the link
would be used. The program just generates the data and calls the
template program which just puts the data into the template where the
tags tell it to.

In the case of a Postscript template (which may create a PDF using,
say, pstopdf) I use tgif to draw the required form with whatever
graphics, fonts, as required and the fields into which the data is
merged are input with tag names in markers, eg:

For a simple field: <!%INVOICENO%>

The cobol program has a table which is passed to the template program
(along with other stuff):

01 Tag-Table:
03 Tag-Item OCCURS 200.
05 Tag-Length PIC S99.
05 Tag-Name PIC X(20).
05 Tag-Value PIC X(80).

It could do this by:
ADD 1 TO Tag-Index
MOVE 1 TO Tag-Length(Tag-Index)
MOVE "INVOICENO" TO Tag-Name(Tag-Index)
MOVE Invoice-No TO Tag-Value(Tag-Index)

or a particular program may have the table predefined with preset tag-
names and named identifiers for the values.

For fields that are longer than the tag name these can be spaced out
in width and length:

<!%DELIVERY%------------->
<!>
<!>
<!>
<!>

I have found it important to use a graphics editor that will keep
these fields as contiguous character blocks with the output
postscript. Not all do that.

The templating program reads in the template and substitutes the 'tag-
values' where it finds the 'tag-names'. Of course it is rather more
complicated than that. The template also need to indicate some things
about how the program deals with the template and the data, for
example which charaters need escaping or substituting, whether the
output is fixed position or variable, whether CRLF is needed on the
lines.

But once developed for simple requirements it can be expanded to deal
with additional requirements without rewriting the programs that use
it.

Richard

unread,
Jan 26, 2009, 4:03:48 PM1/26/09
to
On Jan 26, 10:59 pm, Rene_Surop <infodynamics...@yahoo.com> wrote:

Templating should be a good example of the advantages of OO code. My
Cobol templating programs are not OO, but in other languages (Python)
they are.

With my current Cobol templating it is a dynamic called program and
thus is usable from a number of different applications. It has the
limitation that it can only deal with one templated output at a time,
though it is serially reusable.

The Python templating is OO and this allows the application to output
several types of data by having several template objects, each with a
different template file, and passing the data to each in turn. For
example I automatically process emailed attachments that are
excel .xls files containing delivery jobs. The client enters the data
into a spreadsheet and emails it to the site, the program monitors the
email address and fetches and extracts the attachment. Each row, or a
group of rows with the same code, in the sheet are output to the
transport system using one template while another template is used to
build the reply which lists the jobs processed.

Using conventional called programs this would need to be done with two
passes, or by building a table which is processed at the end. With OO
it is just another instance.

So if you do want to write templating it may be better to use OO.

Rene_Surop

unread,
Jan 26, 2009, 8:26:40 PM1/26/09
to
>
> So if you do want to write templating it may be better to use OO.

Thanks Richard. What I did anyway with the 'downloaded' Cobol PDF
creator application is that I bundled it in an OOCobol code. The
following steps below is an example before invoking the OOcode to
create a PDF;

1.0 From a web-browser, the client click on "Print Preview" link

2.0 From COM/EJBs (server-side)
2.1 Create a text document file of the report (file01.TXT) with
"desired" format
2.2 INVOKE the OOcode by passing the created text document
(file01.TXT) and walla!

3.0 Going back to client browser
3.1 Display the created PDF document (file01.PDF)

So from this approach, the concept is very conventional.... simple
document printing on the client side. Nothing fancy or complicated
process, except of course just the creation of a text document report.

Little drawback;
a. the developer will need to create a text file document (or report)
first
b. the OOCobol PDF creator does not incorporate image file (JPEG/GIF/
PNG) for company logo printing

But it works, simple as it is.

Richard

unread,
Jan 26, 2009, 9:33:22 PM1/26/09
to

It seems to be just putting a simple PDF wrapper around the text file
lines, wouldn't a <pre> ... </pre> do just about the same job of
displaying the text formatted as the program will print it ?

Rene_Surop

unread,
Jan 27, 2009, 12:20:41 AM1/27/09
to
> wouldn't a <pre> ... </pre> do just about the same job of
> displaying the text formatted as the program will print it?

Just like instead of doing file01.TXT to file01.PDF, do it directly
with file01.HTML with a <pre></pre> tags? Nice idea though.

Yes, except that if it's 'within' a PDF document.... the end-user
could not alter the content prior printing a document in a browser.
Some user will cut/paste document content (especially POs) and re-
print it using a Notepad. It is then that you could add security
method to a PDF.

And you can archive every users PDF (printing) file... which of course
you could do it as well in a text file.

Richard

unread,
Jan 27, 2009, 12:36:56 AM1/27/09
to
On Jan 27, 6:20 pm, Rene_Surop <infodynamics...@yahoo.com> wrote:
> > wouldn't a <pre> ... </pre> do just about the same job of
> > displaying the text formatted as the program will print it?
>
> Just like instead of doing file01.TXT to file01.PDF, do it directly
> with file01.HTML with a <pre></pre> tags? Nice idea though.
>
> Yes, except that if it's 'within' a PDF document.... the end-user
> could not alter the content prior printing a document in a browser.
> Some user will cut/paste document content (especially POs) and re-
> print it using a Notepad. It is then that you could add security
> method to a PDF.

Do you think that one cannot copy/paste from PDFs ? Probably not with
Adobe reader, but there are several other PDF readers.

Rene_Surop

unread,
Jan 27, 2009, 1:01:47 AM1/27/09
to
> Do you think that one cannot copy/paste from PDFs ? Probably not with
> Adobe reader, but there are several other PDF readers.

You can, but archiving a PDF copy will not compromise 'control'.

Few things which in most cases happening in a browser-based solution,
and usually we get rid of.

1. Default "File->Print" menu option of the browser. Some browsers has
default margin so you cannot impose the pre-defined format of the
report.

2. In browser-based apps, usually toolbar menus are
'disabled' (especially in IE) and so displaying a PDF file in browser.

So I opted to use PDF displayed report document because of the PDF
reader built-in 'print' button associated with it.

Richard

unread,
Jan 27, 2009, 12:38:50 PM1/27/09
to
On Jan 27, 7:01 pm, Rene_Surop <infodynamics...@yahoo.com> wrote:
> > Do you think that one cannot copy/paste from PDFs ? Probably not with
> > Adobe reader, but there are several other PDF readers.
>
> You can, but archiving a PDF copy will not compromise 'control'.

Nor, as you said, will archiving a text copy, or keeping the data in
the database/isam file where it will be directly accessible.

> Few things which in most cases happening in a browser-based solution,
> and usually we get rid of.
>
> 1. Default "File->Print" menu option of the browser. Some browsers has
> default margin so you cannot impose the pre-defined format of the
> report.
>
> 2. In browser-based apps, usually toolbar menus are
> 'disabled' (especially in IE) and so displaying a PDF file in browser.
>
> So I opted to use PDF displayed report document because of the PDF
> reader built-in 'print' button associated with it.

Why not only print directly to their printer and avoid interception
without having to fiddle with their browser ? It is not like you will
have random clients allowed to have POs.

(which I assume you do mean Purchase Orders).


NotSure

unread,
Jan 27, 2009, 3:37:00 PM1/27/09
to
On Sun, 25 Jan 2009 17:40:20 -0800 (PST), Rene_Surop
<infodyn...@yahoo.com> wrote:

>
> perform 9999 times
> move spaces to RegTxt
> add 1 to x
> move 0 to y
> perform P times
> add 1 to y
> move y to Nro18
> string "L" x " C" Nro18(18:1)
> into RegTxt(((y * 10) - 7):8)
> end-perform
> write RegTxt
> end-perform.
>
> close Textfle-archive.
> *>--------------------------------------------------------------

I'm trying to get this to compile & run under RMCOBOL 85 V6 on an AIX
machine. My compiler is complaining about several things, which I
think I can fix, but this one has me stumped. The compiler does NOT
like using reference modification in the receiving item of the string
statement.

Anyone have a suggestion?

TIA.


Richard

unread,
Jan 27, 2009, 4:27:07 PM1/27/09
to

Fujitsu doesn't like it either so it is probably a non-standard (85)
extension.

String into another variable (eg 01 work-area pic x(200)) and then
move this to the reference modified receiving area - that will work.

Fujitsu also complained about complete lack of 'delimited by' in the
string statements.


William M. Klein

unread,
Jan 27, 2009, 5:41:03 PM1/27/09
to
For some reason (don't ask me why), the '02 Standard relaxed the rule so that
UNSTRING could use reference modified sending items, but didn't relax the rule
for STRING and receiving items. It still says,

3) Identifier-3 shall not be reference modified.

I have sent a note to PL22.4 suggesting that this restriction be removed, but
don't look for that soon.

P.S. The other note about using STRING to a temporary data item and then moving
that to the reference modified receiving item, is your way around the
restriction.

--
Bill Klein
wmklein <at> ix.netcom.com
"NotSure" <glennpa...@verizon.net> wrote in message
news:8orun4t92bk7hjk39...@4ax.com...

Rene_Surop

unread,
Jan 27, 2009, 11:05:31 PM1/27/09
to
>
> Why not only print directly to their printer and avoid interception
> without having to fiddle with their browser ? It is not like you will
> have random clients allowed to have POs.
>
> (which I assume you do mean Purchase Orders).

Yes, it is Purchase Orders.

Say a company that has multi-branch or franchises using a browser-
based online application. So franchise in Chicago, and somewhere in
Singapore entering their POs simultaneously using a single ASP/ASPX/
PHP/JSP page.... looking at their screen with different PO entries of
their own sites, then print the PO (their own).

Some online-applications requires ActiveX for them to print from their
printer (client-side) using the information extracted from the IE/
Mozilla browsers.... but then again, it wont be feasible for Linux
users. ActiveX client application can't be installed to a Linux OS.

So browser printing format is needed.... displaying the format in PDF
and directly print it using their "own" client-based printers.

Rene_Surop

unread,
Jan 27, 2009, 11:12:29 PM1/27/09
to
>
> > I'm trying to get this to compile & run under RMCOBOL 85 V6 on an AIX
> > machine. My compiler is complaining about several things, which I
> > think I can fix, but this one has me stumped. The compiler does NOT
> > like using reference modification in the receiving item of the string
> > statement.
>
> > Anyone have a suggestion?
>
> > TIA.

>


> P.S. The other note about using STRING to a temporary data item and then moving
> that to the reference modified receiving item, is your way around the
> restriction.
>
> --
> Bill Klein

> wmklein <at> ix.netcom.com"NotSure" <glennpazzoNO...@verizon.net> wrote in message
>

The PDF Cobol application is compiled using Microfocus NetExpress v3.1

Mr Klein discusses the workaround for those errors in STRING
statement. I'm not sure about how you will do it (shotcuts) in Fujitsu
Cobol or RMCobol 85.

Rene_Surop

unread,
Jan 27, 2009, 11:22:16 PM1/27/09
to
>
> Why not only print directly to their printer and avoid interception
> without having to fiddle with their browser ? It is not like you will
> have random clients allowed to have POs.
>

Another good example in printing from the browser;

http://infowaters.infodynamicsconsult.com/iNFOWaters.asp

The browser-based application has "Print" and "Process" buttons. Print
means printing the 'selected' content of the HTML into a local
printer... BUT this application is design for IE only, because it
deploys ActiveX print module application to client browser. It cannot
be used in a Linux-based PC.

Thus the best way is PDF for all Windows/Linux/Mac OSs.

viasil...@gmail.com

unread,
Jan 29, 2009, 12:00:23 PM1/29/09
to
>            perform Count-WriteAcc...
>
> read more »

Sorry for my bad english.

There is a second way to build PDF from Cobol if your runtime (any)
can open pipes for output
(typical of all *nix ports, RmCobol, AcuCobol, VSCobol)

Take a look at: http://hpux.connect.org.uk/hppd/hpux/Shells/ClibPDF-2.02/

Free for personal usage, non-free for commercial use.

Using lex i wrote a simple filter capable to capture text report
output from cobol
and generate pdf with
- line
- box
- cirle
- barcodes
- encapsuled JPEG (for logos)
- change color, font
- write as portrait or landscape
- scale all report to A4
- ....

By example, from cobol i put in pipe output
_gbox 1.0 1.0 4.0 8.0
as result in pdf we got one rectangle large 4 inch, height 8 inch,
position 1.0 / 1.0 (starting from left lower border)

What you have to do is
- at beginning of report, or single page, put into pipe (with WRITE
statement)
all directives for drawing your report (by example INVOICE)
- then WRITE to output all data

At beginning of input, and for any occurence of FORM-FEED, filter draw
all your graphics

Final PDF is very good and professional

You can put all directives to a txt file, put it into pipe before
your report, so there is no need to edit your old cobol apps
At end i can
- write to any inkjet/laser from cobol
- send PDF from cobol to mail
- use only white A4 paper

Library comes as sources with a full reference guide

Unlucky i know ClibPDF is not free for commercial use, and authors web
site is not more available (www.fastio.com)

So i have no idea if now this is free software or not.

I am too old for do any more job :-((

Rene_Surop

unread,
Jan 29, 2009, 9:57:25 PM1/29/09
to

It is a great source of input, however it is in C++ and I do not know
how to recode it.

If you will open the created PDF file in Notepad, the content is just
really a simple text document with only a 'PDF' extension name. You
would see the following code;

%PDF-1.4
1 0 obj
<< /Author (Anonymous) >>
endobj
2 0 obj
<< /Length 3 0 R >>
:
:
and so on.

Any other information how could I insert a graphic (JPEG) file within
this PDF document? Been searching Adobe for months but I cant get a
clue how to pipe-in JPEGs into the created text PDF file. Such as
'_gbox 1.0 1.0 4.0 8.0' text pipe in the link that you gave.

Any documentation from Adobe from anywhere else?

singa

unread,
Jan 30, 2009, 4:29:40 AM1/30/09
to

Sorry, my English is very poor.
Try to explain better.

What i have done is that:
- i learned ClibPDF reference guide
- wrote a simple LEX source, embedding a litte bit of C++ calling
ClibPDF functions
- obtain one native unix executable (but under MS you can do the same)
- Cobol main program source still remain untouched
my native cobol environment is RM-Cobol85

in cobol source
ASSIGN PRINT-OUT TO "PRINTER"

in rm-cobol configuration file the name "PRINTER" is set to pipe
output to my
unix program ($HOME/bin/cobol2pdf)

Cobol program does the old dirty ascii report;
my filter (cobol2pdf) capture report thru a pipe
as final result we obtain a pdf file, named by default report.pdf,
and send it
by default to mail box of logged user

Now: for graphics, fonts, colors and so on

i wrote my cobol2pdf program using lex, so i can put in input some
formatted
directives

directives are words at begin of line, followed by optional
parameters
_gbox draw a box
_font change font (take note: this can be a barcode font)
_jpeg embed a jpeg image into pdf

parameters for _jpeg directive are
jpeg file name (must be in working folder or in specific folder for
pictures)
X.Y coordinates
scale factor (from 100 to 10)

My final usage of cobol2pdf is as follow
- i write a simple text file containing all directives to build my
reports
graphics
by default for me all pages of report are same as firts page
this text file could be 300 / 400 lines for a standard INVOICE
model
here i put all directives for drawing all boxes, including logos,
and text
(text directive can put text in landscape orientation, while the
report is in portrait)

- Now from cobol you can
- copy this text file to report output, BEFORE all your data
- leave cobol unchanged but open for print ouput a pipe, calling
one simple SH script
this script should read file where directives are stored, put it
in standard input of
cobol2pdf and copy all data coming in input from cobol to input
of cobol2pdf

I am working in this second way, so from unix shell i can send
obtained report.pdf both
to printer spooler and user's mailbox

Hope my english is not too bad and you can understand

Was a hard job, final result is very fine.

As i wrote, i'm too old to do any more job, so this project was
closed in 2004

Alain Reymond

unread,
Feb 2, 2009, 12:09:28 PM2/2/09
to
Rene_Surop a écrit :

> Hi, I thought of posting this sample Cobol application that I
> downloaded somewhere. Can't remember where anymore BUT it is in
> espanol with a Pedro (as an author). It is a very execellent
> application that can be associated to all your web applications
>
Interesting code.
But I am asking myself if a biding with a C library (like
http://libharu.org f.e.) should not be possible. PDFLib has one, but it
is not free.
Anyone here with good knowledge of Object Cobol to encapsulate the library ?

Regards,

Alain

lorenzo...@gmail.com

unread,
Apr 16, 2020, 9:29:26 AM4/16/20
to
Hello
Sorry for my english I'm italian.
For a long time I have seen this beautiful program written in cobol concerning the pdf generation and its unresolved issues.
I arrived 11 years late :), but now with this covid19 I have had time to take care of him.
I attach the source where I implemented these new functions:
- lines and boxes
- jpeg images
Surely that's not all because the pdf has an enormous number of functions, but it is a further step :)

identification division.
program-id. 114t2pdf. |Lorenzo Isotti
* sorgente originale preso da
* https://groups.google.com/forum/#!topic/comp.lang.cobol/3UqmdgduEL4
* documentazione tecnica di riferimento
* https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
* https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf
* https://www.adobe.com/technology/pdfs/presentations/KingPDFTutorial.pdf
environment division.
input-output section.
file-control.

select Textfle-archive
assign to input-output TextArchive-name
organization line sequential
file status fileStatTxt.

select PDFfle-archive
assign to input-output PdfArchive-name
organization line sequential
file status fileStatPdf.

img select JPGfle-archive
img assign to input-output JPGArchive-name
img organization binary sequential
img file status fileStatJPG.

Data division.
File section.
fd Textfle-archive.
01 RegTxt pic X(240).

fd PDFfle-archive.
01 RegPdf pic X(255).

img FD JPGfle-archive
img RECORD
img IS VARYING IN SIZE FROM 1
img TO 9999999 CHARACTERS
img DEPENDING ON REC-SIZE.
01 RegJPG PIC X(9999999).

working-storage section.
01 wValues.
03 B pic 9(3).
03 L pic 9(3).
03 P pic 9(3).
03 X pic 9(4).
03 Y pic 9(3).
03 PA pic zzzz.99.
03 PL pic zzzz.99.
03 Nro18 pic z(18).
03 Pagemeter pic zzzz.
03 fileStatTxt pic x(2).
03 fileStatPdf pic x(2).
img 03 fileStatJPG pic x(2).
03 EndSw pic x.
03 TextArchive-name pic x(50).
03 PdfArchive-name pic x(50).
img 03 JPGArchive-name PIC X(50).
03 XrefDelObj pic 9(10) occurs 2000.
03 NroObj pic 9(5).
03 NroObjPage pic 9(5) occurs 2000.
03 StreamAccum pic 9(9).
03 PageAccum pic 9(9).
03 XrefAccum pic 9(9).
03 PageSum pic 9(5).
03 LinesPerPage pic 9(5).
03 LineLength pic 9(5).
03 ObjTypeOutlines pic 9(5).
03 ObjTypeFont pic 9(5).
03 ObjTypePages pic 9(5).
03 ObjProcSet pic 9(5).
03 ObjTypeCatalog pic 9(5).

boxlin 77 ED-size-box PIC Z(8).
boxlin 77 ED-high-box PIC Z(8).
boxlin 77 ED-low-left-X-box PIC Z(8).
boxlin 77 ED-low-left-Y-box PIC Z(8).
boxlin 77 X-size-box PIC X(8).
boxlin 77 X-high-box PIC X(8).
boxlin 77 X-low-left-X-box PIC X(8).
boxlin 77 X-low-left-Y-box PIC X(8).
boxlin 77 FLAG-BOX-LINEE PIC X.

img 77 REC-SIZE PIC 9(7).
img 77 W-COUNT-CHAR PIC 9(10).
img 77 W-POINT-CHAR PIC 9(4).
img 77 W-STRINGA PIC X(64).
img 01 FILE-INFO.
img 02 FILE-SIZE PIC X(8) COMP-X.
img 02 FILE-DATE PIC 9(8) COMP-X.
img 02 FILE-TIME PIC 9(8) COMP-X.
img 77 STATUS-CODE PIC 999.
img 77 ED-8 PIC Z(8).
img 77 ED1-8 PIC Z(8).
img 77 ED2-8 PIC Z(8).
img 01 NUMERO-BIN PIC X(8).
img 01 W-STRINGA-IN PIC X(9999999). |max 9.999.999 byte
img 01 W-IND-IN PIC 9(11).
img 01 W-CRT PIC 9(11).
img 77 NUMERO PIC 9(18).
img 77 ELEVAZIONE PIC 99.
img 77 I-IND PIC 99.
img 01 32BIT.
img 05 X-CONV8 PIC X(8) OCCURS 4.
img 01 W-LENGTH PIC 9(7).
img 01 W-WIDTH PIC 9(11).
img 01 W-HEIGHT PIC 9(11).
img 01 DIMENSIONI-JPG PIC X(2).

binhex*---------------
01 CAR.
03 COD PIC 9(5) COMP-1.
01 RCAR REDEFINES CAR.
03 CAR1 PIC X.
03 CAR2 PIC X.

01 W-BYTE-ASCII PIC X.
01 W-BYTE-HEX PIC XX.
01 HI-BYTE PIC 999.
01 LO-BYTE PIC 999.
01 TABESABIN. |H| B |
|e| i |
|x| n |
| | |
03 FILLER PIC X(5) VALUE "00000".
03 FILLER PIC X(5) VALUE "10001".
03 FILLER PIC X(5) VALUE "20010".
03 FILLER PIC X(5) VALUE "30011".
03 FILLER PIC X(5) VALUE "40100".
03 FILLER PIC X(5) VALUE "50101".
03 FILLER PIC X(5) VALUE "60110".
03 FILLER PIC X(5) VALUE "70111".
03 FILLER PIC X(5) VALUE "81000".
03 FILLER PIC X(5) VALUE "91001".
03 FILLER PIC X(5) VALUE "A1010".
03 FILLER PIC X(5) VALUE "B1011".
03 FILLER PIC X(5) VALUE "C1100".
03 FILLER PIC X(5) VALUE "D1101".
03 FILLER PIC X(5) VALUE "E1110".
03 FILLER PIC X(5) VALUE "F1111".
01 RTABESABIN REDEFINES TABESABIN.
03 EL-BIN PIC X(5) OCCURS 16 INDEXED BY EB.
binhex*---------------

*linkage section.
01 wLink-vars.
03 PageCateg-link pic 9.
03 Inputtxt-link pic x(50).
03 PDFtxt-link pic x(50).
img 03 Image-link pic x(50).
03 PageOrientation pic x. *>H/V Horiz/Vertical
03 LinePerPage-link pic 9(5). *>in decimal
03 PointSize-link pic 99. *>in points
03 HorizPointScale-link pic 999. *>in percent
03 SpaceEntryChar-link pic xxxx. *>space entry char
03 SpaceEntryLine-link pic 9(3). *>in points
03 LeftMargin-link pic 9(4). *>in points
03 TopMargin-link pic 9(4). *>in points
03 PageWidth-link pic 9(4)v99. *>in points
03 PageLength-link pic 9(4)v99. *>in points
03 Titleslink. *>title
05 Title-link pic x(240) occurs 5.

procedure division.
*>--------------------------------------------------------------
DECLARATIVES.
ERRORE-Textfle-archive SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON Textfle-archive.
ERRORE-PDFfle-archive SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON PDFfle-archive.
img ERRORE-JPGfle-archive SECTION.
img USE AFTER STANDARD ERROR PROCEDURE ON JPGfle-archive.
END DECLARATIVES.
main section.
*******---incornicio la pagina
*******-------------------------(boxlin start)-------

move "q 1 0 0 1 0 0 cm % save 1 scale (0.1 10% della scala)"
to regPdf
perform Count-WriteAcc
move "/R7 gs % not relevant here"
to regPdf
perform Count-WriteAcc

move "1 w % 10 setlinewidth dimensione della linea"
to regPdf
perform Count-WriteAcc

move "0 G % black for stroking colore linea"
to regPdf
perform Count-WriteAcc

move "L" TO FLAG-BOX-LINEE |test
EVALUATE FLAG-BOX-LINEE
WHEN "L"
PERFORM PREPARA-LINEE |tecnica linee
WHEN "B"
WHEN OTHER
PERFORM PREPARA-BOX |tecnica box
END-EVALUATE

move "S % stroke "
to regPdf
perform Count-WriteAcc

move "Q % restore"
to regPdf
perform Count-WriteAcc

*******-------------------------(boxlin end)-------
img perform Read-Image.
move PageAccum to StreamAccum
move "endstream" to regPdf
perform Count-WriteAcc
perform Finalize-Object

add 1 to NroObj
perform Start-Object
move StreamAccum to Nro18
perform Long-baseProc
move Nro18(B:L) to RegPdf
perform Count-WriteAcc
perform Finalize-Object
move 0 to PageAccum.

*>--------------------------------------------------------------
boxlin PREPARA-LINEE.
if PageOrientation = "h" or "H" |se oriz vengono invertiti xy
compute ED-size-box = PageWidth-link - (TopMargin-link/2)
compute ED-high-box = PageLength-link - (LeftMargin-link/2)
else
* 595 - 12/2 = 589
compute ED-size-box = PageWidth-link - (LeftMargin-link/2)
* 842 - 24/2 = 830
compute ED-high-box = PageLength-link - (TopMargin-link/2)
end-if
MOVE ED-size-box TO X-size-box
MOVE ED-high-box TO X-high-box

move X-size-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-size-box

move X-high-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-high-box

* CALL "C$JUSTIFY" USING X-size-box "L"
* CALL "C$JUSTIFY" USING X-high-box "L"

if PageOrientation = "h" or "H" |se oriz vengono invertiti xy
compute ED-low-left-Y-box = LeftMargin-link / 2
compute ED-low-left-X-box = TopMargin-link / 2
else
* 12/2=6
compute ED-low-left-X-box = LeftMargin-link / 2
* 24/2=12
compute ED-low-left-Y-box = TopMargin-link / 2
end-if
MOVE ED-low-left-X-box TO X-low-left-X-box
MOVE ED-low-left-Y-box TO X-low-left-Y-box

move X-low-left-X-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-low-left-X-box

move X-low-left-Y-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-low-left-Y-box

* CALL "C$JUSTIFY" USING X-low-left-X-box "L"
* CALL "C$JUSTIFY" USING X-low-left-Y-box "L"

move spaces to regPdf
string "% " X-high-box " e' l'altezza del box" into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string "% " X-size-box " e' la larghezza del box" into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string "% " X-low-left-X-box
" e' l'offset X angolo basso a sx"
into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string "% " X-low-left-Y-box
" e' l'offset Y angolo basso a sx"
into regPdf
end-string
perform Count-WriteAcc

------*-------- inizio tecnica linee
* costruisco il box con la tecnica delle linee
* x y m
* (x + width) y l
* (x + width) (y + height) l
* x (y + height) l
* h

move spaces to regPdf
string X-low-left-X-box " "
X-low-left-Y-box
" m % m = moveto angolo basso sx x , y"
into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string X-size-box delimited by size
" "
X-low-left-Y-box
" l % l = lineto angoli basso dx x , y"
into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string X-size-box delimited by size
" "
X-high-box delimited by size
" l % angolo alto dx x , y"
into regPdf
end-string
perform Count-WriteAcc

move spaces to regPdf
string X-low-left-X-box " "
X-high-box
" l % angolo alto sx x , y"
into regPdf
end-string
perform Count-WriteAcc

move "h % closepath"
to regPdf
perform Count-WriteAcc.
------*-------- fine tecnica linee
*>--------------------------------------------------------------
boxlin PREPARA-BOX.
if PageOrientation = "h" or "H" |se oriz vengono invertiti xy
compute ED-size-box = PageWidth-link - TopMargin-link
compute ED-high-box = PageLength-link - LeftMargin-link
else
* 595 - 12/2 = 589
compute ED-size-box = PageWidth-link - LeftMargin-link
* 842 - 24/2 = 830
compute ED-high-box = PageLength-link - TopMargin-link
end-if
MOVE ED-size-box TO X-size-box
MOVE ED-high-box TO X-high-box

move X-size-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-size-box

move X-high-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-high-box

* CALL "C$JUSTIFY" USING X-size-box "L"
* CALL "C$JUSTIFY" USING X-high-box "L"

if PageOrientation = "h" or "H" |se oriz vengono invertiti xy
compute ED-low-left-Y-box = LeftMargin-link / 2
compute ED-low-left-X-box = TopMargin-link / 2
else
* 12/2=6
compute ED-low-left-X-box = LeftMargin-link / 2
* 24/2=12
compute ED-low-left-Y-box = TopMargin-link / 2
end-if
MOVE ED-low-left-X-box TO X-low-left-X-box
MOVE ED-low-left-Y-box TO X-low-left-Y-box

move X-low-left-X-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-low-left-X-box

move X-low-left-Y-box to Nro18
perform Long-baseProc
move Nro18(B:L) to X-low-left-Y-box

* CALL "C$JUSTIFY" USING X-low-left-X-box "L"
* CALL "C$JUSTIFY" USING X-low-left-Y-box "L"

------*-------- inizio tecnica rettangolo
* costriusco il rettangolo con questa istruzione
* x y width height re
move spaces to regPdf
string X-low-left-X-box " " |angolo X basso sx
X-low-left-Y-box " " |angolo Y basso sx
X-size-box " " |angolo X alto dx
X-high-box " re " |angolo Y alto dx
into regPdf
end-string
perform Count-WriteAcc

move "h % closepath"
to regPdf
perform Count-WriteAcc .
------*-------- fine tecnica rettangolo
move "c:\tmp\xCobolPDF.txt" to Inputtxt-link *>Txt archive
move "c:\tmp\xCobolPDF.pdf" to PDFtxt-link *>PDF archive
img move "c:\tmp\xCobolPDF.jpg" to Image-link *>image
* perform 2 times |togli
move spaces to RegTxt
add 1 to x
move 0 to y
perform P times
add 1 to y
move y to Nro18
string "L" x " C" Nro18(18:1)
into RegTxt(((y * 10) - 7):8)
end-perform
write RegTxt
end-perform.

close Textfle-archive.
*>--------------------------------------------------------------
------*---------(start img)-------------------------------------------
Read-Image.
CALL "C$FILEINFO" |mi serve per testare esistenza e size file
USING Image-link, FILE-INFO,
GIVING STATUS-CODE.
IF STATUS-CODE NOT = 0 EXIT PARAGRAPH
END-IF.
MOVE Image-link to JPGArchive-name.
move file-size to REC-SIZE.
OPEN INPUT JPGfle-archive
READ JPGfle-archive NEXT AT END EXIT PARAGRAPH
END-READ.
PERFORM DATI-JPG.
PERFORM SCRIVI-TESTA-IMG.
PERFORM SCRIVI-ASCIIHEX
move "EI" TO RegPdf
perform Count-WriteAcc.
move "Q" TO RegPdf
perform Count-WriteAcc.
close JPGfle-archive.

SCRIVI-ASCIIHEX.
MOVE 1 TO W-POINT-CHAR.
MOVE 0 TO W-COUNT-CHAR.
MOVE SPACES TO W-STRINGA.
perform until 1 = 2
MOVE SPACES TO W-BYTE-ASCII W-BYTE-HEX
ADD 1 TO W-COUNT-CHAR
MOVE W-STRINGA-IN(W-COUNT-CHAR:1) TO W-BYTE-ASCII
PERFORM ASCII2BINhex

STRING W-BYTE-HEX DELIMITED BY SIZE
INTO W-STRINGA POINTER W-POINT-CHAR
END-STRING

IF W-POINT-CHAR > 63
MOVE W-STRINGA TO RegPdf
perform Count-WriteAcc
MOVE SPACES TO W-STRINGA
MOVE 1 TO W-POINT-CHAR
END-IF
IF W-COUNT-CHAR > W-LENGTH EXIT PERFORM
END-IF
end-perform.
STRING ">" DELIMITED BY SIZE
INTO W-STRINGA POINTER W-POINT-CHAR
END-STRING.
MOVE W-STRINGA TO RegPdf
perform Count-WriteAcc.

SCRIVI-TESTA-IMG.
MOVE "q" to RegPdf.
perform Count-WriteAcc.
*%23 0 0 69 0 0 20 6 12 cm
MOVE SPACES TO RegPdf
MOVE W-HEIGHT TO ED1-8.
MOVE W-WIDTH TO ED2-8.
if PageOrientation = "h" or "H" |se oriz vengono invertiti xy
STRING ED2-8 DELIMITED BY SIZE
" 0 0 "
ED1-8 DELIMITED BY SIZE
" 0 0 35 25 407 cm % 35=%resize image 25/407 position
- ""
INTO RegPdf
END-STRING
perform Count-WriteAcc
* cosQ sinQ -sinQ cosq
* 0.7071 0.7071 -0.7071 0.7071 0 0 cm % 45 deg rotation
* 0.0000 1.0000 -1.0000 0.0000 0 0 cm % 90 deg rotation
MOVE "0.0000 1.0000 -1.0000 0.0000 0 0 cm % 90 deg rotatio
- "n" TO RegPdf

ELSE
STRING ED1-8 DELIMITED BY SIZE
" 0 0 "
ED2-8 DELIMITED BY SIZE
" 0 0 15 280 815 cm % 15=%resize image 280/815 positi
- "on"
INTO RegPdf
END-STRING
END-IF.
perform Count-WriteAcc.
MOVE "BI" to RegPdf
perform Count-WriteAcc.
MOVE W-WIDTH TO ED-8.
MOVE SPACES TO RegPdf.
STRING "/W " ED-8 INTO RegPdf.
* MOVE "/W 69" to RegPdf
perform Count-WriteAcc.

MOVE W-HEIGHT TO ED-8.
MOVE SPACES TO RegPdf.
STRING "/H " ED-8 INTO RegPdf.
* MOVE "/H 23" to RegPdf
perform Count-WriteAcc.

MOVE "/BPC 8" to RegPdf
perform Count-WriteAcc.
MOVE "/CS /DeviceRGB" to RegPdf
perform Count-WriteAcc.

MOVE "/F [ /AHx /DCTDecode ]" to RegPdf
perform Count-WriteAcc.

MOVE W-LENGTH TO ED-8
MOVE SPACES TO RegPdf
STRING "/Length " DELIMITED BY SIZE
ED-8 DELIMITED BY SIZE INTO RegPdf
END-STRING
perform Count-WriteAcc.
MOVE "ID" to RegPdf
perform Count-WriteAcc.

ASCII2BINhex. |input W-BYTE-ASCII
|output NUMERO-BIN
|output COD (codascii)
|output W-BYTE-HEX
MOVE 0 TO COD.
MOVE W-BYTE-ASCII TO CAR2
DIVIDE COD BY 16 GIVING HI-BYTE
REMAINDER LO-BYTE
COMPUTE EB = HI-BYTE + 1
MOVE EL-BIN(EB)(1:1) TO W-BYTE-HEX(1:1)
MOVE EL-BIN(EB)(2:4) TO NUMERO-BIN(1:4)
COMPUTE EB = LO-BYTE + 1
MOVE EL-BIN(EB)(1:1) TO W-BYTE-HEX(2:1).
MOVE EL-BIN(EB)(2:4) TO NUMERO-BIN(5:4) .

BIN2DEC. |input NUMERO-BIN - output W-BYTE-ASCII - output COD
MOVE ZERO TO COD
SET EB TO 1
SEARCH EL-BIN
WHEN EB NOT > 16 AND EL-BIN(EB)(2:4) = NUMERO-BIN(1:4)
END-SEARCH
COMPUTE HI-BYTE = EB - 1
SET EB TO 1
SEARCH EL-BIN
WHEN EB NOT > 16 AND EL-BIN(EB)(2:4) = NUMERO-BIN(5:4)
END-SEARCH
COMPUTE LO-BYTE = EB - 1
COMPUTE COD = 16 * HI-BYTE + LO-BYTE
MOVE CAR2 TO W-BYTE-ASCII.

32BIT-DEC.
MOVE 0 TO NUMERO ELEVAZIONE.
* move "01100101011000010111001101111001" TO 32BIT.
PERFORM VARYING W-IND-IN FROM 32 BY -1 UNTIL W-IND-IN = 0
IF 32BIT(W-IND-IN:1) = "1"
IF ELEVAZIONE > 0
COMPUTE NUMERO = NUMERO + (2 ** ELEVAZIONE)
ELSE
ADD 1 TO NUMERO
END-IF
END-IF
ADD 1 TO ELEVAZIONE
END-PERFORM.
* Qui in NUMERO ho il valore decimale dei 32bit binari

DATI-JPG.
MOVE FILE-SIZE TO W-LENGTH.
MOVE SPACES TO W-STRINGA-IN.
|primi 4 byte indicatori jpg FF D8 FF E0
STRING X"FFD8FFE0" |identificativo jpg che la read mi perde
|e devo quindi riaggiunger alla stringa
|forse un bug acucobol con record var
REGJPG(1:W-LENGTH) INTO W-STRINGA-IN
END-STRING.
* 164-165 crt in hex convertiti in dec height
MOVE W-STRINGA-IN(164:2) TO DIMENSIONI-JPG.
MOVE ALL "0" TO 32BIT.
MOVE 2 TO W-IND-IN.
PERFORM VARYING W-CRT FROM 1 BY 1 UNTIL W-CRT > 2
MOVE DIMENSIONI-JPG(W-CRT:1) TO W-BYTE-ASCII
PERFORM ASCII2BINhex
ADD 1 TO W-IND-IN
MOVE NUMERO-BIN TO X-CONV8(W-IND-IN)
END-PERFORM.
PERFORM 32BIT-DEC.
MOVE NUMERO TO W-HEIGHT.
* 166-167 crt in hex convertiti in dec width
MOVE W-STRINGA-IN(166:2) TO DIMENSIONI-JPG.
MOVE ALL "0" TO 32BIT.
MOVE 2 TO W-IND-IN.
PERFORM VARYING W-CRT FROM 1 BY 1 UNTIL W-CRT > 2
MOVE DIMENSIONI-JPG(W-CRT:1) TO W-BYTE-ASCII
PERFORM ASCII2BINhex
ADD 1 TO W-IND-IN
MOVE NUMERO-BIN TO X-CONV8(W-IND-IN)
END-PERFORM.
PERFORM 32BIT-DEC.
MOVE NUMERO TO W-WIDTH.

------*---------(end img)-------------------------------------------

Kerry Liles

unread,
Apr 16, 2020, 12:45:34 PM4/16/20
to
On 4/16/2020 9:29 AM, lorenzo...@gmail.com wrote:
> Hello
> Sorry for my english I'm italian.
> For a long time I have seen this beautiful program written in cobol concerning the pdf generation and its unresolved issues.
> I arrived 11 years late :), but now with this covid19 I have had time to take care of him.
> I attach the source where I implemented these new functions:
> - lines and boxes
> - jpeg images
> Surely that's not all because the pdf has an enormous number of functions, but it is a further step :)
>

* sorgente originale preso da
* groups.google.com/forum/#!topic/comp.lang.cobol/3UqmdgduEL4
* documentazione tecnica di riferimento
* www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
*
www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf
* www.adobe.com/technology/pdfs/presentations/KingPDFTutorial.pdf


...deleted source code

Thank you! Very interesting.
I wish you success with this interesting project.

pete dashwood

unread,
Apr 22, 2020, 8:58:57 PM4/22/20
to
That was very interesting, thanks.

But, in the real world, I'd use one of the very many COM components that
handle PDFs. (To be fair, some of these are not free, but for commercial
use, neither is COBOL...)

1. Create an object. (say, 3 lines of code).
2. Invoke whatever PDF function I wanted (Open, Read, Edit, etc.)
(say, 8 lines of code with the parameters to the invoke.)

So, for less than a dozen lines of OO COBOL I could do ANYTHING I wanted
with a PDF, without re-inventing the wheel... :-)

Pete.


0 new messages