# Wednesday, August 21, 2013

We've had several requests for an example on using our SOAP API, so decided to throw one together for you to get an idea of how it works.

The example below will send PDF documents as a letter with a cover letter which is written as a formatted HTML string (see the LetterBody attribute below).

To make more use of this example and to adapt it to your needs you may need to look at the Letter Pricing API along with the country code list which can all be found here.

If you would like us to advise you on what are the best options to use for postage and paper usage please contact us.

   1:  <?php
   3:  $client = new SoapClient("https://www.pc2paper.co.uk/lettercustomerapi.svc?wsdl");
   5:  // Your PC2Paper Username and Password go below
   6:  $pc2paperUsername = "username";
   7:  $pc2paperPassword = "password";
   9:  //First we upload a PDF we wish to attach to our letter
  11:  $file = file_get_contents("C:\tempfiles\mytestfile.pdf");
  13:  //We give the pdf a friendly name
  14:  $parametersUpload->filename = "mytestFile.pdf";
  15:  $parametersUpload->fileContent = $file;
  16:  $parametersUpload->username=$pc2paperUsername;
  17:  $parametersUpload->password=$pc2paperPassword;
  19:  //We submit our PDF to PC2Paper
  20:  $uploadedFileResult = $client->UploadDocument($parametersUpload);
  22:  // Not the above return value contains the following
  23:  // $uploadedFileResult->UploadDocumentResult->ErrorMessages  (A a string array of any errors that took place)
  24:  // $uploadedFileResult->UploadDocumentResult->FileCreatedGUID (The created files GUID)0
  25:  // $uploadedFileResult->UploadDocumentResult->Status (OK or ERROR, if error check ErrorMessages array
  27:  //After our PDF has been submited we get a GUID which we store in an array to use with our letter below.
  28:  //Note you can attach multiple PDF's to your letter by adding to this array.
  29:  $fileGuidArray =  array($uploadedFileResult->UploadDocumentResult->FileCreatedGUID);
  32:  // ********** The actual Letter.
  33:  // We put an address together
  34:  $address->ReceiverName = "Tom Smith";
  35:  $address->ReceiverAddressLine1 = "Line 1 ";
  36:  $address->ReceiverAddressLine2 = "Line 2";
  37:  $address->ReceiverAddressTownCityOrLine3 = "My Town";
  38:  $address->ReceiverAddressCountyStateOrLine4 = "County";
  39:  $address->ReceiverAddressPostCode = "ZZ1 2ZZ";
  41:  // Add the address to an address array
  42:  $addressArray = array($address);
  44:  //Add the address array to our letter
  45:  $letter->Addresses = $addressArray ;
  47:  //Setup our postage options (use the LetterPosting API for these values 
  48:  //or ask us and we will be happy to provide the values based on your needs)
  51:  // 1=UK , 240=US for a list of more please refer to country.csv file from the API section of our website.
  52:  $letter->ReceiverCountryCode = 1; 
  54:  $letter->IncludeSenderAddressOnEnvelope = true;
  55:  $letter->Postage = 3; //UK First Class
  56:  $letter->Paper = 1;  // B&W Single Sides print
  57:  $letter->Extras = 0;
  58:  $letter->Envelope = 1; //Simple DL envelope
  59:  $letter->Pages = 2;
  60:  $letter->FileAttachementGUIDs = $fileGuidArray;
  62:  $letter->SenderAddress = "Peter Smith\nMy Town";
  64:  //This is the cover letter of your letter. Leave this null if you do not want a cover letter
  65:  //You may use formatted HTML in here to format your letter.
  66:  $letter->LetterBody = "<p>Hi Tom,</p> <p>This is a letter sent from PHP!</p>";
  69:  $parameters->letterForPosting = $letter;
  71:  // Your PC2Paper username and password
  72:  $parameters->username = $pc2paperUsername;
  73:  $parameters->password = $pc2paperPassword;
  75:  $result = $client->SendSubmitLetterForPosting($parameters);
  77:  // The return object will give you the following
  78:  // $result->SendSubmitLetterForPostingResult->CostOfLetter
  79:  // $result->SendSubmitLetterForPostingResult->ErrorMessages  (any errors that took place)
  80:  // $result->SendSubmitLetterForPostingResult->FundsLeftInYourAccount
  81:  // $result->SendSubmitLetterForPostingResult->LetterId
  82:  // $result->SendSubmitLetterForPostingResult->Status (OK if everything went ok or ERROR, if error check the ErrorMessages array)
  85:  print_r($result);
  86:  ?>
posted on Wednesday, August 21, 2013 9:02:50 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Wednesday, August 7, 2013

One query we often get from our customers, is why can't they send a personalised mailshot. It often surprises us because this functionality has existed on PC2Paper for nearly 10 years. We suddenly realised that maybe we're just not that good at advertising the features available on our service so will be starting a series of blog articles to highlight some of them. The first being how to do a mail merge with our service.

This tutorial will show you how to send the same letter to multiple recipients, personalising each one with the recipients name and address using our mailshot letter writing interface and a spread sheet of your recipients details. You will write your letter online using our letter writing interface and can attach as many PDF's as you wish to the letter.

