Baanboard.com

Baanboard.com (http://www.baanboard.com/baanboard/index.php)
-   Code & Utilities (http://www.baanboard.com/baanboard/forumdisplay.php?f=33)
-   -   DEV: Create vanilla PDF files from Baan with Open Source components (http://www.baanboard.com/baanboard/showthread.php?t=590)

~Vamsi 8th December 2001 01:39

DEV: Create vanilla PDF files from Baan with Open Source components
 
1 Attachment(s)
Extract of the file...

Code:

|******************************************************************************
| Notes for posting on Baanboard.com
| This was posted initially to baanfans.com in August 2000.
| Joy Conner's posting for this functionality has prompted me to look it up
| in my archives.
|
| It would be nice if someone irons out the logic to be generic for both
| Unix and NT. As usual my Achille's heel continues to be documentation.
| Will some kind soul write documentation for this. Also possible is to combine
| this script with the one posted by Mark Holland at
| http://www.baanboard.com/baanboard/s...=&threadid=513
|
| ~Vamsi
| 7th December, 2001
|******************************************************************************

                        long            ret
                        string          tmp.file(1024)
                        string          pdf.tmp.file(1024)

        #pragma used dll ottdllbw
        #pragma used dll ottdllinputstr

function main()
{
                        long            i
                domain  tcmcs.str100    local.path

        | Convert the report file
        tmp.file = creat.tmp.file$( bse.tmp.dir$() )
        wait.and.activate("ttstpconv", argv$(1), tmp.file, argv$(3), argv$(4))
        | ensure argv$(3) has a value "POSTSCRIPT"


mark_h 9th December 2001 00:19

How about this
 
1 Attachment(s)
Vamsi,

(1) Thanks Vamsi. You gave a interesting idea. In this version you select the printer with a version of this script and THEN it launches a sub-session which asks if you want to create a PDF file, launch word or excel. I am sorry to say it is still only a UNIX version. Hopefully we can add other useful conversions. Maybe a Email section or a text session.

(2) Is there a way to tell if you on NT client or server? Is that what the fix slash is for? If so a check could be built in that would fix the slashes for NT.

(3) I downloaded Ghostscript and tested this, but since I do not know ghostscript I think something is wrong with the format. Hopefully you or someone else can fix this. Check the PDF file in the attachment.

(4) Hope new documentation is enough for others to get started.

Mark

PS: Do not hold it against me if I forgot to attach something. I had to come to work, so I took a few hours and rushed through this.

Teaser of the script:
Code:

|******************************************************************************
|* Title        : Create PDF Output from Baan
|* Author        : MohanaVamsi Potluru <vamsi@who.net>
|* Date                : August 02, 2000 at 14:09:13 EST
|* Requirements : Ghostscript,MS word, MS excel.
|*                  Location of word and excel and ghostscript in your client path.
|*                  Domain Created tugs with values
|*                        tugs.loc  = gswin32c.exe
|*                        tugs.excel = excel.exe
|*                        tugs.word  = word.exe
|******************************************************************************
|* Script Type        : Library
|* Description        : Creates PDF,word or excel
|* Category        : Output Management
|* License        :
|* Platform    : UNIX
|* Copyright 2000- by MohanaVamsi Potluru
|*
|* 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.
|*
|* MohanaVamsi Potluru and Baanboard.com DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|* AND FITNESS, IN NO EVENT SHALL MohanaVamsi Potluru nor Baanboard.com 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.
|******************************************************************************
|*
|******************************************************************************
|* This is just a rev 0.1 - almost nothing more than an idea.
|* Download and install Ghostscript http://www.cs.wisc.edu/~ghost/
|* Initial revision - MohanaVamsi Potluru
|* based on the Wrapper Program - Kevin Brock
|* Modification by Mark Holland
|*
        extern        domain        tgyenox        opt.pdf                |Create PDF file.
        extern        domain        tgyenox        opt.word        |Start word with file.
        extern        domain        tgyenox        opt.excel        |Start excel with file.

| Variables need for the conversion program.
        string        tmp.file(1024)                | Temporary file name.
        string        local.path(1024)        | Location on client for report.
        long        ret                        | Return code.
        string        appl(132)                | Application to start.
        long        app_id                        | Application id.
        string        start(1024)                | Parameter for the app_start
                                        | function which has application
                                        | and file to use.
        string app1(132)                | Used for RDI domain
        long fval                        | Used for RDI Domain

        #pragma used dll ottdllbw
        #pragma used dll ottdllinputstr

function main()
{
| Export variables for sub-session.
        export("opt.pdf",opt.pdf)
        export("opt.excel",opt.excel)
        export("opt.excel",opt.word)
| Launch sub-system to find out what they want to do.       
        zoom.to$("tuddc9130s000",z.session,"","",0)
| Import variables.       
        import("opt.pdf",opt.pdf)
        import("opt.word",opt.word)
        import("opt.excel",opt.excel)
       
| Go do what they want.       
        if(opt.pdf = tgyenox.yes) then
                create_pdf()
        endif
        if(opt.word = tgyenox.yes) then
                create_word()
        endif
        if(opt.excel = tgyenox.yes) then
                create_excel()
        endif
}


mark_h 18th December 2001 22:35

Another Version
 
1 Attachment(s)
This new version contains a section to launch the display. I also tweaked the GS section to work for our site - it now launches acrobat.

Thanks to Vamsi for the original script and to Gordon for providing me with info on calling the display.

Mark

Code:

|******************************************************************************
|* Title        : Create PDF Output from Baan
|* Author        : MohanaVamsi Potluru <vamsi@who.net>
|* Date                : August 02, 2000 at 14:09:13 EST
|* Requirements : Ghostscript,MS word, MS excel.
|*                  Location of word, excel, ghostscript and acrobat
|*                  in your clients path.
|*                  Domain Created tugs with values
|*                        tugs.loc  = gswin32c.exe
|*                        tugs.excel = excel.exe
|*                        tugs.word  = word.exe
|*                        tugs.acrobat = acrord32.exe
|******************************************************************************
|* Script Type        : Library
|* Description        : Creates PDF,word or excel
|* Category        : Output Management
|* License        :
|* Platform    : UNIX
|* Copyright 2000- by MohanaVamsi Potluru
|*
|* 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.
|*
|* MohanaVamsi Potluru and Baanboard.com DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|* AND FITNESS, IN NO EVENT SHALL MohanaVamsi Potluru nor Baanboard.com 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.
|******************************************************************************
|*
|******************************************************************************
|* This is just a rev 0.1 - almost nothing more than an idea.
|* Download and install Ghostscript http://www.cs.wisc.edu/~ghost/
|* Initial revision - MohanaVamsi Potluru
|* based on the Wrapper Program - Kevin Brock
|* Modification by Mark Holland
|*
        extern        domain        tgyenox        opt.pdf                |Create PDF file.
        extern        domain        tgyenox        opt.word        |Start word with file.
        extern        domain        tgyenox        opt.excel        |Start excel with file.
        extern        domain        tgyenox        opt.display        |Start the display.

| Variables need for the conversion program.
        string        tmp.file(1024)                | Temporary file name.
        string        local.path(1024)        | Location on client for report.
        long        ret                        | Return code.
        string        appl(132)                | Application to start.
        long        app_id                        | Application id.
        string        start(1024)                | Parameter for the app_start
                                        | function which has application
                                        | and file to use.
        string app1(132)                | Used for RDI domain
        long fval                        | Used for RDI Domain

        #pragma used dll ottdllbw
        #pragma used dll ottdllinputstr
        #pragma used dll ottdlldisplay
function main()
{
| Export variables for sub-session.
        export("opt.pdf",opt.pdf)
        export("opt.excel",opt.excel)
        export("opt.excel",opt.word)
        export("opt.display",opt.display)
| Launch sub-system to find out what they want to do.       
        zoom.to$("tuddc9130s000",z.session,"","",0)
| Import variables.       
        import("opt.pdf",opt.pdf)
        import("opt.word",opt.word)
        import("opt.excel",opt.excel)
        import("opt.display",opt.display)
       
| Go do what they want.       
        if(opt.pdf = tgyenox.yes) then
                create_pdf()
        endif
        if(opt.word = tgyenox.yes) then
                create_word()
        endif
        if(opt.excel = tgyenox.yes) then
                create_excel()
        endif
        if(opt.display = tgyenox.yes)then
                create_display()
        endif
}


~Vamsi 14th August 2002 01:16

Ajitdon wrote:
Quote:

Hi Vamsi,

I have used your solution to print in PDF and tweaked the hard coded portions
to suit my environment.

For an intial test, I have hard coded the start_app(.... as follows:

app_id = app_start(start, "","","","")
WHERE : start = "AcroRd32.exe" & " " & "c:\temp\ajit.ps" .

ajit.ps is the file being created in c:\temp.

When I run the program in debug , it starts acrobat but gives me the error
message -
"There was an error opening this document. A file read error has occured".

Would you know why I am getting this error?

Thanks for your time,
Ajit.
Ajit,

Open a command prompt on your local pc and try the command. Whatever works on your local pc is what you want to put in the Baan script. At first looks, I believe you are trying to open a postscript file in Adobe Acrobat Reader. To my knowledge this is not supported. Acrobat reader only supports pdf files.

ajitdon 21st August 2002 20:10

Error : File not found.
 
Vamsi, Mark:

I am trying to print in PDF using Mark's version(pdfvers31.zip) for UNIX as a starting point.

ENVIRONMENT:
Baan Server - Unix.
Client - Windows 2000
Ghostscript (gs653w32.exe) present in d:\baan\tmp

DEVICE MANAGER SETUP:
Device - PDFIT
Type - Rewrite
Locale - ISO-8859-1
4GL Program - otccomconv4
Argument - POSTSCRIPT
Path - d:\baan\tmp\ajit

PROBLEM:

It seems Ghostwriter is not creating the ajit.pdf file.
The ajit.ps file is being created in d:\baan\tmp
However, it seems that the ajit.pdf file is not being created by Ghostwriter.

I am reproducing the code for function create.pdf() below :

|***************

function create_pdf()
{
long fp1 | File to create PDF File.
string tmp.file1(1024)



| Convert file.
convert_file("POSTSCRIPT")
local.path = local.path & ".pdf"


|Create some temp files.
tmp.file1 = creat.tmp.file$( bse.tmp.dir$() )

|Open the temp files.
fp1 = seq.open(tmp.file1, "w")

| Put Ghostwriter stuff
seq.puts("-q -dNOPAUSE -dBATCH -sDEVICE#pdfwrite", fp1)
seq.puts("-sOutputFile#"&local.path, fp1)
seq.puts("-q -dNOPAUSE -dBATCH -sDEVICE#pdfwrite -c save pop -sOutputFile#"&local.path & " -f " & local.path(1;(len(local.path)-3))&"ps", fp1)

| Close the files.
seq.close(fp1)

| Move these two files to the c drive.
send.report.to.client(tmp.file1, "d:\BAAN\tmp\_.gs1")

|Move the postscript file to the client.
server2client(tmp.file, local.path(1;(len(local.path)-3))&"ps",1)
| Setup filename to start.
ret = rdi.domain.enum.value( "tugs",1,"2",app1,appl,fval)
appl = "d:\BAAN\tmp\gs653w32.exe"

ret = app_start(appl & " @_.gs1", "d:\BAAN\tmp.ps","","","")
| Make sure GS is completed before launching Acrobat.
if ret >= 0 then
| not equals
while app_status(ret) <> 0
suspend(500)
endwhile
else
message("Error %d encountered while starting Ghostscript", (-1 * ret))
endif
|Delete old temp file.
ret = seq.unlink(tmp.file)
ret = seq.unlink(tmp.file1)

| Start adobe acrobat
appl = "AcroRd32.exe"
ret = rdi.domain.enum.value( "tugs",4,"2",app1,appl,fval)
start= appl & " " & local.path

| Start the aplication.
start_app()

}

|**********

The problem seems to be within the code that is calling the ghostwriter.
I have tried two variations:
(1) | Setup filename to start.
ret = rdi.domain.enum.value( "tugs",1,"2",app1,appl,fval)
appl = "d:\BAAN\tmp\gs653w32.exe"

ret = app_start(appl & " @_.gs1", "d:\BAAN\tmp","","","")

When using this, at this command the ghostwriter install pop up starts and I have to go through the complete ghostwriter installation everytime - still no ajit.pdf file is created.

(2) | Setup filename to start.
ret = rdi.domain.enum.value( "tugs",1,"2",app1,appl,fval)
appl = "d:\BAAN\tmp\gs653w32.exe"

ret = app_start(appl & " @_.gs1", "d:\BAAN\tmp.ps","","","")

When using this, at this command, nothing seems to happen. The debugger just goes through it very quickly. Again, no ajit.pdf file is created.

|***************
In both cases, at the command that launches acrobat,

[[ app_id = app_start(start,"","","","")
Where: start = "AcroRd32.exe d:\baan\tmp\ajit.pdf" ]]

the acrobat reader application is launched but it gives a pop up error message - " There was an error opening this document. The file does not exist."

It seems because of some problem with the ghostwriter, the ajit.pdf file is not being created.

Please advise.

Thanks for your time,
Ajit.

Eddie Monster 21st August 2002 20:57

Maybe I'm wrong...
 
Ajit,

You have a line of code in you post:

ret = app_start(appl & " @_.gs1", "d:\BAAN\tmp.ps","","","")
| Make sure GS is completed before launching Acrobat.


Shouldn't it read:

ret = app_start(appl & " @_.gs1", "d:\BAAN\tmp","","","")
| Make sure GS is completed before launching Acrobat.

Wasn't quite sure... I was just comparing your code to code I modified to get it to work...

Also under Control Panel in windows I have set up the following System path: D:\gs\gs7.03\bin

so that all I have to call is:

appl = "gswin32c.exe"
ret = app_start(appl & " @_.gs1", "c:\temp","","","")

to run the Ghostwrite and not have to go through the entire install.

Hope this helps...

ajitdon 21st August 2002 22:13

Hi Eddie,

Thanks a lot!
That was the problem.

Now it works for me!.

However, that is the problem - it only works for me.

Will I have to install ghostrscript on all PCs that should be able to use it? Or is their an easier way to install the ghostwriter on the server (Unix for us?) or can we have ghostwriter on

Has anyone tried this?

Thanks again - Eddie:)
Ajit.

Eddie Monster 21st August 2002 22:40

Network version...
 
My company only has a few finance people actually printing .pdf reports from Baan to our Intranet. Then all other management review these reports so we don't need many people printing in PDF format. Each of these people have Ghostwriter installed on their individual PC.

However, I believe that GhostWriter has a network version that could be set up so that all networked users could access it. We were going to look at it when we have time, but you know how that goes...

~Vamsi 21st August 2002 23:39

Folks,

I released the code with it implemented on the local pc because I do not have a business need for it to be present on the server :). Install Ghostscript on the Baan server (it is available for all flavours of unix and windoze) and make changes to create the pdf on the server instead of the client.

Good luck

Francesco 30th August 2002 09:45

This has bugged me long enough
 
I switched version 7.05 for 6.53 and it compiled for me (with minor problems).

Solaris users beware.

Francesco 6th September 2002 20:28

success!
 
I finally managed to get a working concept of the Unix installation.

First of all, installing ghostscript on Solaris is no picnic. It took me several days to get it to compile and then several more to get it to compile properly.
Maybe it would have helped if I actually knew what I was doing? ;)

I still have some issues with the way gs is producing its PDF files, probably due to incorrect fonts or stuff...anybody here with extensive adobe knowledge?
But I'll get that fixed down the road.

Then Mark's code wouldn't run for me at all, vamsi's code wouldn't produce any results, so I ended up with a very stripped down version that looks like this:

Code:

        domain  tcmcs.str100    local.path

        | Convert the report file
        tmp.file = creat.tmp.file$( bse.tmp.dir$() )
        wait.and.activate("ttstpconv", argv$(1), tmp.file, "POSTSCRIPT", argv$(4))

        local.path = argv$(2)
        | make sure the final file has a valid extension
        if rpos(toupper$(local.path), ".PDF") <> (len(local.path) - 3) then
                local.path = local.path & ".pdf"
        endif

        gs.path = "/opt/apps/baan/gs/6.53/bin/gs"
        gs.options = "-dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=- -dBATCH " & tmp.file & " > " & local.path
        gs.command = gs.path & " " & gs.options

|        ret = run.prog(gs.path, gs.options, RP_WAIT)
        ret = shell( gs.command, SHELL_MWINDOW )
        ret = seq.unlink(tmp.file)

Notice I had to use the shell() function instead of the run.prog() to get it to work (thanks for the tip, Prashanth). If anybody has any idea why run.prog wouldn't work as entered in the above code, I'd like to hear it.

Also, both Vamsi's and Mark's versions have the script type 'library' in the code. This needs to be 3GL (thank you vamsi for this clarification).

I will have to incorporate some more code to move the pdf files to the right destination based on what user, etc. But this is the gest of it.

Remind me to attach the Solaris make file so other poor souls don't have to go through this part of the struggle.

mark_h 6th September 2002 20:45

Glad you got it working
 
Francesco,

Glad you got it working. As for the run.prog - I wonder if it would have the same problem I had with the sed program. Had to put some quotes around the commands. Below worked for me and I wonder if it could be something like that in this case. Just a guess.

Code:


sed.cmd = sprintf$("-c %ssed -f %s %s>%s%s",
                chr$(34), tmp.sed.file, return.file, tmp.sed.output.file, chr$(34))
status = run.prog("sh",sed.cmd,RP_WAIT)

Thanks for your contribution.

Mark

Francesco 10th September 2002 18:56

As promised
 
1 Attachment(s)
Here is the makefile that ended up working for me.
Of course it will need adjustments for any particular environment, but it should give some hints to people trying to install ghostscript on Solaris.

good luck.

therese 18th September 2002 10:17

I used the program of Vamsi. I didn't encountered any error. There is a pdf file created but when I try to open the pdf file, the error "There was an error opening this document. The file cannot be open because it has no pages".

What seems to be the problem?

Please help.

Thanks,
Therese

therese 18th September 2002 10:44

Hi again,

Please ignore my previous message. I already solve the problem.

I have created pdf file without any error but when I check the report output, it double the pages. The file must supposed to have only one page but it created another page (page 2) with same data.

Thanks.


All times are GMT +2. The time now is 23:33.


vB.Sponsors
©2001-2017 - Baanboard.com - Baanforums.com