PHP: Retrieve The PDF Document Of The Letter Or Postcard With GetPDF()

/************* Settings  Begin ****************/
$username = '********';
$password = '********';
$id = 99999999; // ID of transaction being queried
$output_filename = 'PostalMethods_' . $id . '.pdf'; // Comment out to view on screen
/************* Settings  End ******************/
$soapclient = new SoapClient('');
$result = $soapclient->GetPDF(array('Username'    => $username,
                                    'Password'    => $password,
                                    'ID'   => $id));
// Extract returned fields
$result_code = $result->GetPDFResult->ResultCode;
$file_data   = $result->GetPDFResult->FileData;
if ( $result_code == -3000) { 
    // an letter has been successfully retrieved
    if ($output_filename != ''){ 
        // output to file
		print "PDF successfully retrieved<br>";
        if (!$handle = fopen($output_filename, 'w')) {
            echo "Cannot open file ($output_filename)";
        if (fwrite($handle, $file_data) === FALSE) {
            echo "Cannot write to file $output_filename";
		print "PDF successfully written<br>";
        } else { 
            // output to screen
            header ("Content-type: application/pdf"); 
            echo $file_data;
} else {
    // no letter retrieved
    echo "Error: <a href=\"\">$result_code</a><br>";

Continue to: PHP: Accept status callback by HTTP POST from PostalMethods


Go back to: ‹PHP: Send PDF or other binary file with SendLetter()
Send Letters
Securely + Reliably
Send letters securely and reliably from any business application. Use for invoices, quotes, and other important business communications. Enjoy special web-form to postal features and instant notifications.
Simple Process
Easy as 1-2-3
Experience the ease of our streamlined process - developed for efficiency! You submit your document by email or API. We automatically print, collate, insert, and stamp your letter. Your letter is delivered via standard postal service.
Pay As You Go
No Fuss. No Obligations.
Register for free with no obligations! Evaluate the service as long as you need. Once you are ready, set up our user-friendly pay-as-you option to use our service. No fuss. No on-going commitment. Just plain easy!