Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSDocument


            textFile = pdfFile.substring( 0, pdfFile.length() -4 ) + ".txt";
        }

        InputStream input = null;
        Writer output = null;
        COSDocument document = null;
        try
        {
            input = new FileInputStream( pdfFile );
            long start = System.currentTimeMillis();
            document = parseDocument( input );
            long stop = System.currentTimeMillis();
            LOG.info( "Time to parse time=" + (stop-start) );


            //document.print();
            if( document.isEncrypted() )
            {
                try
                {
                    DecryptDocument decryptor = new DecryptDocument( document );
                    decryptor.decryptDocument( password );
                }
                catch( InvalidPasswordException e )
                {
                    if( args.length == 4 )//they supplied the wrong password
                    {
                        System.err.println( "Error: The supplied password is incorrect." );
                        System.exit( 2 );
                    }
                    else
                    {
                        //they didn't suppply a password and the default of "" was wrong.
                        System.err.println( "Error: The document is encrypted." );
                        usage();
                    }
                }
            }
            if( toConsole )
            {
                output = new OutputStreamWriter( System.out );
            }
            else
            {
                output = new OutputStreamWriter(
                    new FileOutputStream( textFile ), encoding );
            }

            start = System.currentTimeMillis();
            stripper.writeText( document, output );
            stop = System.currentTimeMillis();
            LOG.info( "Time to extract text time=" +(stop-start) );
        }
        finally
        {
            if( input != null )
            {
                input.close();
            }
            if( output != null )
            {
                output.close();
            }
            if( document != null )
            {
                document.close();
            }
        }
    }
View Full Code Here


            try
            {
                parser = new PDFParser( new FileInputStream( infile ) );
                parser.parse();
                COSDocument document = parser.getDocument();

                if( document.isEncrypted() )
                {
                    DecryptDocument decryptor = new DecryptDocument( document );
                    decryptor.decryptDocument( password );

                    COSWriter writer = new COSWriter( new FileOutputStream( outfile ) );
View Full Code Here

     * @throws Exception If there is an error importing the FDF document.
     */
    public static void main(String[] args) throws Exception
    {
        PDDocument pdf = null;
        COSDocument fdf = null;
        FileInputStream pdfStream = null;
        FileInputStream fdfStream = null;
        FileOutputStream output = null;
        PDFParser pdfParser = null;
        PDFParser fdfParser = null;
View Full Code Here

     *
     * @throws IOException If there is an error creating this document.
     */
    public PDDocument() throws IOException
    {
        document = new COSDocument();

        //First we need a trailer
        COSDictionary trailer = new COSDictionary();
        document.setTrailer( trailer );

View Full Code Here

    /* @see de.spotnik.mail.server.mail.content.AbstractContentHandler#getContent(javax.mail.Part) */
    @Override
    public String getContent( Part part) throws IOException, MessagingException
    {
        LOG.debug("parsing PDF document");
        COSDocument cosDoc = parseDocument(part.getInputStream());
        String docText = "";
       
        if( !cosDoc.isEncrypted())
        {
            // extract PDF document's textual content
            try
            {
                PDFTextStripper stripper = new PDFTextStripper();
                docText = stripper.getText(new PDDocument(cosDoc));
            }
            finally
            {
                try
                {
                    cosDoc.close();
                }
                catch( IOException e)
                {
                    // do nothing
                    LOG.debug(e);
View Full Code Here

TOP

Related Classes of org.pdfbox.cos.COSDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.