ahulikavi
25th February 2004, 06:05
We have developed baan to pdf functionality using Java iText Class, Java class is executed through shell script which is called by 4GL baan script.

More information at
http://www.lowagie.com/iText/

Following things are done presently :

Any baan report is converted into PDF, page size/Font is chosen automatically based on report size.

PDF is encrypted and only Print choice is enabled.

Company Logo and Custom footer with Date/Time Stamp and User details added.

Things not done :

Font effects of report not carried over since basically its a text to PDF converter. (How to get formatting details ? (report XML could help ???)

~Vamsi
25th February 2004, 06:36
Akshay,

Is the code you developed open source? If it is please either post it to this forum or a link to some other location.

If it is not open source... I will move the announcement to a different forum.

ahulikavi
25th February 2004, 08:14
Hi,

3 components are required

1. Baan 3GL to convert report to ASCII and invoke shell scripts
2. Java Class to convert text to pdf
3. Shell scripts to invoke java class
4. Device Definition

1. Baan 3GL - Hope copyright is OK

||******************************************************************************
|* tdtcdpdf 0 VRC B40C L ive
|* Title : PDF
|* Author : Akshay Hulikavi
|* Date : 2004-02-09 [09:17]
|******************************************************************************
|* License :
|* Copyright 2004 by Akshay Hulikavi
|*
|* All Rights Reserved
|*
|* Permission to use, copy, modify, and distribute this software and its
|* documentation for any purpose and without fee is hereby granted,
|* provided that the above copyright notice appear in all copies and that
|* both that copyright notice and this permission notice appear in
|* supporting documentation.
|*
|* Akshay Hulikavi DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|* AND FITNESS, IN NO EVENT SHALL Akshay Hulikavi BE LIABLE FOR ANY
|* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
|* OR PERFORMANCE OF THIS SOFTWARE.
|******************************************************************************
#pragma used dll ottdllbw

long ret, fp, zoomed | general return variable
extern domain tcmcs.str215 input.file, pdf.file, local.file | input file - created by Baan
extern domain tcmcs.str215 argument, argu1, argu4, argu0, argu2, argu3
extern domain tcmcs.str215 argu5, argu6, argu7, argu8, argu9
extern string sh.string(1024), file.path(128), date.str(8), time.str(5), dat(12)

function main()
{
argu0 = argv$(0)
argu1 = argv$(1)
argu2 = argv$(2)
argu3 = argv$(3)
argu4 = argv$(4)
zoomed = false

dat = dte$()
date.str = dat(3;2) & "/" & dat(1;2)& "/" & dat(5;2)
time.str = dat(7;2) & ":" & dat(9;2)

if argu1 = "" and argu2= "" then | Called from another program not spooler
import("argu1", argu1)
import("argu2", argu2)
import("argu3", argu3)
import("argu4", argu4)
zoomed = true
endif

file.path = getcwd()
input.file = shiftl$(strip$(argu2))
ret = wait.and.activate("ttstpconv", argu1, input.file, "ASCII", "wt")


input.file = shiftl$(strip$(file.path))&"/"&shiftl$(strip$(input.file))
pdf.file = input.file&".pdf"
local.file = "c:\"&shiftl$(strip$(argu2))&".pdf"

sh.string = ""
sh.string = sh.string &" "&chr$(34)&input.file&chr$(34)
sh.string = sh.string &" "&chr$(34)&pdf.file&chr$(34)
sh.string = sh.string &" "&str$(spool.pg.length)
sh.string = sh.string &" "&chr$(34)&logname$&" on "& date.str & " at "& time.str& chr$(34)

fp=seq.open("text2pdf.sh","r")
if fp >= 1 then | text2pdf.sh file exists
ret = shell( "text2pdf.sh " & sh.string,0)
else
fp=seq.open("text2pdf.sh","wt")
seq.puts("cd /baanIVc/c4/bse/tcd_email", fp)
seq.puts("pdf.sh $@", fp)
seq.close(fp)
ret = shell( "chmod 777 text2pdf.sh",0)
ret = shell( "text2pdf.sh " & sh.string,0)
endif

if ret = 0 then
if zoomed = false then | Called from another program not report
ret = server2client(pdf.file,local.file, 0, 0) | Binary Mode Transfer
if ret = 0 then
ret = app_start(local.file,"","","","")
ret = seq.unlink(input.file)
ret = seq.unlink(pdf.file)
else
message("File could sent to client !!!!" & str$(ret)&local.file)
endif
endif
else
message("File could not be created !!!!" & str$(ret))
endif

}
|*********************************** end of script ****************************





2. the java class tcd_text2pdf

/*
Class to convert baan ascii report to pdf
Author : Akshay Hulikavi
Date : 10.02.2004

Requires : itext-x.jar - can be downloaded from www.lowagie.com/iText/
Source can be downloaded from www.lowagie.com/iText/

Usage : java tcd_text2pdf <inputfile> <outputfile.pdf> <PageLength, Default = 60>

*/
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;

public class tcd_text2pdf
{

public static void main(String[] args)
throws IOException, DocumentException
{
String resultStr = "", line=null, strFooter;
int lncnt=1, i, j, pgcnt=0, fntSize=8, lineSpacing, strLength=0;

//~ i = Integer.parseInt(args[2]);
j = Integer.valueOf(args[2]).intValue();
if (j <= 0)
j = 60; // Default page length

if(args.length < 2 ) {
System.out.println("Usage : java tcd_text2pdf <inputfile> <outputfile.pdf> <PageLength, Default = 60>");
return;
}

Reader in = new InputStreamReader(new FileInputStream(args[0]));
OutputStream os = new FileOutputStream(args[1]);
Document doc= new Document();
Image t_logo = Image.getInstance("logocolor.jpg");
t_logo.scalePercent(75); // scale image to 75%
java.io.BufferedReader br2 = new java.io.BufferedReader(in);

// get length of the longest line
try {
BufferedReader bufReader = new BufferedReader(new FileReader(args[0]));
while ((line=bufReader.readLine()) != null){
if (strLength < line.length())
strLength = line.length();
}
bufReader.close();

} catch (IOException e) {
System.err.println(e);
}



line = null;
i=1;

/*
Decide on Paper Size ,Orientation and Line Spacing based on max line length in report

*/
if (strLength <= 108)
i = 1 ;
if (strLength > 108 && strLength <= 127)
i = 2 ;
if (strLength > 127 && strLength <= 165)
i = 3 ;
if (strLength > 165 && strLength <= 176)
i = 4 ;
if (strLength > 176 && strLength <= 239)
i = 5;
if (strLength > 239)
i = 6 ;

switch (i) {
case 1:
doc = new Document(PageSize.A4, 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(535, 770); // image margin 60 so 595-60 and 842-60
break;
case 2:
doc = new Document(PageSize.A4, 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(535, 770);
break;
case 3:
doc = new Document(PageSize.A4.rotate(), 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(770, 535);
break;
case 4:
doc = new Document(PageSize.A4.rotate(), 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(770, 535);
break;
case 5:
doc = new Document(PageSize.LEDGER, 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(1164, 732);
break;
case 6:
doc = new Document(PageSize.LEDGER, 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(1164, 732);
break;
default:
doc = new Document(PageSize.A4, 36, 36, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(535, 770); // image margin 85 so 595-85 and 842-85
break;

}


// Add footer
strFooter = "Thermax Limited Chemical Division : 97-E General Block MIDC Bhosari Pune 411026";
strFooter +="\nPhone - 91-20-27120181, Fax - 91-20-27120206, URL - www.thermaxindia.com/chemical";
strFooter +="\nGenerated by (BaaN Login) : ";
strFooter +=args[3];

HeaderFooter footer = new HeaderFooter(new Phrase(strFooter,FontFactory.getFont(FontFactory.COURIER, 7)), false);

PdfWriter docWriter = null;
docWriter = PdfWriter.getInstance(doc, os);
doc.setFooter(footer);
docWriter.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.AllowPrinting);
doc.addTitle("BaaN Report");
doc.addSubject("Report Generated from BaaN System");
doc.addKeywords("Thermax Limited Chemical Division : 97-E General Block MIDC Bhosari Pune 411026");

doc.open();
doc.add(t_logo);
Paragraph p;
java.io.BufferedReader br = new java.io.BufferedReader(in);

try {
while ((line=br.readLine()) != null){
if (lncnt > j)
{
doc.newPage();
lncnt = 0;
}
p = new Paragraph(new Phrase(lineSpacing,line,FontFactory.getFont(FontFactory.COURIER, fntSize)));
doc.add(p);
lncnt++;
}
br.close();
} catch (IOException e) {
System.out.println("IO Exception on Buffered Read :" + e);
};

doc.close();
os.close();
}

}



3. Shell Scripts
a. text2pdf.sh in user home directory
cd /baanIVc/c4/bse/tcd_email
pdf.sh $@


b. pdf.sh in say $BSE or other convinient directory
CLASSPATH=.:/baanIVc/c4/bse/tcd_email/PeBSClasses.zip:/baanIVc/c4/bse/tcd_email/itext-1.01.jar:/usr/j2se/javamail/javamail-1.3/mail.
export CLASSPATH
java tcd_text2pdf $@



4. Device Definition
Also need to define device called say PDF as follows

Device type: Rewrite File
4GL Program : tdtcdpdf
Argument : %s
Page Length : 72



regards

~Vamsi
25th February 2004, 20:18
Akshay,

I split the posting into two threads so that there is more visibility. You get the advantage of 4066 views to start with ;).

NPRao
8th May 2004, 01:42
Sean C. Sullivan works for our company and there was Portland Java User Group meeting here in April.

Here is more info -

Portland Java User Group Meeting Info (http://www.pjug.org/)

The topic was - Generating reports with JasperReports and there is a ppt on the site for reference.

Generating reports with JasperReports
JasperReports is an open source Java reporting tool. In this presentation, we will discuss the Jasper engine API, Jasper XML report templates, and Jasper datasources. We'll also look at JasperAssistant, a visual report designer tool.

sant123
11th December 2004, 00:36
hi, AKshay,

I have implemented your idea, and it just works great!!

Now I want to go one step further and color the report, any ideas??? I looked at iText library there seems to be the chunk java api which lets us specify the color for the paragraph? I am palnning to try that.

Any thoughts.

Thanks
Sant

veyant
1st June 2005, 08:36
Hi ahulikavi ,

I tried to implement your idea. but i am facing problem in it.

as per your instructions, i have copied all 4 components and now when i give print on the new device(PDF), it gives me error "File can't be created!!! 127"

actually in debugging i found that while existing command

ret = shell("text2pdf.sh" & sh.string,0) it returns 127 value to ret.

however, i tried to run text2pdf file on command prompt directly and it gives following error.

pdf.sh[2]: CLASSPATH^M: this is not an identifier.

is java needed to be installed on the server. i have java1.4 installed on the server.

here is the code of pdf.sh which i modified.

CLASSPATH=/app/baan4c4/bse/tcd_email/PeBSClasses.zip:/app/baan4c4/bse/tcd_email/itext-1.3.jar:/usr/java14/bin
export CLASSPATH
java tcd_text2pdf $@


PeBSClasses.zip file is not available on the path =/app/baan4c4/bse/tcd_email/

actually this file doesn't exist. please advice why it is throwing 127 value in return.

thanks
Sandy

ahulikavi
2nd June 2005, 06:17
Hi Sandy,

pdf.sh is a script to ensure that classpath is set correctly, it needs to be modified based on your setup and where you placed the itext-1.03.jar file, please modify it accordingly. You can ignore other jars like PeBS..., these are not required for pdf.

create pdf.sh in a common directory accessible by all users, with owner bsp. For our setup this is /tcd_email in bse path, change it as required by you.

You will have to make same change in script...
seq.puts("cd your_directory_path_where_pdf.sh_is_present", fp)

Run the shell script directly and check if CLASSPATH is set.

As far as text2pdf.sh is concerned, ensure, that it has 777 permission.

Lets see if it works now ....

veyant1
16th June 2005, 06:48
hi,

i have modified the pdf.sh and txt2pdf.sh shell scripts accordingly. but it still gives me error "file can not be created!!!127".

However, i tried to run the text2pdf.sh at shell itself in AIX.

it activates pdf.sh and gives me error "vaja not found'.

however in pdf.sh on line 3 i am calling

java text2pdf $@

in AIX at /usr/java14/jre/bin , i have the java components available. i have declared these paths in CLASSPATH in pdf.sh.

here are the codes for pdf.sh and text2pdf.sh.


pdf.sh:
=======================

CLASSPATH = /app/baan4c4/bse/tcd_email/itext-1.3.jar:/usr/java14/jre/bin
export CLASSPATH
java tcd_text2pdf $@
=========================


txt2pdf,sh:
=======================================
cd /app/baan4c4/bse/tcd_email
pdf.sh $@
=======================================

please help as txt2pdf.sh is working fine but pdf.sh is not working fine.

however, need one more clarification.

there is a file tcd_text2pdf which is a java class should this file be with .class extension or not.

thanks
Sandeep Makan

bdittmar
1st July 2005, 17:10
Hello,
attached is an converter i use.
The shell script is built in converter and handles the java classes.
So you only need this converter and nothing else.

Regards

veyant1
9th July 2005, 12:23
Hi Akshay,

I have still not got the break-thru in implementation of this utility.
here is what i have done.

I created a new folder in $BSE with tcd_email name and placed text2pdf.sh,
pdf.sh, tcd_text2pdf class, i-text.jar and source code for i-text with all related class files in it.

I copied your script in baan and attached it with a device. now when i try to check the utility, i found that it is failing in conversion.

i have installed all source and related class files in the folder. but it gives error "file can't be created". it fails in execuing pdf.sh.

i checked it seprately on shell and found that while running tcd_text2pdf it gives error com/lowagie/text/ELEMENT java class not found.

however, i check the path and found that ELEment class is present in the folder.

any clue please. can you let me know some tip on it.

thanks
Sandeep Makan

bdittmar
14th July 2005, 17:24
Hi Akshay,

I have still not got the break-thru in implementation of this utility.
here is what i have done.

I created a new folder in $BSE with tcd_email name and placed text2pdf.sh,
pdf.sh, tcd_text2pdf class, i-text.jar and source code for i-text with all related class files in it.

I copied your script in baan and attached it with a device. now when i try to check the utility, i found that it is failing in conversion.

i have installed all source and related class files in the folder. but it gives error "file can't be created". it fails in execuing pdf.sh.

i checked it seprately on shell and found that while running tcd_text2pdf it gives error com/lowagie/text/ELEMENT java class not found.

however, i check the path and found that ELEment class is present in the folder.

any clue please. can you let me know some tip on it.

thanks
Sandeep Makan

Hello,
is the CLASSPATH set to the lowagie dir ?
set the absolute path /..../bse/..../.... to this dir.
the subdir structure must be the lowagie structure :

"classpath dir"
|
|----ant
|----com-----------|lowagie----|---bc++++++subdirs and files
| |---text+++++subdirs and files
|----META-INF |---tools

Regards

manojsharma
23rd August 2005, 07:28
Hi,

I am facing the same problem as Veyant is facing i.e. 127. Bernad, I have used your script also but its giving the same error.

Sant, how do you do that. Can anyone explain. Its urgent.

Thanx in advance

manojsharma
24th August 2005, 06:56
Hi Vamsi,

seeking for help from your side

ahulikavi
24th August 2005, 07:09
Hi,

Only things I can think of are accuracy of
1. CLASSPATH ( Should also include required itext JAR's)
2. File Permissions (Execute permissions on script files and classes)
3. Directory permissions
4. path_names as defined in your system ( also adjust accordingly in JAVA, BaaN Program script and OS Script files)

Hope this resolves your problem, since it is working at other places.

~Vamsi
24th August 2005, 07:41
Manoj,

Please accept my apologies in not being of much assistance in the matter. When it comes to Java I am a complete novice. It took me days of perseverence to figure out the classpath stuff when I was experimenting with http://www.antlr.org/

And from first looks at the problem it looks like a Classpath issue. Hopefully someone can help you with what needs to be set in the classpath variable. If you are researching yourself, I liked this page that comes very high in a google search - http://www.kevinboone.com/classpath.html

veyant
24th August 2005, 09:51
Hi,

Thanks to all for the support. The Program has been sorted out. it was not because of CLASS PATH at all. Actually, it was throwing some exception s while running convertion script due to footer & logo which is embedded in the script. after commenting the lines due to which exception msg was comming , problem has been resolnved and has been implemented successfully on Baan IVc4.

manojsharma
24th August 2005, 11:13
Thanx Akshay, Vamsi for your prompt reply. My problem solved. I was facing the same problem as veyant is facing

Thanx all.

Its a nice utility

deepaksachdeva
14th December 2005, 08:36
I had tried the same, but finding one error while executing print, can not read session or object tdapbpdf, i had made tdapbpdf as 3 gl prgram.

could any one help me out where i am lacking.

Regards
Deepak

mark_h
14th December 2005, 15:05
I think it should be otdapbpdf in the device program - try that.

deepaksachdeva
15th December 2005, 08:08
Hi Manoj,

could u please explain me the procedure, how u have mangaged to do this, we are also on the same platform as u are.

Thanks Mark, your suggession for otdapbpdf has worked, but i m facing the problem which manoj has faced earlier.

with Regards
Deepak

manojsharma
15th December 2005, 10:25
Hi Deepak,

I was facing problem in tcd_text2pdf file, just remove the lines which print logo and footer (e-mail etc.) from your script and it will work fine.

deepaksachdeva
15th December 2005, 11:13
I had removed the logo and footer, but while running the file by using java tcd_text2pdf <inputfile> <outputfile> <pagelength> it is throwing following error :

# java tcd_text2pdf pdf.sh deepak.pdf
The java class could not be loaded. java.lang.ClassFormatError: tcd_text2pdf (Ba
d magic number)

can someone help me out on this.

With Regards
Deepak

deepaksachdeva
16th February 2006, 12:21
hi akshay,

i m facing the problem while applying your solution, i had debugged it and found there is a problem in running the program.

could u pls help me out where i m wrong ?

Deepak

awassif
1st March 2006, 23:33
Hi Deepak,
I am having the same problem. When I execute from command line I get (Bad magic number) error:
# /usr/java14/bin/java -cp ./itext-1.3.jar tcd_text2pdf.class test test.pdf

Error:
====
The java class could not be loaded. java.lang.ClassFormatError: tcd_text2pdf (Bad magic number)

Any one can help would be appreciated.
- Ameen

camilla
21st March 2006, 09:54
Hi, I had the same error:
bad magic number
I search in Internet and I think that the problem is that the files are not compiled with the right version of java. Is it the problem? Can someone help me?

camilla
22nd March 2006, 08:58
Hi,
I compiled the java class tcd_text2pdf and everything now works fine!
You have to rename the file tcd_text2pdf in tcd_text2pdf.java; then you can directly use the file pdf.sh to compile it, only making two step:

1) modify the file pdh.sh:
instead of java you have to write:
javac tcd_text2pdf.java $@
2) download from the iText site the not compiled library, unzip the file and copy as bin the files on the unix folder where you have pdf.sh

then you have to execute pdh.sh, by the unix prompt:
./pdf.sh

That's all!

The compiler will create to you a file: tcd_text2pdf.class

Then you have to modify again the file pdf.sh and put it as before.

Ciao
Cri

mr_suleyman
14th November 2006, 09:28
It doesnt' work for me . I got some errors about JAVA code. I removed some lines from it.I compiled but I couldn't get PDF file.
WHO do you know all about it ?


Thanks ...

jmathew
26th June 2010, 14:16
Hi Akshay,
Can you please help us how we could implement the same with Baan LN 6.1 FP5. The operating system is AIX 5.3. and the database is Oracle 9.2. Please let us know the steps in details. Thanks in advance.


Hi,

3 components are required

1. Baan 3GL to convert report to ASCII and invoke shell scripts
2. Java Class to convert text to pdf
3. Shell scripts to invoke java class
4. Device Definition

1. Baan 3GL - Hope copyright is OK

||******************************************************************************
|* tdtcdpdf 0 VRC B40C L ive
|* Title : PDF
|* Author : Akshay Hulikavi
|* Date : 2004-02-09 [09:17]
|******************************************************************************
|* License :
|* Copyright 2004 by Akshay Hulikavi
|*
|* All Rights Reserved
|*
|* Permission to use, copy, modify, and distribute this software and its
|* documentation for any purpose and without fee is hereby granted,
|* provided that the above copyright notice appear in all copies and that
|* both that copyright notice and this permission notice appear in
|* supporting documentation.
|*
|* Akshay Hulikavi DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|* AND FITNESS, IN NO EVENT SHALL Akshay Hulikavi BE LIABLE FOR ANY
|* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
|* OR PERFORMANCE OF THIS SOFTWARE.
|******************************************************************************
#pragma used dll ottdllbw

long ret, fp, zoomed | general return variable
extern domain tcmcs.str215 input.file, pdf.file, local.file | input file - created by Baan
extern domain tcmcs.str215 argument, argu1, argu4, argu0, argu2, argu3
extern domain tcmcs.str215 argu5, argu6, argu7, argu8, argu9
extern string sh.string(1024), file.path(128), date.str(8), time.str(5), dat(12)

function main()
{
argu0 = argv$(0)
argu1 = argv$(1)
argu2 = argv$(2)
argu3 = argv$(3)
argu4 = argv$(4)
zoomed = false

dat = dte$()
date.str = dat(3;2) & "/" & dat(1;2)& "/" & dat(5;2)
time.str = dat(7;2) & ":" & dat(9;2)

if argu1 = "" and argu2= "" then | Called from another program not spooler
import("argu1", argu1)
import("argu2", argu2)
import("argu3", argu3)
import("argu4", argu4)
zoomed = true
endif

file.path = getcwd()
input.file = shiftl$(strip$(argu2))
ret = wait.and.activate("ttstpconv", argu1, input.file, "ASCII", "wt")


input.file = shiftl$(strip$(file.path))&"/"&shiftl$(strip$(input.file))
pdf.file = input.file&".pdf"
local.file = "c:\"&shiftl$(strip$(argu2))&".pdf"

sh.string = ""
sh.string = sh.string &" "&chr$(34)&input.file&chr$(34)
sh.string = sh.string &" "&chr$(34)&pdf.file&chr$(34)
sh.string = sh.string &" "&str$(spool.pg.length)
sh.string = sh.string &" "&chr$(34)&logname$&" on "& date.str & " at "& time.str& chr$(34)

fp=seq.open("text2pdf.sh","r")
if fp >= 1 then | text2pdf.sh file exists
ret = shell( "text2pdf.sh " & sh.string,0)
else
fp=seq.open("text2pdf.sh","wt")
seq.puts("cd /baanIVc/c4/bse/tcd_email", fp)
seq.puts("pdf.sh $@", fp)
seq.close(fp)
ret = shell( "chmod 777 text2pdf.sh",0)
ret = shell( "text2pdf.sh " & sh.string,0)
endif

if ret = 0 then
if zoomed = false then | Called from another program not report
ret = server2client(pdf.file,local.file, 0, 0) | Binary Mode Transfer
if ret = 0 then
ret = app_start(local.file,"","","","")
ret = seq.unlink(input.file)
ret = seq.unlink(pdf.file)
else
message("File could sent to client !!!!" & str$(ret)&local.file)
endif
endif
else
message("File could not be created !!!!" & str$(ret))
endif

}
|*********************************** end of script ****************************





2. the java class tcd_text2pdf

/*
Class to convert baan ascii report to pdf
Author : Akshay Hulikavi
Date : 10.02.2004

Requires : itext-x.jar - can be downloaded from www.lowagie.com/iText/
Source can be downloaded from www.lowagie.com/iText/

Usage : java tcd_text2pdf <inputfile> <outputfile.pdf> <PageLength, Default = 60>

*/
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;

public class tcd_text2pdf
{

public static void main(String[] args)
throws IOException, DocumentException
{
String resultStr = "", line=null, strFooter;
int lncnt=1, i, j, pgcnt=0, fntSize=8, lineSpacing, strLength=0;

//~ i = Integer.parseInt(args[2]);
j = Integer.valueOf(args[2]).intValue();
if (j <= 0)
j = 60; // Default page length

if(args.length < 2 ) {
System.out.println("Usage : java tcd_text2pdf <inputfile> <outputfile.pdf> <PageLength, Default = 60>");
return;
}

Reader in = new InputStreamReader(new FileInputStream(args[0]));
OutputStream os = new FileOutputStream(args[1]);
Document doc= new Document();
Image t_logo = Image.getInstance("logocolor.jpg");
t_logo.scalePercent(75); // scale image to 75%
java.io.BufferedReader br2 = new java.io.BufferedReader(in);

// get length of the longest line
try {
BufferedReader bufReader = new BufferedReader(new FileReader(args[0]));
while ((line=bufReader.readLine()) != null){
if (strLength < line.length())
strLength = line.length();
}
bufReader.close();

} catch (IOException e) {
System.err.println(e);
}



line = null;
i=1;

/*
Decide on Paper Size ,Orientation and Line Spacing based on max line length in report

*/
if (strLength <= 108)
i = 1 ;
if (strLength > 108 && strLength <= 127)
i = 2 ;
if (strLength > 127 && strLength <= 165)
i = 3 ;
if (strLength > 165 && strLength <= 176)
i = 4 ;
if (strLength > 176 && strLength <= 239)
i = 5;
if (strLength > 239)
i = 6 ;

switch (i) {
case 1:
doc = new Document(PageSize.A4, 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(535, 770); // image margin 60 so 595-60 and 842-60
break;
case 2:
doc = new Document(PageSize.A4, 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(535, 770);
break;
case 3:
doc = new Document(PageSize.A4.rotate(), 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(770, 535);
break;
case 4:
doc = new Document(PageSize.A4.rotate(), 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(770, 535);
break;
case 5:
doc = new Document(PageSize.LEDGER, 36, 18, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(1164, 732);
break;
case 6:
doc = new Document(PageSize.LEDGER, 36, 18, 72, 18);
fntSize = 7;
lineSpacing = 9;
t_logo.setAbsolutePosition(1164, 732);
break;
default:
doc = new Document(PageSize.A4, 36, 36, 72, 18);
fntSize = 8;
lineSpacing = fntSize;
t_logo.setAbsolutePosition(535, 770); // image margin 85 so 595-85 and 842-85
break;

}


// Add footer
strFooter = "Thermax Limited Chemical Division : 97-E General Block MIDC Bhosari Pune 411026";
strFooter +="\nPhone - 91-20-27120181, Fax - 91-20-27120206, URL - www.thermaxindia.com/chemical";
strFooter +="\nGenerated by (BaaN Login) : ";
strFooter +=args[3];

HeaderFooter footer = new HeaderFooter(new Phrase(strFooter,FontFactory.getFont(FontFactory.COURIER, 7)), false);

PdfWriter docWriter = null;
docWriter = PdfWriter.getInstance(doc, os);
doc.setFooter(footer);
docWriter.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.AllowPrinting);
doc.addTitle("BaaN Report");
doc.addSubject("Report Generated from BaaN System");
doc.addKeywords("Thermax Limited Chemical Division : 97-E General Block MIDC Bhosari Pune 411026");

doc.open();
doc.add(t_logo);
Paragraph p;
java.io.BufferedReader br = new java.io.BufferedReader(in);

try {
while ((line=br.readLine()) != null){
if (lncnt > j)
{
doc.newPage();
lncnt = 0;
}
p = new Paragraph(new Phrase(lineSpacing,line,FontFactory.getFont(FontFactory.COURIER, fntSize)));
doc.add(p);
lncnt++;
}
br.close();
} catch (IOException e) {
System.out.println("IO Exception on Buffered Read :" + e);
};

doc.close();
os.close();
}

}



3. Shell Scripts
a. text2pdf.sh in user home directory
cd /baanIVc/c4/bse/tcd_email
pdf.sh $@


b. pdf.sh in say $BSE or other convinient directory
CLASSPATH=.:/baanIVc/c4/bse/tcd_email/PeBSClasses.zip:/baanIVc/c4/bse/tcd_email/itext-1.01.jar:/usr/j2se/javamail/javamail-1.3/mail.
export CLASSPATH
java tcd_text2pdf $@



4. Device Definition
Also need to define device called say PDF as follows

Device type: Rewrite File
4GL Program : tdtcdpdf
Argument : %s
Page Length : 72



regards

lchleong
4th August 2011, 17:35
Great idea. It works perfectly. But how do I draw lines or tables that i had drawn in LN report into PDF. Apparently, all the horizontal lines had been converted into dashed lines instead of straight lines.