Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8090455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:43:41+00:00 2026-06-05T19:43:41+00:00

I have a WebService in Java (Using Apache Axis) that get’s the id of

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:43:44+00:00Added an answer on June 5, 2026 at 7:43 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one application in flex that is accessing the Java webservice using
I have implemented a Webservice using Apache CXF . The flow is this way
I have developed a simple Apache-Axis java web service using Eclipse IDE and now
We have to create a web service client using Apache CXF in Java. The
We have tried to create sample webservices helloworld in Java using Jersey and Tomcat
I have a legacy Java webservice based on Axis2. This webservice classes consist of:
I have a web service client using axis. It's using document/literal style and supposed
I have developed a webservice using Apache CXF ,which will be in production very
I've got a JAX-WS WebService that is using Spring 3 IOC. I have coded
I have an application that is using Apache CXF to communicate with Axis2 web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.