我现在用的是英国皇家邮政送货API生成打印的PDF标签,我的PHP SoapClient的返回如下所示的有效响应(只显示整个响应最初的反应是巨大的)。
I am using the Royal Mail Shipping API to generate printed PDF labels, my PHP SoapClient returns a valid response shown below (only shown the initial response as the whole response is huge).
%PDF-1.7 %äãÏÒ 4 0 obj <> stream xœ endstream endobj 3 0 obj 8 endobj 9 0 obj <> stream xÚí]bì*¤Höýoübƒ¤Æ-q²É>ø%Íë‚ÔFÒ<1ÆoÌúÝú¯ý?1Æ%Èa9Ò4QÌ!}üŠ ÆãS€ZÿŸ2Mô¨H}üßÇcŒ˜Z´½\¡´üý’y©1Æø$¨RÓd°úø’ÆÄŒ1Ægð´ ¨Š'ª°Z¾MCF1Æ}¥/¨{d˜ZQ•†Þ7Æ_P¢õ‘ kjŒ1.J¦ê"ÕÑŽ©,ž‹1ÆãNÿÅIü{}L%üÄcŒÑS Þª€êÁI"ÀÅÃcŒcHÚsïuP5Ð4Æ .ê2¤mbŒ1vU¼vè:ž>Æ<´¾1ÆØTŠûfÓ¢œÆcTŒ³wGF1Æ任何人都可以建议转换这一带的Base64 codeD PDF标签正确的最好方法,所以我可以实际下载这个浏览器。下面我的code下载PDF文件,但是当我尝试打开该文件大小始终是57KB,我将返回在Acrobat Reader下面的消息
Can anyone suggest the best method to 'convert' this Base64 encoded PDF label correctly so I can physically download this to the browser. My code below downloads the PDF file but when I attempt to open this the filesize is always 57kb and I returns the following message in Acrobat Reader
"There was an error opening this document. The file is damaged and could not be repaired."我的code是如下:
My code is as follows:
$rm = new RoyalMailLabelRequest(); // provide shipment number, order tracking id, output format (e.g PDF/PNG) $response = $rm->PrintLabel('TTT000358756GB', '276831601444829801', 'PDF'); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="doc-'.$document.'.pdf"'); $data = base64_decode($response); file_put_contents('pdf/label.pdf', $data);更新
当我尝试回声脱codeD响应我得到以下...不知道是什么这一个发生..奇怪的。
UPDATE
When I try to echo the decoded response I get the following... not sure what is happening with this one.. odd.
$response = $rm->PrintLabel('TTT000358756GB', '276831601444829801', 'PDF'); $data = base64_decode($response); echo $data;exit;作为base64_de codeD之后
中回显$数据响应
Echo'd $data response after being base64_decoded
<1uï(n?Ëzx-‡}üX¥µêÿVx7œ¡×¬¶·š›我还补充说,由我的code回到这里引擎收录完整base64_en code响应,如果它可以帮助任何人 pastebin/JEtmRURK
推荐答案排序 - 是一个很漫长的一天。
Sorted - been a very long day.
我并不需要取消code到底反应,使下面的工作(希望它可以帮助别人做的API集成)
I didn't need to decode the response in the end so the following will work (hopefully it helps someone else doing the API integration)
function PrintLabelRequest($shipmentNumber, $transactionId) { $rm = new RoyalMailLabelRequest(); // function from library returns a response using SOAP $response = $rm->PrintLabel($shipmentNumber, $transactionId); // name the file & saved this label as a PDF in the following folder $filename = 'printedlabel-' . $shipmentNumber; file_put_contents(dirname(__FILE__) . '/labels/'. $filename .'.pdf', $response); }更多推荐
输出标准的Base64恩codeD流成PDF格式(PHP)
发布评论