cancel
Showing results for 
Search instead for 
Did you mean: 

Download spool as PDF with PHP problem

0 Kudos

Hi all,

I've written a php program where a user can select a spool job and download it as a pdf file using PHP.

If they download OTF's (using CONVERT_OTFSPOOLJOB_2_PDF)), it works superb. Never had a problem.

If they download ABAP spool lists (using CONVERT_ABAPSPOOLJOB_2_PDF) they get an error opening the PDF document in Acrobat reader.

"An unrecognized token 'x,xxx' was found", where x is a number.

It probably has something to do with the ',' needs to be an '.' (or vice versa), I think.

Anyone know how this can be solved?

Many Thanks in advance.

Here's my php code if someone is interested.

$rfc = saprfc_open ($login);

if ( !$rfc )

{

echo "RFC connection failed with error:".saprfc_error();

exit;

}

saprfc_set_trace( $rfc, false );

if( $_GET['RQDOCTYPE'] == "OTF" )

{

$fce = saprfc_function_discover($rfc, "Z_CONVERT_OTFSPOOLJOB_2_PDF", true);

}

else

{

$fce = saprfc_function_discover($rfc, "Z_CONVERT_ABAPSPOOLJOB_2_PDF", true);

}

if ( !$fce )

{

echo "Discovering interface of function module Z_CONVERT_xxxSPOOLJOB_2_PDF failed";

exit;

}

saprfc_import( $fce, "SRC_SPOOLID", $_GET['RQIDENT'] );

saprfc_import( $fce, "NO_DIALOG", " " );

saprfc_table_init ($fce,"PDF");

$rc = saprfc_call_and_receive ($fce);

if ($rfc_rc != SAPRFC_OK)

{

if ($rfc == SAPRFC_EXCEPTION )

echo ("Exception raised: ".saprfc_exception($fce));

else

echo ("Call error: ".saprfc_error($fce));

exit;

}

$lines = "";

$rowcount = saprfc_table_rows ($fce,"PDF");

for( $index = 1; $index <= $rowcount; $index++ )

{

$line = saprfc_table_read( $fce, "PDF", $index );

$lines .= $line['TDFORMAT'].$line['TDLINE'];

}

saprfc_function_free($fce);

saprfc_close($rfc);

// Stream PDF to browser or download

if(ob_get_contents())

echo 'Some data has already been output, can\'t send PDF file';

if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))

header('Content-Type: application/force-download');

else

header('Content-Type: application/octet-stream');

if(headers_sent())

echo 'Some data has already been output to browser, can\'t send PDF file';

header('Content-Length: '.strlen($lines));

header('Content-disposition: attachment; filename="spool-'.$_GET['RQIDENT'].'.pdf"');

echo $lines;

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi guys,

I've allready came up with a solution.

It had indeed something to do with the 'comma'-chars which in fact need to be 'dot'-chars (probably due to different locale settings on the SAP-server and the Webserver).

I've solved it by doing a str_replace( ',', '.', $lines );

The str_replace() only has to be done between the "stream" and "endstream" blocks within the PDF, otherwise the PDF will be corrupted!

Also do it only on PDF's created with FM CONVERT_ABAPSPOOLJOB_2_PDF and not with PDF's converted with FM CONVERT_OTFSPOOLJOB_2_PDF!

But... I'm still intrested on perhaps some more "subtle" solutions, although my solution works as a charm.

Many thanks.

Kind regards.