I got a time to post the important feature for web applications. User need to access statements through PDF. But that PDF needs to be Password protected.
To open the PDF, we can have different Password implemenations like (telephone no, DOB,Bank id, Last 4 digit of account no and name Etc...)
Now i am implementing password feature through the Random number Genaration.
import java.io.FileOutputStream;
import java.util.Random;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class ProtectPDFPassword {
public static byte[] UserPassword= "UserPassword".getBytes();
public static byte[] OwnerPassword = "OwnerPassword".getBytes();
public static void main(String[] args){
try {
Document Document_For_Protection = new Document();
PdfWriter EncryptPDF= PdfWriter.getInstance(Document_For_Protection, new FileOutputStream(generatePin()+".pdf"));
EncryptPDF.setEncryption(UserPassword, String.valueOf(generatePin()).getBytes(),
PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
EncryptPDF.createXmpMetadata();
Document_For_Protection.open();
Document_For_Protection.add(new Paragraph("Some Contents for Password Protection"));
Document_For_Protection.add(new Paragraph("Password is :"+"password"));
Document_For_Protection.close();
}
catch (Exception i)
{
System.out.println(i);
}
}
public static int generatePin() throws Exception {
Random generator = new Random();
generator.setSeed(System.currentTimeMillis());
int num = generator.nextInt(99999) + 99999;
System.out.println("Random number value---" + num);
if (num < 100000 || num > 999999) {
num = generator.nextInt(99999) + 99999;
if (num < 100000 || num > 999999) {
throw new Exception("Unable to generate PIN at this time..");
}
}
return num;
}
Required Jars's
itext-5.0.2.jar
bcprov-jdk15-136.jar
Thursday, December 15, 2011
Wednesday, September 21, 2011
Create a Executable jar file from the command line or ANT build, Build Simple ANT File
Here i am posting how to make executable jar file from the command line as well through ANT tool, then how to run that executable jar file from the command prompt
This is the simple way to create executable jar file.
Step 1 : create folder inside your respective directory [Ex: c:/simple_java/src>]
Step 2 : create java file/files under this project[Package name is optional]
Ex: HelloWorld.java ,Person.java
under com.siva pacakage
Ex: c:/simple_java/src/com/siva>HelloWorld.java
Person.java
compile : c:/simple_java/src>javac com/siva/*.java
Step 3 : create one MANIFEST.MF or manifest.txt
under src folder.[this file can be created any place in your computer]
Ex: c:/>simple_java/src/manifest.txt
We need to mention the main class details.
Manifest-Version: 1.0
Main-Class: com.siva.HelloWorld
Step 4 : Now we need to create the executable jar file with the following command
c:/simple_java/src>jar cvfm simple_java.jar manifest.txt com/siva/*.class
Step 5: Run the executable jar file
c:/simple_java/src>java -jar simple_java.jar
Simple ANT build.xml- which used to compile , run and create the executable jar file which includes manifest file.
Before Starting with build.xml- We need to know What is ANT(Another Neat Tool]. Used for to build the application.
setting the ANT in our system.
Step 1: Down load the latest code from the ANT site .[Prefer to download the .ZIP file]
Download
Step 2: Unzip the Downloaded file, Then set the path.
Setting the Path
Right Click on My Computer ->Properties ->Advanced-> Environment Variables-> System variables -> select Path -> Edit ->give semicolon(;) end of the path value-> paste the ant location upto bin
Ex:
C:\apache-ant-1.8.2-bin\apache-ant-1.8.2\bin
Step 4: Create java programs related to your purpose.
Step 5: create build.xml file, then write the code inside build.xml, for
compilation, creating executable jar file the application.
Step 6: Run the build.xml-> by using the ant command
EX:
c:/simple_javaproject>ant
Down Load Source Code
This is the simple way to create executable jar file.
Step 1 : create folder inside your respective directory [Ex: c:/simple_java/src>]
Step 2 : create java file/files under this project[Package name is optional]
Ex: HelloWorld.java ,Person.java
under com.siva pacakage
Ex: c:/simple_java/src/com/siva>HelloWorld.java
Person.java
compile : c:/simple_java/src>javac com/siva/*.java
Step 3 : create one MANIFEST.MF or manifest.txt
under src folder.[this file can be created any place in your computer]
Ex: c:/>simple_java/src/manifest.txt
We need to mention the main class details.
Manifest-Version: 1.0
Main-Class: com.siva.HelloWorld
Step 4 : Now we need to create the executable jar file with the following command
c:/simple_java/src>jar cvfm simple_java.jar manifest.txt com/siva/*.class
Step 5: Run the executable jar file
c:/simple_java/src>java -jar simple_java.jar
Simple ANT build.xml- which used to compile , run and create the executable jar file which includes manifest file.
Before Starting with build.xml- We need to know What is ANT(Another Neat Tool]. Used for to build the application.
setting the ANT in our system.
Step 1: Down load the latest code from the ANT site .[Prefer to download the .ZIP file]
Download
Step 2: Unzip the Downloaded file, Then set the path.
Setting the Path
Right Click on My Computer ->Properties ->Advanced-> Environment Variables-> System variables -> select Path -> Edit ->give semicolon(;) end of the path value-> paste the ant location upto bin
Ex:
C:\apache-ant-1.8.2-bin\apache-ant-1.8.2\bin
Step 4: Create java programs related to your purpose.
Step 5: create build.xml file, then write the code inside build.xml, for
compilation, creating executable jar file the application.
Step 6: Run the build.xml-> by using the ant command
EX:
c:/simple_javaproject>ant
Down Load Source Code
Subscribe to:
Comments (Atom)