aspose file tools*
The moose likes Beginning Java and the fly likes Arivazhagan Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arivazhagan" Watch "Arivazhagan" New topic
Author

Arivazhagan

Arivazhagan ranganathan
Greenhorn

Joined: Aug 09, 2008
Posts: 1
Hello sir i am trying to develop a application to extract the text messages from a pdf file but i got the error massage as below

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.pdfbox.util.operator.OperatorProcessor.setContext(Lorg/pdfbox/util/PDFStreamEngine V
at org.pdfbox.util.PDFStreamEngine.registerOperatorProcessor(PDFStreamEngine.java:140)
at org.pdfbox.util.PDFStreamEngine.<init>(PDFStreamEngine.java:123)
at org.pdfbox.util.PDFTextStripper.<init>(PDFTextStripper.java:119)
at PdfToText.pdfToText(PdfToText.java:47)
at ConstrutorDeTemplate2.chamaConversor(ConstrutorDeTemplate2.java:216)
at ConstrutorDeTemplate2.actionPerformed(ConstrutorDeTemplate2.java:75)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
at java.awt.Component.processEvent(Component.java:5818)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:697)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:962)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:834)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:661)
at java.awt.Component.dispatchEventImpl(Component.java:4285)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)



My program is below

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;


// Java extension packages
import javax.swing.*;

import org.pdfbox.*;


