wp_get_attachment_url not working

  1. Add the PDF attachment ID as a custom field value, for example attached_pdf_id.

  2. Get the URL using wp_get_attachment_url():

<?php
if ( is_user_logged_in() ) {

$pdf_link = wp_get_attachment_url( get_post_meta( get_the_ID(), 'attached_pdf_id', true ) );

if ( $pdf_link ) {
?><a href = "https://wordpress.stackexchange.com/questions/89809/<?php echo $pdf_link ?>" >Download</a><?php
} else {
?>Sorry, no link available. Please contact the webmaser.<?php
}
}
?>