0

Forgive my lack of familiarity with SOAP. I've been tasked with saving multiple pdf files that are provided to us through the SOAP API of a third party vendor to our webserver. The result from the vendor's API is provided as

    xsd:element name="content" type="xsd:base64Binary" 

I've got it to the point where I can output the pdf to the browser with php without issue with the following code:

    $document=$vendor_soap_client->getPersonDocument($pid);  
    $filename= $name . $extension;  
    header("Content-type: " . $document->mime);  
    header("Content-Disposition: attachment; filename=" . $name. $extension);  
    print($document->content);

I assumed from the base64Binary type of the result, that I needed to base64_decode. That just left my output with a bunch of symbols. I tried converting the result to a string and then saving to a pdf. That got me closer in that at least the text of the pdf was written to the file, but the original formatting was not, which was to be expected. So, how can I grab the original pdf from the API and save it to our own webserver? As an FYI - yes, the content of the pdfs IS ours and we are allowed to download it. I'm not trying anything shifty here. I just am lost as how to go from the above to having a pdf on our servers. Now, the next obvious choice is to do the above, and save each pdf one at a time. Doable, but onerous.

UPDATE: XSD:

    <xsd:complexType name="DocumentObject">
  <xsd:all>  
   <xsd:element name="student_document_id" type="xsd:string" nillable="true"/>  
   <xsd:element name="document_label" type="xsd:string" nillable="true"/>
   <xsd:element name="document_type" type="xsd:string" nillable="true"/>
   <xsd:element name="mime" type="xsd:string" nillable="true"/>
   <xsd:element name="size" type="xsd:integer" nillable="true"/>
   <xsd:element name="content" type="xsd:base64Binary" nillable="true"/>
   <xsd:element name="private" type="xsd:boolean" nillable="false"/>
   <xsd:element name="created" type="xsd:dateTime" nillable="false"/>
   <xsd:element name="modified" type="xsd:dateTime" nillable="false"/>
   <xsd:element name="approved" type="xsd:boolean" nillable="false"/>
   <xsd:element name="link" type="xsd:string" nillable="true"/>
   <xsd:element name="student_id" type="xsd:string" nillable="true"/>
   <xsd:element name="match_context" type="xsd:string" nillable="true"/>
   <xsd:element name="reviewed_date" type="xsd:dateTime" nillable="true"/>
   <xsd:element name="review_status" type="xsd:string" nillable="true"/>
   <xsd:element name="review_comment" type="xsd:string" nillable="true"/>
   <xsd:element name="reviewed_by" type="xsd:string" nillable="true"/>
   <xsd:element name="resubmitted" type="xsd:boolean" nillable="true"/>
  </xsd:all>  

Is that what you were asking for?

The results of doing the file_put_contents looks like so:

%PDF-1.5 %µµµµ 1 0 obj <>>> endobj 2 0 obj <> endobj 3 0 obj <>/XObject<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]

/Annots[ 9 0 R 12 0 R] /MediaBox[ 0 0 612 792] /Contents 4 0 R/Group<>/Tabs/S/StructParents 0>> endobj 4 0 obj <> stream xœµ=k“ÛÆ‘ßU¥ÿ€IŠL¼æ çÚº•Vr”xíÄR’«RîÍ…visÞ%¥(u?þ¦{0/

UPDATE: Well, it turns out user error was the big problem here. Doing an fopen and fwrite did the trick, which is the very first thing I had tried. However, I was using WinScp to view the files on the server, to make sure they were being written...but I also didn't think about the consequences of using it to actually VIEW the pdfs!! So, they were correct all along. Thanks so much for the responses though!

AAGC
  • 3
  • 3

1 Answers1

2

It looks like $document->content is just the raw file data - not encoded or anything. If that's the case, this should do the trick:

file_put_contents($filename, $document->content);

If not, can you provide a link to the full XSD for the web service?

George Brighton
  • 5,131
  • 9
  • 27
  • 36
  • Sadly no. That also produces junk. You want this? – AAGC Sep 12 '13 at 19:22
  • Sorry...new user. I meant to add the code, not end the comment like that. – AAGC Sep 12 '13 at 19:23
  • 1
    Thanks for the XSD; unfortunately it isn't really helpful on reflection. Are you using SoapClient? It decodes base64 for you, so I'm a little puzzled: http://stackoverflow.com/questions/16893934/soap-base64binary-data-in-php – George Brighton Sep 12 '13 at 23:54
  • The vendor does have a SoapClient that we make a call to. I had seen that post before as I was researching. I'm sure I'm missing something obvious because I'm not familiar with SOAP. – AAGC Sep 13 '13 at 12:19