Before you continue with this tutorial, ensure you are logged into your PC2Paper Account in order for the links below to work.

Step 1 - Create a new Address List/Book

You can create a new Address List from the My Address Book section of the site click here to do so (will open in new window). You can also manually navigate here from the website by clicking on the "My Address book" option from with the PC2Paper Website.


Step 2 - Upload your address list

You can do this from the My Address Book section of the site. To upload your address book click on the "Upload your address book" tab or go to the following link upload my address book (will open in new window) and follow the steps on the page.

Step 3 - Name your mailshot

If you haven't already done so go to the mailshot writing interface, you can go to it directly by clicking here or by clicking on the write letter option from within the PC2Paper website.

Give your mailshot a name.


Step 4 - Choose you address list

Click the "Add Address" button and select the address list/book you uploaded in step 2 above. Select the recipients, you can select multiple by selecting the first item and then holding down the shift key as you select the last item. After selecting your recipients select the "Add recipient" button and then the OK button. You can also add more addresses manually at this stage.


Step 5 - Create your letter

In this example we are using a template to create the letter. You do not need to use a template you can create your own letter from scratch.

Step 5a

Click on the "Write letter" dialogue.

Step 5b - Template

Choose a template by clicking on the template icon (indicated in the image below).

Step 6 - Your Letter

After selecting a template you should see something similar to the image below. The odd looking characters that begin with <& are placeholders for the various details of your recipients. To see what the letter will look like when sent to us press the "Preview" button at the top or bottom of the write letter page. You can insert further mail merge fields using the floating Field dialogue box shown below.

Step 7 - Preview

You should now be able to see previews of your mailshot by clicking on the Preview button located at the top or bottom of the write letter page. Using the arrows shown below you can scroll through a preview of how your letter will look to each recipient. When you are happy with your preview, close the preview click on the Send button (at the top of the page) to see how much it will cost, select postage options and send your letter to us for printing and posting.

Step 8 - Attach PDF's (optional)

Don't forget you can also attach PDFs to your letter by clicking on the "PDF Attachments" tab.

Step 9 - Insert your signature or an image (optional)

To personalise your letter further you can also insert an uploaded image of your signature find out how.

posted on Wednesday, August 7, 2013 10:07:34 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Monday, August 5, 2013

We've just released a beta version of our new SOAP API which harnesses many of the features found in our recently launched Letter 2.0 writing interface.

The API enables you to:

  • Send the same letter to multiple recipient
  • Attach multiple PDF's to a letter
  • Add a cover (written in HTML) with or without PDF's

More documentation will follow soon, but for now here is an example for using the API.

The endpoint for the service can be found here https://www.pc2paper.co.uk/lettercustomerapi.svc
to access the WSDL simply go here https://www.pc2paper.co.uk/lettercustomerapi.svc?wsdl

Please note the service endpoint talks about svcutil.exe, this is only applicable to Microsoft WCF users. Please also note that SOAP is a widely used XML-based protocol, it is assumed at all times that the developer is aware of SOAP or has used it. It is beyond the scope of this article to explain SOAP. If you are using .NET you can take advantage of the features available to you in WCF, if not you can still use the service as a bog standard soap service from any of the popular languages such as PHP, C#, Ruby, Delphi, Java etc. by just using the WSDL (https://www.pc2paper.co.uk/lettercustomerapi.svc?wsdl )

The example in this article uses C#, we will cover using the service from other languages in future, for now here are some links about SOAP in those languages.

The following example illustrates how to upload a PDF attachment and write a cover letter with our new API the sample below is in C# using Visual Studio .NET. More examples in other languages will follow.

Firstly add a new service reference to your project, ensure you use https in the service address as below.


