I use SOAP like webservice. It's work nice. Now I want to get pdf file from server. I receive a array

    ('filename'=>'test.pdf', 'mimetype'=>'pdf/file', 'content'=>'dhjhfjskjfhksjfhsjfhsfhsdfjhsfj')

How can I read and print the content o the file.

Sorry for my bad english :o)

Edited by pritaeas: Added markdown.

3 Years
Discussion Span
Last Post by almostbob

How can I read and print the content o the file.


Probably contains the binary file. You need to save it before you can open it.



header("Content-disposition: inline; filename=$YourArray['filename']");
header('Content-type: application/pdf;');
echo $YourArray['content'];

force save

header("Content-disposition: attachment; filename=$YourArray['filename']");
header('Content-type: application/pdf;');
echo $YourArray['content'];

not tested for pdf
works with images

the mimetype pdf/file is wrong

Edited by almostbob


the above two scraps are used when the pdf is the only thing on the page to be displayed, headers make the page limited in the amount of other data than can be sent, everything is assumed to be encoded pdf

as part of a page, tested,
BUT there is always a but;
Ensure the type of encoding in which the content is sent, and change base64 appropriately

<a href="data:application/pdf;base64,<?php echo $YourArray['content']; ?>"><?php echo $YourArray['filename']; ?></a>

the mimetype is still wrong
If you are accepting multiple mimetypes from the web service, you can always if/else or switch/case through $YourArray['mimetype'] and echo the correct mimetype into the link

sample generated pdf, as html, in the attachment

Edited by almostbob


If you are serving many files from the web service, it would be better to retrieve the file onclick
the page will be huge, +(all files x1.25) if all embedded at once

1 post, no return for a week, not coming back

Edited by almostbob

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.