Hello,
Does anyone know how to add a password to a PDF file using Purebasic or is it possible?
Just like the applications Restrict PDF or Adobe Acrobat.
Thank you.
Password protected PDF file
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Password protected PDF file
If you are creating the PDF with PB (using PurePDF for example) then you can probably password protect the file by embedding a JavaScript snippet.
http://www.pageresource.com/jscript/jpass.htm
http://www.pageresource.com/jscript/jpass.htm
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Password protected PDF file
@IdeasVacuum:
Thank you for your reply
Is this the same format of javascript to be used?
say i have a file named "jsscript.js" with that code, then will it be just:
Regards.
Thank you for your reply
Is this the same format of javascript to be used?
Code: Select all
<HEAD>
<SCRIPT language="JavaScript">
<!--hide
var password;
var pass1="cool";
password=prompt('Please enter your password to view this page!',' ');
if (password==pass1)
alert('Password Correct! Click OK to enter!');
else
{
window.location="http://www.pageresource.com/jscript/jpass.htm";
}
//-->
</SCRIPT>
</HEAD>
Code: Select all
pdf_IncludeFileJS("C:\Documents and Settings\name\Desktop\jsscript.js")
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Password protected PDF file
That's how I imagined it, should work. The only snag is that some Anti-Virus apps do not like 'smart' PDF, so people may see an alarming pop-up from the AV.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Password protected PDF file
I tried something like that but it didn't work.
Maybe there's some format for the script to be followed.
Maybe there's some format for the script to be followed.
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Password protected PDF file
Hmm - I had expected a simple Include to work:
.....The file is created without complaint, but the javascript does not execute on file open.
I assume this must be a syntax issue, ABBKlaus will know, but this post needs to be in the PurePDF posts.
Edit: Posted question in PurePDF topic:http://www.purebasic.fr/english/viewtop ... 95#p368595
Code: Select all
sPdfName.s = "C:\MyPdf.pdf"
pdf_Create("P","mm",#PDF_PAGE_FORMAT_A4)
pdf_AddPage()
pdf_IncludeJS("pass=prompt('enter password',' ');if(pass=='secret')alert('OK');")
pdf_Save(sPdfName)I assume this must be a syntax issue, ABBKlaus will know, but this post needs to be in the PurePDF posts.
Edit: Posted question in PurePDF topic:http://www.purebasic.fr/english/viewtop ... 95#p368595
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Password protected PDF file
Thanks for the help.
I'm looking forward to it.
I'm looking forward to it.