The code for the example is below. As with our other interfaces, in order to get the correct envelope, paper, print type and postage type please refer to our Letter Pricing API or contact us with your requirements and we will be more than happy to provide suitable values for you.

   1:  using System;
   2:  using System.IO;
   3:  using System.Text;
   4:  using PC2PaperLetterCustomerAPIExample.PC2PaperAPI;
   6:  namespace PC2PaperLetterCustomerAPIExample
   7:  {
   8:      static class Program
   9:      {
  11:          static void Main()
  12:          {
  13:              SendLetter();
  14:          }
  16:          static void SendLetter()
  17:          {
  18:              //Your PC2Paper username and password go here.
  19:              string username = "yourusername";
  20:              string password = "yourpassword";
  22:              var pc2PaperAPI = new PC2PaperAPI.LetterCustomerAPIClient();
  25:              //1. First we upload the files we want to attach to our letter
  26:              //   If you don't want to attach any files you can leave this step out.
  27:              // NOTE: You can also upload files async if using WCF Async methods are enables so you don't hang a UI thread for example.
  29:              // You can add as many PDF's as you want in this way. Just remember to grab the GUID's from each submit to the server.
  30:              // below we are only attaching one.
  31:              var fileContent =
  32:                  LoadBinaryFileAsByteArray(
  33:                      @"c:\temp\testPDF.pdf");
  36:              string fileName = "testPDF.pdf";
  38:              var uploadDocumentResults = pc2PaperAPI.UploadDocument(fileName, fileContent, username, password);
  41:              if(uploadDocumentResults.Status!="OK")
  42:              {
  43:                  // Oops an error took place.
  44:                  Console.WriteLine(uploadDocumentResults.ErrorMessages.ToString());
  45:                  return;
  46:              }
  48:              //2. Create a letter to attach out PDF to.
  49:              var letter = new LetterForPosting();
  51:              letter.Addresses = new LetterAddressForPosting[]
  52:                                     {
  53:                                         new LetterAddressForPosting()
  54:                                             {
  55:                                                 ReceiverName = "Tom Smith",
  56:                                                 ReceiverAddressLine1 = "Acme Co",
  57:                                                 ReceiverAddressLine2 = "2 Acme Street",
  58:                                                 ReceiverAddressTownCityOrLine3 = "Acme Town",
  59:                                                 ReceiverAddressCountyStateOrLine4 = "State",
  60:                                                 ReceiverAddressPostCode = "ZN12 9xn"
  61:                                             }
  62:                                     };
  64:              letter.ReceiverCountryCode = 1;
  66:              letter.Envelope = 1;
  67:              letter.Postage = 3; //UK First Class
  68:              letter.Paper = 1;
  69:              letter.Extras = 0;
  70:              letter.SenderAddress = "Peter Smith\n 72 Some Road \n Some Town \n P23 123";
  71:              letter.Pages = 1;
  73:              // We are also putting a cover letter onto our letter. (The cover letter will always be in front)
  74:              // Leave the LetterBody line out if you do not wish to include one.
  75:              var bodyOfLetter = new StringBuilder();
  77:              bodyOfLetter.Append("

Dear Tom

  79:              bodyOfLetter.Append("

How are you? I'm sending you a letter via the PC2Paper API

  81:              bodyOfLetter.Append("


  83:              letter.LetterBody = bodyOfLetter.ToString();
  85:              // delete this line if you only wish to send a cover letter
  86:              letter.FileAttachementGUIDs = new string[] { uploadDocumentResults.FileCreatedGUID};
  88:             var letterSendingResult =  pc2PaperAPI.SendSubmitLetterForPosting(letter, username, password);
  90:              Console.WriteLine("Result:" + letterSendingResult.Status + " with letter id:" + letterSendingResult.LetterId);
  92:          }
  94:          static byte[] LoadBinaryFileAsByteArray(string filename)
  95:          {
  96:              var binReader = new
  97:                  BinaryReader(File.Open(filename, FileMode.Open,
  98:                                         FileAccess.Read));
  99:              binReader.BaseStream.Position = 0;
 100:              byte[] binFile =
 101:                  binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
 102:              binReader.Close();
 104:              return binFile;
 105:          }
 107:      }
 108:  }


If you have any questions, please let us know.

posted on Monday, August 5, 2013 11:01:56 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Wednesday, July 10, 2013

We have recently sourced new equipment which will soon be enable us to offer the colour laser print option at a greatly reduced price, in fact the same price we currently charge for a colour Ink Jet print. As a result of this PC2Paper will soon be withdrawing the Ink Jet printing option as we feel it has become surplus to requirements. The Ink Jet option has allowed customers the option to send a much lower cost colour print, however, we feel the new lower priced colour laser print not only provides a much better quality print but also better value for money.

posted on Wednesday, July 10, 2013 10:43:34 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Friday, May 24, 2013

Monday the 27th of May is a Bank Holiday in the UK. We do not have any Royal Mail collections of deliveries on this day and the PC2Paper office is closed. Any letters sent after our 4pm cut-off time on Friday the 24th of May will be sent on the next available working day Tuesday the 28th of May. Customers should also be aware that mail may take longer to be delivered over the Bank Holiday weekend.

posted on Friday, May 24, 2013 2:10:54 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Friday, May 3, 2013

Monday the 6th of May is a Bank Holiday within the UK so we have no mail deliveries or postal collections on this day. Any mail sent after our 4pm cut-off time on Friday the 3rd of May will be processed on the next available working day which is Tuesday the 7th of May.

posted on Friday, May 3, 2013 4:29:38 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Tuesday, April 2, 2013

As of today (2nd of April) the prices have increased for some Royal Mail services. These include Recorded and Special Delivery, International Signed delivery and Airmail. PC2Paper have increased our prices of these items to take into account the increases.

posted on Tuesday, April 2, 2013 3:47:49 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Wednesday, March 27, 2013

We would like to remind customers of the Royal Mail delivery times for Easter. Friday the 29th of March and Monday the 1st of April are public holidays in the UK. This means that there are no Royal Mail collections or deliveries on these days. PC2Paper will also be closed for the long weekend. Any letters received into our system after our cut-off time of 4pm on Thursday the 28th of March will be processed on the next available working day which is Tuesday the 2nd of April. Customers should also expect mail delivery to take longer due to the Bank Holidays.

posted on Wednesday, March 27, 2013 2:10:28 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback