Package org.jpedal.tools
Class PdfOptimizer
java.lang.Object
org.jpedal.tools.PdfOptimizer
Utility class with static methods to optimize PDF files
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
closePDF()
Closes the PDF file that is current loadedbyte[]
Create a new PDF from the result of the original final after any optimizations have been performed.void
Load a PDF file to be optimizedstatic void
Optimize a PDF and save the output to the specified file.static void
optimizePDF
(File input, File output) Save a copy of the specified file after optimization.static void
optimizePDF
(File input, File output, List<PdfOptimizer.Optimization> optimizations) Save a copy of the specified file after optimization.static void
optimizePDF
(File input, File output, PdfOptimizer.Optimization optimization) Save a copy of the specified file after optimization.void
Remove any unused object from the PDF and flag the objects as free in the files xref tablevoid
writeoptimizedFileToStream
(OutputStream outputStream) Write the optimized file to the provided stream.
-
Constructor Details
-
PdfOptimizer
public PdfOptimizer()
-
-
Method Details
-
loadFile
Load a PDF file to be optimized- Parameters:
input
- File object for the PDF to be optimized- Throws:
IOException
- Thrown if the file is corrupted or invalid in some way
-
closePDF
Closes the PDF file that is current loaded- Throws:
IOException
- Thrown if an I/O error occurs
-
getoptimizedFileAsBytes
Create a new PDF from the result of the original final after any optimizations have been performed.- Returns:
- The optimized file as a byte array
- Throws:
IOException
- Thrown if an I/O error occurs
-
writeoptimizedFileToStream
Write the optimized file to the provided stream.- Parameters:
outputStream
- OutputStream the optimised file is written to- Throws:
IOException
- Thrown if an I/O error occurs
-
optimizePDF
public static void optimizePDF(File input, File output, List<PdfOptimizer.Optimization> optimizations) throws IOException Save a copy of the specified file after optimization. The file will be optimized using the specified optimizations- Parameters:
input
- File object representing the PDF containing formsoutput
- File object representing where the modified PDF should be savedoptimizations
- a list of all the optimizations to perform- Throws:
IOException
- if an I/O error occurs during writing
-
optimizePDF
public static void optimizePDF(File input, File output, PdfOptimizer.Optimization optimization) throws IOException Save a copy of the specified file after optimization. The file will be optimized using the specified optimization- Parameters:
input
- File object representing the PDF containing formsoutput
- File object representing where the modified PDF should be savedoptimization
- the optimization to perform- Throws:
IOException
- if an I/O error occurs during writing
-
optimizePDF
Save a copy of the specified file after optimization. The file will be optimized using all currently available optimization options which may change over time.- Parameters:
input
- File object representing the PDF containing formsoutput
- File object representing where the modified PDF should be saved- Throws:
IOException
- if an I/O error occurs during writing
-
removeUnusedObjects
Remove any unused object from the PDF and flag the objects as free in the files xref table- Throws:
IOException
- if an I/O error occurs
-
main
Optimize a PDF and save the output to the specified file. The file will be optimized using all currently available optimization options which may change over time.- Parameters:
args
- Expects a String array of 2 values. the first being the filename for the input PDF, and the second being the filename for the output
-