我正在从快递网站生成运输标签,并以字节为单位接收响应,现在需要将字节数据转换为PDF,任何人都可以让我知道如何在php中做到这一点吗?
我的PHP代码是如下:
$soap_request = '<?xml version="1.0" encoding="utf-8"?>'."\n";
$soap_request .= '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'."\n";
$soap_request .= '<soap12:Body>'."\n";
$soap_request .= '<GetAddressLabel xmlns="http://tempuri.org/">'."\n";
$soap_request .= '<Username>abcd</Username>'."\n";
$soap_request .= '<password>xxxx</password>'."\n";
$soap_request .= '<accountNo>xxxx</accountNo>'."\n";
$soap_request .= '<consignments>54234567</consignments>'."\n";
$soap_request .= '</GetAddressLabel>'."\n";
$soap_request .= '</soap12:Body>'."\n";
$soap_request .= '</soap12:Envelope>';
$header = array(
"POST /mnpconsignments/pushtomnp.asmx HTTP/1.1",
"Host: mraabta.mulphico.pk",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://mraabta.mulphico.pk/mnpconsignments/pushtomnp.asmx" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
$buffer = curl_exec($soap_do);
if($buffer === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
echo $buffer;
curl_close($soap_do);
}
输出如下: %PDF-1.4%����1 0 obj <> streamx���w�����mt。“��b�K�+#v���ƈ�hP�h4;. X#v�QQb�Q�Ɗ���K��Uvv�;; s〜���〜��{�\g��wΞ�;w����ӧ�;o�� ��c�⦍���r�Tz��=?��s]��SQ{��1H���!u_�GO�X�&u�) '�ۖ������������4y�1���zb������������5���z����}�Q QƩ��� �/�c�^]�wOz��?5yA��vvo�>?l |�\���[�u[����z��R6���n�� ��搜;; [����������OM��y,��9��n���k��FX�ÐYo。{�a��5������4} I,Vܦ>'“] PZuW7lN?
但是我要输出的应该显示为pdf。 谢谢