I've been looking in many sites and I didn't find an answer. Is it possible to password protect a PDF generated with "renderAs = PDF"? In a negative case I need to find another way to protect my PDF document against copy. Can anyone helps me?
-
1It is not possible to do inside Salesforce. You have to create a third party service for this, and call that from Salesforce. Check this link appirio.com/tech-blog/password-protect-pdf-salesforce-heroku– Saroj BeraFeb 17, 2017 at 11:59
-
@SarojBera Thank you very much. I'll try to solve my problem like this. If is there any other way to solve this I'm open for new ideas.– Bruno PerdigãoFeb 17, 2017 at 13:51
1 Answer
You can create a Username - Password step before allowing anyone to download your PDF. If you inform the user that he can download a PDF after inserting a Username and Password you can do something like this.
Put a link in your Visualforce page to access the PDF. When the user clicks on that link he will see a login page, if the username and password are correct you will redirect him to the page where the PDF is located or automatically start the download.
So, here is a small code that can help you with the access page. You can also use a checkbox, 'PDF Allow', on the User page layout to allow access to you PDF fiel/s. If the check is true you can redirect the user to the page with the PDF. For this, you need to elaborate your code a bit and make the correct changes, this code is a starting point.
So you can start with something like this:
public class accessPDFpage{
public String password { get; set; }
public String username { get; set; }
public PageReference registerNewUser() {
PageReference newPage = new PageReference('/apex/newUserPage');
newPage.setRedirect(true);
return newPage;
}
}
This is the Visualforce code:
<apex:page controller="accessPDFpage" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:Pagemessages id="msg"/>
<apex:form >
<apex:pageBlock title="PDF Access">
<p><b>Login Page</b><br /></p>
<apex:panelGrid columns="1" style="margin-top:1em;">
<p><b>UserName</b><br />
<apex:inputText required="true" id="username" value="{!username}"/>
</p>
<p><b>Password</b><br />
<apex:inputSecret id="password" value="{!password}"/>
</p>
<apex:pageBlockSection >
<apex:commandButton action="{!registerUser}" value="Save" id="save"/>
<apex:commandButton action="{!registerUser}" value="Cancel" id="cancel"/>
</apex:pageBlockSection>
<apex:pageblockSection >
<apex:commandButton action="{!registerUser}" value="Register" id="register" immediate="true"/>
</apex:pageblockSection>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
Like you can see this is very simple code but you can do a lot of things. You can run an SOQL on the current user and if the user 'PDF Allow' checkbox is true, you can send the user to the PDF without inserting any Username or Password.
You can also allow the users to register or ask for access to the PDF.Is really up to you and to your business requirements. I hope this helps you to build a solution :)
-
2Love the work you put into this answer. One point though, it does not prevent the PDF from being "shared" and thus access to those who should not have it. Understanding that the downloader could also share the password if set on the PDF but that would be their problem...– EricFeb 19, 2017 at 18:40
-
1Thank you, Eric. Yes, you right, that will not stop from sharing the PDF with people that don't have access, but that will be practically impossible to do :( Feb 19, 2017 at 19:51