public class ConstrutorDeTemplate2 extends JFrame
implements ActionListener {

private JTextField enterField;
private JTextArea outputArea;
private BufferedWriter out;
private String word;

private PdfToText conversor = new PdfToText();


// ajusta a interface do usu�rio
public ConstrutorDeTemplate2()
{
super( "Testing class File" );

enterField = new JTextField("Digite aqui o nome do arquivo :" );
enterField.addActionListener( this );
outputArea = new JTextArea();

ScrollPane scrollPane = new ScrollPane();
scrollPane.add( outputArea );

Container container = getContentPane();
container.add( enterField, BorderLayout.NORTH );
container.add( scrollPane, BorderLayout.CENTER );

setSize( 400, 400 );
show();
}

// Exibe as informa��es sobre o arquivo especificado pelo usu�rio
public void actionPerformed( ActionEvent actionEvent )
{
File name = new File( actionEvent.getActionCommand() );

// Se o arquivo existe, envia para a sa�da as informa��es sobre ele
if ( name.exists() ) {
outputArea.setText(
name.getName() + " exists\n" +
( name.isFile () ?
"is a file\n" : "is not a file\n" ) +
( name.isDirectory() ?
"is a directory\n" : "is not a directory\n" ) +
( name.isAbsolute() ? "is absolute path\n" :
"is not absolute path\n" ) +
"Last modified: " + name.lastModified() +
"\nLength: " + name.length () +
"\nPath: " + name.getPath() +
"\nAbsolute path: " + name.getAbsolutePath() +
"\nParent: " + name.getParent() );

// informa��o de sa�da se "name" � um arquivo
if ( name.isFile() ) {

String nameString = String.valueOf(name.getPath());
String nameTeste = new String(nameString);


if (nameString.endsWith(".pdf"))

nameTeste = chamaConversor(nameString);

else
{
if (nameString.endsWith(".doc"))
nameTeste = chamaConversor(nameString); // chama conversor de arquivos DOC
else
if (nameString.endsWith(".txt"))
nameTeste = nameString;
}


// se o arquivo termina com ".txt"
if (nameTeste.endsWith(".txt"))
{


// acrescenta conte�do do arquivo � �rea de sa�da

try {
// Create the tokenizer to read from a file
FileReader rd = new FileReader(nameTeste);
StreamTokenizer st = new StreamTokenizer(rd);

// Prepare the tokenizer for Java-style tokenizing rules
st.parseNumbers();
st.wordChars('_', '_');
st.eolIsSignificant (true);

// If whitespace is not to be discarded, make this call
st.ordinaryChars(0, ' ');

// These calls caused comments to be discarded
st.slashSlashComments(true);
st.slashStarComments(true);

// Parse the file
int token = st.nextToken();
String word_ant = "";
outputArea.append( " \n" );
out = new BufferedWriter(new FileWriter(nameTeste, true));

while (token != StreamTokenizer.TT_EOF) {
token = st.nextToken();

if (token == StreamTokenizer.TT_EOL){
//out.write(word);
out.flush();
out = new BufferedWriter(new FileWriter(nameTeste, true));
//outputArea.append( word + "\n" );
// out.append ( "\n" );
}

switch (token) {

case StreamTokenizer.TT_NUMBER:
// A number was found; the value is in nval
double num = st.nval;
break;
case StreamTokenizer.TT_WORD:
// A word was found; the value is in sval
word = st.sval;
// if (word_ant.equals("a") || word_ant.equals("an") || word_ant.equals("the") || word_ant.equals("The") || word_ant.equals("An"))
// {
outputArea.append( word.toString() + " \n " );
// out.append( word + " " );
// }

// word_ant = word;
break;
case '"':
// A double-quoted string was found; sval contains the contents
String dquoteVal = st.sval;
break;
case '\'':
// A single-quoted string was found; sval contains the contents
String squoteVal = st.sval;
break;
case StreamTokenizer.TT_EOL:
// End of line character found
break;
case StreamTokenizer.TT_EOF:
// End of file has been reached
break;
default:
// A regular character was found; the value is the token itself
char ch = (char)st.ttype;
break;
} // fim do switch
} // fim do while

rd.close();
out.close();
} // fim do try


// process file processing problems
catch( IOException ioException ) {
JOptionPane.showMessageDialog( this,
"FILE ERROR",
"FILE ERROR", JOptionPane.ERROR_MESSAGE );
}

} // fim do if da linha 92 - testa se o arquivo � do tipo texto

} // fim do if da linha 78 - testa se � um arquivo

// output directory listing
else if ( name.isDirectory() ) {
String directory[] = name.list();

outputArea.append( "\n\nDirectory contents:\n");

for ( int i = 0; i < directory.length; i++ )
outputArea.append( directory[ i ] + "\n" );
} // fim do else if da linha 184 - testa se � um diret�rio


} // fim do if da linha 62 - testa se o arquivo existe

// not file or directory, output error message
else {
JOptionPane.showMessageDialog( this,
actionEvent.getActionCommand() + " Does Not Exist",
"ERROR", JOptionPane.ERROR_MESSAGE );
}

} // fim do m�todo actionPerformed



// m�todo que chama o conversor

public String chamaConversor(String arquivoPdf){

String arquivoTxt = new String(arquivoPdf);

arquivoTxt = arquivoPdf.replace(".pdf", ".txt");

try {

conversor.pdfToText(arquivoPdf,arquivoTxt);

}
catch (Exception ex) {
ex.printStackTrace();
}


return (arquivoTxt);
}



// executa a aplica��o
public static void main( String args[] )
{
ConstrutorDeTemplate2 application = new ConstrutorDeTemplate2();

application.setDefaultCloseOperation (
JFrame.EXIT_ON_CLOSE );
} // fim do m�todo main

} // fim da classe ExtratorDeSubstantivos2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

1) UseCodeTags. That will preserve your formatting, so it will be more readable. For instance:


2) UseAMeaningfulSubjectLine. Your name definitely isn't.

3) CarefullyChooseOneForum. Although you're using Swing in your application, that's irrelevant for your error.


As for the answer, your error message clearly mentions that method setContent(org/pdfbox/util/PDFStreamEngine) does not exist within class org.pdfbox.util.operator.OperatorProcessor.

Now I've checked the Javadoc, and the method is most certainly there. However, I've seen this error before, in fact even just yesterday, and I found out how it happened with me.

I compiled with one version of a library, which had a certain method. However, a previous version of that library, without that method, had precedence in the class loading.

Check your classpath, and even the lib\ext folder of your Java installation, if there is an older version of the PDFBox library.
[ August 09, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: Arivazhagan