Page 1 of 1
Password protected PDF file
Posted: Fri Dec 02, 2011 10:06 am
by shire
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.
Re: Password protected PDF file
Posted: Fri Dec 02, 2011 9:45 pm
by IdeasVacuum
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
Re: Password protected PDF file
Posted: Sat Dec 03, 2011 12:03 pm
by shire
@IdeasVacuum:
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>
say i have a file named "jsscript.js" with that code, then will it be just:
Code: Select all
pdf_IncludeFileJS("C:\Documents and Settings\name\Desktop\jsscript.js")
Regards.
Re: Password protected PDF file
Posted: Sat Dec 03, 2011 6:28 pm
by IdeasVacuum
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.
Re: Password protected PDF file
Posted: Mon Dec 05, 2011 1:32 am
by shire
I tried something like that but it didn't work.
Maybe there's some format for the script to be followed.
Re: Password protected PDF file
Posted: Mon Dec 05, 2011 3:05 am
by IdeasVacuum
Hmm - I had expected a simple Include to work:
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)
.....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
Re: Password protected PDF file
Posted: Tue Dec 06, 2011 2:39 am
by shire
Thanks for the help.
I'm looking forward to it.