public void doIt(String in,
String out) throws IOException, COSVisitorException {
PDDocument doc = null;
try
{
doc = PDDocument.load( in );
if( doc.isEncrypted() )
{
try
{
doc.decrypt( "" );
}
catch( InvalidPasswordException e )
{
System.err.println( "Error: The document is encrypted." );
}
catch( org.apache.pdfbox.exceptions.CryptographyException e )
{
e.printStackTrace();
}
}
for (Iterator i = doc.getDocument().getObjects().iterator(); i.hasNext();)
{
COSBase base = ((COSObject) i.next()).getObject();
if (base instanceof COSStream)
{
// just kill the filters
COSStream cosStream = (COSStream)base;
cosStream.getUnfilteredStream();
cosStream.setFilters(null);
}
}
doc.save( out );
}
finally
{
if( doc != null )
{
doc.close();
}
}
}
This will perform the document reading, decoding and writing. |