I want to create shipping label (in pdf) via DHL. So, I have created the required xml format and post the same through PHP cUrl.
$message_ref = '';
for ($i=0; $i< 30; $i++)
{
$message_ref .= rand(0, 9);
}
$message_time = date("Y-m-d") . "T" . date("H:i:sP");
Below is the codes for the XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<req:ShipmentValidateRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com ship-val-req.xsd">
<Request>
<ServiceHeader>
<MessageTime>$message_time</MessageTime>
<MessageReference>$message_ref</MessageReference>
<SiteID>XXXXX</SiteID>
<Password>XXXXX</Password>
</ServiceHeader>
</Request>
<RequestedPickupTime>N</RequestedPickupTime>
<NewShipper>N</NewShipper>
<LanguageCode>en</LanguageCode>
<PiecesEnabled>Y</PiecesEnabled>
<Billing>
<ShipperAccountNumber>XXXXX</ShipperAccountNumber>
<ShippingPaymentType>S</ShippingPaymentType>
<BillingAccountNumber>XXXXX</BillingAccountNumber>
<DutyPaymentType>R</DutyPaymentType>
</Billing>
<Consignee>
<CompanyName>-</CompanyName>
<AddressLine>Address 1 </AddressLine>
<City>Enugu</City>
<Division>Enugu</Division>
<DivisionCode>EN</DivisionCode>
<PostalCode></PostalCode>
<CountryCode>NG</CountryCode>
<CountryName>Nigeria</CountryName>
<Contact>
<PersonName>DDDDDD</PersonName>
<PhoneNumber>+23555555555</PhoneNumber>
<PhoneExtension></PhoneExtension>
</Contact>
</Consignee>
<Dutiable>
<DeclaredValue>0.00</DeclaredValue>
<DeclaredCurrency>USD</DeclaredCurrency>
<TermsOfTrade>DAP</TermsOfTrade>
</Dutiable>
<Reference>
<ReferenceID>129624</ReferenceID>
<ReferenceType>St</ReferenceType>
</Reference>
<ShipmentDetails>
<NumberOfPieces>1</NumberOfPieces>
<Pieces><Piece>
<PieceID>1</PieceID>
<PackageType>EE</PackageType>
<Weight>1</Weight>
<DimWeight>1</DimWeight>
<Width>1</Width>
<Height>1</Height>
<Depth>1</Depth>
<PieceContents></PieceContents>
</Piece></Pieces>
<Weight>1</Weight>
<WeightUnit>L</WeightUnit>
<GlobalProductCode>P</GlobalProductCode>
<Date>2018-06-22</Date>
<Contents>SHIPMENT #129624</Contents>
<DoorTo>DD</DoorTo>
<DimensionUnit>I</DimensionUnit>
<PackageType>EE</PackageType>
<IsDutiable>N</IsDutiable>
<CurrencyCode>USD</CurrencyCode>
</ShipmentDetails>
<Shipper>
<ShipperID>XXXXXX</ShipperID>
<CompanyName>CompanyName</CompanyName>
<RegisteredAccount>848XXXX</RegisteredAccount>
<AddressLine>MyAddress </AddressLine>
<City>Houston</City>
<Division>Texas</Division>
<DivisionCode>TX</DivisionCode>
<PostalCode>77031</PostalCode>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<Contact>
<PersonName>Urama</PersonName>
<PhoneNumber>65656565</PhoneNumber>
<PhoneExtension></PhoneExtension>
</Contact>
</Shipper>
<EProcShip>N</EProcShip>
<LabelImageFormat>PDF</LabelImageFormat>
<RequestArchiveDoc>Y</RequestArchiveDoc>
<Label>
<LabelTemplate>8X4_thermal</LabelTemplate>
<Logo>Y</Logo>
<Resolution>200</Resolution>
</Label>
</req:ShipmentValidateRequest>
Below is the cUrl code:
$url = "https://xmlpi-ea.dhl.com/XMLShippingServlet";
Modified ---
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$query");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
#print_r($output);
preg_match("/<OutputImage>(.*?)<\/OutputImage>/", $output, $matches);
$image = base64_decode($matches[1]);
<img src="data:image/gif;base64,<?=$image?>">
Now I see the image is showing garbage chars in the browser. I have append "data:image/gif;base64," before $image but still garbage characters are showing. Can someone help me how can I display the image?
Finally I solved it by adding the code:
header("Content-type:application/pdf");
header("Content-Disposition:inline;filename=label_123demo.pdf");
echo $image;