0

hi am a c# programmer with basic knowledge on php. Currently am working on a php assignment which requires a pdf to be downloaded. i tried downloading through webservice but it does not work. Am able to get the byte array of the concerned PDF. Is it possible to convert it in to a PDF file. Please help thank you.

my php code:

   <?php
    require_once("nuSOAP/lib/nusoap.php");
    $client = new nusoap_client('http://localhost/WS-PDF/Fill_Pdf.asmx?wsdl',true);
    $soapaction = "http://tempuri.org/GetPdf";
    $namespace= "http://tempuri.org/";
    $client->soap_defencoding = 'UTF-8';
    $params = array('test' => "PDF");
    $result = $client->call('GetPdf',$params,$namespace,$soapaction);
    print_r(array_values($result));
    $err = $client->getError();
    if ($err) {
        exit();
    }
?>
2
  • A file is just a stream of bytes. You should be able to save that array to a disk file and open it as a PDF. Provided, of course, that the bytes you received represent a valid PDF file. Commented Nov 8, 2012 at 15:11
  • @JimMischel can you please provide me some example code Commented Nov 8, 2012 at 15:49

1 Answer 1

1

if you assign the byte's to a variable then tell the browser to output a pdf you should get the pdf back. In the example below I use the variable $pdf.

header("Content-type: application/pdf");
header("Content-Length: $length");
header("Content-Disposition: inline; filename='$filename'");
echo $pdf;
Sign up to request clarification or add additional context in comments.

3 Comments

o right thats the length of the file, you can use this function to get that information filesize();
it seems to return the file size.. should i be using the array variable instead of file name to get size? since am creating a new file
if its returning exactly the same file then i would just use the file location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.