NetTalk Central

Author Topic: Save Base64 encoded label PDF  (Read 12143 times)

Neil Porter

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Save Base64 encoded label PDF
« on: July 04, 2011, 07:47:52 AM »
Has anyone had any sucess saving PDF labels that have been produced by a SOAP server?

EG. I provide the following request:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<PrintLabelRequest xmlns="http://www.parcelforce.net/ws/ship/v2">
<Authentication>
<UserName>username</UserName>
<Password>password</Password>
</Authentication>
<ShipmentNumber>AA1082805</ShipmentNumber>
<PrintFormat>PDF</PrintFormat>
</PrintLabelRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The server sends me the response:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<PrintLabelReply xmlns="http://www.parcelforce.net/ws/ship/v2">
<Label>
<Data>{base 64 encoded label PDF}</Data>
</Label>
</PrintLabelReply>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need to save the encoded label, so that I can print it.

The question is how do I save that data to disk?

Any advice whould be very welcome.

Regards

Neil.

 
Clarion 11.0.13244
NetTalk 11.04

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Save Base64 encoded label PDF
« Reply #1 on: July 04, 2011, 10:46:29 PM »
So there are two ways to do this. With StringTheory, or without string theory.
http://www.capesoft.com/accessories/StringTheorysp.htm
With StringTheory it boils down to 5 lines of code;

str   StringTheory
  code
  str.SetValue(net.Page)
  str.SetValue(str.Between('<Data>','</Data>')
  str.Base64 = 1
  str.Base64Decode()
  str.SaveFile('somefilename')


Without StringTheory this breaks down to 3 main parts;
a) extract the data between the <Data> and </Data> tags. You can use Instring to do this.

b) Decode the string as it's current in Bas64 format. There's a NetTalk function that lets you do this; see here;
http://www.capesoft.com/docs/NetTalk5/NetTalk2.htm#NetBase64DecodeEx

c) Save the string to a file. WinEvent has a feature to do this as well, or use the DOS file driver, and a small loop to write the file.

Cheers
Bruce





first parse out the "data" field. Do this using xFiles or Instring or something like that.

Then decode the base64 using NetBase64DecodeEx. This is a NetTalk function, so you can just call it as;



Neil Porter

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: Save Base64 encoded label PDF
« Reply #2 on: July 05, 2011, 04:13:31 AM »
Thanks Bruce.

I don't have String Theory, but I do have WinEvent and Xfiles, so I will have a good crack at it.

My idea is to combine this with a NetTalk webserver, so that I can capture address details from a web client, pass the information to the Parcel Force SOAP server, and then serve the pdf labels as a document back to my original webclient.
Clarion 11.0.13244
NetTalk 11.04