Page 1 of 1

Sending PDF password via php

Posted: Wed Sep 21, 2011 11:38 am
by Mince
Hi All

I have been struggling with this for a while. On my intranet site I create PDF's, and assign them a password (they all have the same password). Now i want to know if there's a method to send the pdf document the password via php? I assume it would be done here:

Code: Select all

$file = "../../../base/ScanReport.pdf";

if (file_exists($file)) 
{
    header('Content-Description: File Transfer');
    header('Content-Type: MIME');
    header('Content-Disposition: inline; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file)); 
    ob_clean();
    flush();
    readfile($file);
    exit;
}
else
{
	echo "<font color = 'red'>Something went wrong, file not created.</font>";
}
The reason why I need the php to send the password is because when users open the file using the intranet, they should be allowed to see it automatically as they are already logged in. A person who finds the document on the server, for example, would have to type in the password manually to get access to the document.

Re: Sending PDF password via php

Posted: Sun Sep 25, 2011 7:32 pm
by yacahuma
I dont think you can do that. What you should do is send the pdf with no password when the user is logged in.

Re: Sending PDF password via php

Posted: Wed Sep 28, 2011 3:42 am
by Mince
Thanks for the reply.

Unfortunately, the pdf's are created and stored on the server, and have to be password protected due to privacy laws. These pdfs are not created on the fly, so i can't just create them without the passwords.

Re: Sending PDF password via php

Posted: Wed Sep 28, 2011 8:42 am
by yacahuma
why not remove the password and then sent it, only when the user is logged in?