Ruby: Get The Generated Letter with GetPDF()

The following code will retrieve the PDF generated by PostalMethods. Please note, the document takes time to complete rendering. Requesting the PDF before it is rendered results with an error code.

  1. Replace MyUsername and MyPassword with your PostalMethods user details.
  2. Replace LetterID with the unique ID returned when sending this letter.
  3. Execute this code. If the returned ResultCode equals -3000, this call will return the PDF file for the specified letter ID as a data blob. You should write it to a file in order to view it. The returned file will always be in a PDF format, regardless of the file type you originally sent as input.
    If the returned ResultCode is different than -3000, the request was unsuccessful. Check the Web Service Status Codes section.
#!/usr/bin/env ruby 
require 'rubygems'
require 'postalmethods'
options = {:username => 'MyUsername', :password => 'MyPassword'}
client =
pdf_file = client.get_pdf(LetterID)