PDFBox 1.8.x
import org.apache.pdfbox.pdfparser.PDFStreamParser;
import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.util.PDFOperator;
import java.util.ArrayList;
import java.util.List;
/**
* This is an example on how to remove all text from PDF document.
*
* Usage: java org.apache.pdfbox.examples.util.RemoveAllText <input-pdf> <output-pdf>
*
* @author Ben Litchfield
* @version $Revision: 1.2 $
*/
public class RemoveAllText
{
/**
* Default constructor.
*/
private RemoveAllText()
{
//example class should not be instantiated
}
/**
* This will remove all text from a PDF document.
*
* @param args The command line arguments.
*
* @throws Exception If there is an error parsing the document.
*/
public static void main( String[] args ) throws Exception
{
if( args.length != 2 )
{
usage();
}
else
{
PDDocument document = null;
try
{
document = PDDocument.load( args[0] );
if( document.isEncrypted() )
{
System.err.println( "Error: Encrypted documents are not supported for this example." );
System.exit( 1 );
}
List allPages = document.getDocumentCatalog().getAllPages();
for( int i=0; i
" );
}
}