I have a WebService in Java (Using Apache Axis) that get's the id of a document and this call to JasperReports to create a PDF File (Report previously created in java app - server side), to create the report i'm using the methods: JasperManager.fillReport and JasperExportManager.exportReportToPdf. The last one returns an array of bytes. My webservice takes the array and encodes it into a Base64 String, PHP receives this string as response from the WebService.
I want to recreate the file in PHP, but i don't know exactly if this is possible. I'm trying to do this with the following snippet:
private function createFileFromString($stringWithFile){
header('Content-Description: File Transfer');
header("Content-Type: application/pdf");
header('Content-Disposition: attachment; filename=remesa.pdf');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_start();
ob_clean();
ob_flush();
flush();
$fp = file_put_contents("document.pdf", "w");
fwrite($fp, base64_decode($stringWithFile));
readfile($fp);
ob_get_contents();
fclose($fp);
exit();
}
The WebService Returns a String Like this:
JVBERi0xLjQKJeLjz9MKNCAwIG9iaiA8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VS R0IvU3VidHlwZS9JbWFnZS9CaXRzUGVyQ29tcG9uZW50IDgvV2lkdGggMjg0L0xlbmd0aCAzNjc0 L0hlaWdodCA1MC9GaWx0ZXIvRENURGVjb2RlPj5zdHJlYW0K/9j/4AAQSkZJRgABAgAAAQABAAD/ 2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0 Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAyARwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEA...
This string has the "PDF Header", begins like this:
%PDF-1.4 %âãÏÓ 4 0 obj <>stream ÿØÿà
When i try to download the file, it's size is around 4-5KB (and, the file is damaged), but the Response String is around 180KB.
Is this possible? What i'm doing wrong?
EDIT: I've read about unpack function, maybe this function can help me?
Thanks in advance