01: package com.etymon.pj.samples;
02:
03: import java.io.*;
04: import java.util.*;
05: import com.etymon.pj.*;
06: import com.etymon.pj.exception.*;
07: import com.etymon.pj.object.*;
08:
09: /**
10: Demonstrates uncompressing flate-compressed streams in a PDF file.
11: @author Nassib Nassar
12: */
13: public class UncompressPdf {
14:
15: public static void main(String args[]) {
16: if (args.length < 2) {
17: System.out.println("UncompressPdf [infile] [outfile]");
18: return;
19: }
20: String infile = args[0];
21: String outfile = args[1];
22: System.out
23: .println("This creates a new version of a PDF file and uncompresses");
24: System.out.println("any flate-compressed streams.");
25: try {
26: System.out.println("Reading and parsing input file...");
27:
28: // load the infile
29: Pdf pdf = new Pdf(infile);
30:
31: System.out.println("Got it.");
32:
33: if (pdf.getEncryptDictionary() != null) {
34: System.out.println("File appears to be encrypted.");
35: }
36:
37: int y = pdf.getMaxObjectNumber();
38:
39: for (int x = 1; x <= y; x++) {
40: PjObject obj = pdf.getObject(x);
41: if (obj instanceof PjStream) {
42: try {
43: pdf.registerObject(((PjStream) obj)
44: .flateDecompress(), x);
45: } catch (InvalidPdfObjectException e) {
46: }
47: }
48:
49: }
50:
51: System.out.println("Writing modified output file...");
52:
53: pdf.writeToFile(outfile);
54:
55: System.out.println("Done.");
56: } catch (PjException pje) {
57: System.out.println(pje);
58: } catch (IOException ioe) {
59: System.out.println(ioe);
60: }
61: }
62:
63: }
|