Recreate PDF File From Java To PHP

后端 未结 1 1920
情深已故
情深已故 2021-01-21 22:55

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 - ser

相关标签:
1条回答
  • 2021-01-21 23:23

    Ok, i solved it. I have, basically, two errors:

    1. From Java: The class that i've used to encode the content of PDF file (org.w3c.tools.codec.Base64Encoder) was corrupting the String with the file content, instead of this class, i've switched to Apache Axis Tools (org.apache.axis.encoding.Base64). I say this because i've compared the content of a PDF generated with my Java App and the content returned from the WebService and the last one is a bit smaller.

    2. From PHP: Building The File: In this part i've trying to do this:

    $fp = file_put_contents("document.pdf", "w");
    fwrite($fp, base64_decode($stringWithFile));
    readfile($fp);
    

    But, only with file_put_contents i've done writing the content to a PDF File, fwrite it wasn't necessarily at this point. I'm generating the pdf with this snippet:

    private function createFileFromString($stringWithFile){
        header('Content-Description: File Transfer');
        header("Content-Type: application/pdf");
        header('Content-Disposition: attachment; filename=document.pdf');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        flush();
        file_put_contents("document.pdf", base64_decode($stringWithFile));
        readfile("document.pdf");
        exit();
    }
    

    I hope that this answer helps to everyone.

    0 讨论(0)
提交回复
热议问题