Hi,
As the subject stated, I want to know if is it possible to password protect the PDF generated by ebase webapp? If so, how?
Thanks in advance for the help.
can the PDF created by ebase apps be password protected?
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 305
- Joined: Thu Jul 02, 2015 8:32 am
- Location: Indonesia
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
I google'd this and came up with this stack overflow example http://stackoverflow.com/questions/2568 ... -protected. In general, if you can find some Java code that does what you want, you can just convert it to Javascript:
The example uses this Java code:
Converted to Javascript it looks like this:
I don't know anything about PDF protection so can't vouch for whether this works or not. But you should be able to create a solution from this. It seems to take an existing PDF file path as input (var src), and create a new PDF (at patht dest). This uses the itext PDF package which is already included in Ebase, but you will also need to import a bouncy castle provider jar (provides encryption) and add it to WEB-INF/lib on the server. I found this problematic and eventually got it to work with this jar file http://repo2.maven.org/maven2/org/bounc ... 5%2b/1.46/
Hope this points you in the right direction.
The example uses this Java code:
Code: Select all
/** User password. */
public static byte[] USER = "Hello".getBytes();
/** Owner password. */
public static byte[] OWNER = "World".getBytes();
...
public void encryptPdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.setEncryption(USER, OWNER,
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
stamper.close();
reader.close();
}
Code: Select all
importPackage(com.lowagie.text.pdf);
importPackage(java.io);
/** User password. */
var USER_PASSWORD = new java.lang.String("Hello").getBytes();
/** Owner password. */
var OWNER_PASSWORD = new java.lang.String("World").getBytes();
function encryptPdf(src, dest) {
var reader = new PdfReader(src);
stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.setEncryption(USER_PASSWORD, OWNER_PASSWORD,
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
stamper.close();
reader.close();
}
Hope this points you in the right direction.
0 x
-
- Ebase User
- Posts: 305
- Joined: Thu Jul 02, 2015 8:32 am
- Location: Indonesia
Hi,
Thanks a lot for the respond, Jon. Really appreciate a complete pointer.
I will try to elaborate it and find out if I can get what I want.
Thanks a lot for the respond, Jon. Really appreciate a complete pointer.
I will try to elaborate it and find out if I can get what I want.
Jon wrote:I google'd this and came up with this stack overflow example http://stackoverflow.com/questions/2568 ... -protected. In general, if you can find some Java code that does what you want, you can just convert it to Javascript:
The example uses this Java code:
Converted to Javascript it looks like this:Code: Select all
/** User password. */ public static byte[] USER = "Hello".getBytes(); /** Owner password. */ public static byte[] OWNER = "World".getBytes(); ... public void encryptPdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.setEncryption(USER, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA); stamper.close(); reader.close(); }
I don't know anything about PDF protection so can't vouch for whether this works or not. But you should be able to create a solution from this. It seems to take an existing PDF file path as input (var src), and create a new PDF (at patht dest). This uses the itext PDF package which is already included in Ebase, but you will also need to import a bouncy castle provider jar (provides encryption) and add it to WEB-INF/lib on the server. I found this problematic and eventually got it to work with this jar file http://repo2.maven.org/maven2/org/bounc ... 5%2b/1.46/Code: Select all
importPackage(com.lowagie.text.pdf); importPackage(java.io); /** User password. */ var USER_PASSWORD = new java.lang.String("Hello").getBytes(); /** Owner password. */ var OWNER_PASSWORD = new java.lang.String("World").getBytes(); function encryptPdf(src, dest) { var reader = new PdfReader(src); stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.setEncryption(USER_PASSWORD, OWNER_PASSWORD, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA); stamper.close(); reader.close(); }
Hope this points you in the right direction.
0 x
Who is online
Users browsing this forum: No registered users and 23 guests