cancel
Showing results for 
Search instead for 
Did you mean: 

Using Preview when printing from SAP

erik_hendrix
Explorer
0 Kudos

Just starting to use SAP Java GUI on the Mac and one of the 1st items I discovered was the inflexibility for printing. I would need to define the printer in the preferences of the SAP Java GUI and then anytime I would print it would just go to that printer.

Problem with this is that sometimes I work from within the office, and sometimes from home with as a result that my printer changes.

When on Windows, I also often performed a print from within SAP but then selected the Adobe PDF printer instead so that I had a resulting PDF file.

What I thus really wanted was for anytime I print from SAPGUI to the local printer to get a print dialog just like it does on Windows. I checked around but could not find anything to replace the lp command with on Mac that would then provide this. As a work-around I developed the following small script instead. Now instead of just printing, the print-out will be shown in Preview as a PDF. From here I can then save it as a PDF, print it, mail it, .... anything else one can do with Preview.

This is not the exact solution I wanted as I wanted to just get a print dialog; but this gets me a lot closer to it.

See next post (hopefully as I am having issues posting) for script & steps.

Accepted Solutions (0)

Answers (1)

Answers (1)

erik_hendrix
Explorer
0 Kudos

Instructions:

First, make sure that printing is setup for SAP Java GUI. There is sufficient information out there but main items are that the printer within SAP is defined with method G and that the device type os POST2 (for postscript). Also ensure that under output attributes Color printer is checked.

Next create the script. I put it in the /Applications/SAP Clients folder but it can be put anywhere you like. You can name the script however you like, I named it SAPLPD.

First thing the script does is converting the postscript file to PDF and storing it in the user's temporary directory. It adds the timestamp to the filename just to ensure there are no duplicated. It then opens the PDF file using Preview. It will wait for 1 second after which it will remove the file created.

It also looks that all the files in this temporary directory are automatically removed by OSX, so even should the file not have been removed; on next logout (I think) the file will be removed anyhow.

Script:

The script is:

#!/bin/bash

timestmp=`date +%Y%m%d%H%M%S`
/usr/bin/pstopdf -i -o $TMPDIR/sap_print_$timestmp_$$.pdf
open -a /Applications/Preview.app $TMPDIR/sap_print_$timestmp_$$.pdf
sleep 1
rm $TMPDIR/sap_print_$timestmp_$$.pdf

Once you have created the script it needs to be made executable. Do this by open the Terminal, changing to the location where you saved the script and entering the command:

chmod a+x (script name)

So in my case I would have entered the following 2 commands in Terminal:

cd "/Application/SAP Clients"

chmod a+x SAPLPD

Last but not least is changing the command the SAP Java GUI uses for printing. Go into preferences for the SAP Java GUI and go to the Printing section (under Desktop). There for the Print Spooler entry which is currently set to /usr/bin/lp you change that to the script. So for me I have:

/Applications/SAP Clients/SAPLPD

Easiest way to do this is by using the Browse button and then going to where the script is. No parameters are passed to the script so everything else can be removed. What I have is exactly what I show a few lines above.

And that is it, when now printing from SAP it opens the print-out in Preview and from there I can select my printer options etc.

Use of the script is on your own risk. It works for me but there is no guarantee that it will work for you.

Would love to hear about any other options.

RMW
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Erik,

very nice approach.

Two comments:

Preview is supposed to also understand postscript, so why converting first to PDF?

Also you could call Preview synchronously and do not need to add some sleep time.

/Applications/Preview.app/Contents/MacOS/Preview $TMPDIR/sap_print_$timestmp_$$.pdf 

instead of


open -a /Applications/Preview.app $TMPDIR/sap_print_$timestmp_$$.pdf
sleep 1

Just my two cents.

Best regards

Rolf-Martin

erik_hendrix
Explorer
0 Kudos

I tried calling Preview directly and having it read from STDIN but it is not working. I tried using:

open -f -a /Applications/Preview.app

Preview opens but no document; I think that Preview does not like reading a postscript file from STDIN or there is something with the SAP Postscript files that Preview just does not like.

I made a few small modifications now to the script:

1) 1st parsing it as PDF but then providing it to Preview through STDIN. This means that I can remove the temporary created file immediately and let Preview handle the temporary file it creates. Might be more safe for big documents as I think Preview might then need to keep the file around.

2) If the 1st parameter provided by the script is PDF then it will open preview directly. For this, create the printer in SAP as a PDF printer instead, then in the SAPJava Gui Preferences -> Printing, add PDF to the command for printing.

Here is the adjusted script:

#!/bin/bash

if "$1" = "PDF" then
   open -f -a /Applications/Preview.app
else
   timestmp=`date +%Y%m%d%H%M%S`
   /usr/bin/pstopdf -i -o $TMPDIR/sap_print_$timestmp_$$.pdf
   cat $TMPDIR/sap_print_$timestmp_$$.pdf | open -f -a /Applications/Preview.app
   rm $TMPDIR/sap_print_$timestmp_$$.pdf
fi

Tested and it works.

If anyone knows any parameters that the Java GUI could pass on (such as name of the local printer as defined in SAP) then this could be adjusted a bit more so that it can take that to determine if the provided input is a PDF or PS file.

Edited by: Erik Hendrix on Aug 8, 2011 11:53 AM

Former Member
0 Kudos

Hello Erik,

i also have the same problem, i've made all like you wrote but it doesn't work...

Do you have other ideas, how to fix it?

Best regards

Mario