A dozen free & essential apps for Windows by ZDNet's George Ou -- Every time I build a new Windows computer, there are a dozen free and essential applications that I always install for other people. These applications all seem to fill essential functions and they all seem to be well-behaved installers and uninstallers, in other words it won’t crash your computer or drag it down with gunk. [...]
A Tech and Social blog to share latest and greatest stuff from areas like Web technology, eCommerce , Travel and many more ...
Friday, February 15, 2008
Wednesday, February 13, 2008
Small utility program to unlock PDF documents
Ever downloaded a PDF document from internet which doesn’t have print option or its disabled? I hope you must have come across this situation.
Try this small java program to unlock PDF document for printing etc.
I am using iText API for doing it. They have a very rich collection of classes and methods to play with PDF files.
You need itext-1.4.6.jar to run this program. You can download this jar from http://www.lowagie.com/iText/download.html . If you are using eclipse IDE then set this jar in your project build path or if you are running this code from command prompt then you need to set this jar in your classpath.
So here is the code… just copy it and run it. You can see we are passing PDF file name to unlockPdf() method though command prompt. inputFile name is your original file which you want to unlock and outputFile name can be anything which you like.
package my.examples;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfEncryptor;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
public class UnlockPdf
{
public static void main(String[] args)
{
if (args.length < 2)
{
System.err.println("usage: java my.examples.UnlockPdf inputfile.pdf outputfile.pdf");
}
else
{
new UnlockPdf().unlock(args[0], args[1]);
}
}
private void unlock(String inputFile, String outputFile)
{
try
{
PdfReader reader = new PdfReader(inputFile);
PdfEncryptor.encrypt(reader, new FileOutputStream(outputFile), null, null,
PdfWriter.AllowAssembly | PdfWriter.AllowCopy
| PdfWriter.AllowDegradedPrinting | PdfWriter.AllowFillIn
| PdfWriter.AllowModifyAnnotations | PdfWriter.AllowModifyContents
| PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders, false);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (DocumentException e)
{
e.printStackTrace();
}
}
}
Popular Posts
-
In this post I have tried to explore Cartridges and Endeca Assembler Application by examining how they work together in a "Hello Wor...
-
E xploring new software and tool is always exciting and fun way to learn new stuff. With ATG Commerce v11 Oracle has replaced ATG Se...
-
H ope most of you must be knowing about Dynamo Application Framework ( DAF ) and Nucleus concepts in ATG . I have just tried to summarized t...
-
Recently started exploring Hybris commerce suite 5.0.4 and have some of the interesting facts to share. So let’s start with basics. ...
-
Just read one of the white papers from ATG's site , liked the way they have explained about Data Anywhere Architecture. Thought to shar...
-
Well we all have been writing the classic JUnit tests from years now but it becomes challenging to write test cases when you dealing w...
-
Here are some of the commonly used FormHandlers, although ATG provides many out of the box FormHandlers and even we can write our own custom...
-
Recently faced couple of issues with running the Purge Service under BCC and had to do some tuning to finally make it work on large vol...
-
Time to explore barebone concepts around Endeca commerce guided search v11.1. It’s vital to understand the key concepts before moving ahe...
-
R ecently installed ATG search 9.3 on local windows machine and configured search environment and index. It was a good fun as it gave quit...