[英]Creating a .jar out of java source won't work
Java is absolutely unknown for me. Java对我来说绝对是未知的。
I want to use a tool called PDFBox to extract text from a certain area using PHP. 我想使用一个称为PDFBox的工具来使用PHP从特定区域提取文本。
The default jar won't allow me to select a certain area to extract text so I decided to take the ExtractTextByArea.java and make a .jar out of it, where I can input my own parameters in PHP to get the desired text. 默认的jar不允许我选择某个区域来提取文本,因此我决定从ExtractTextByArea.java中提取一个.jar,然后在PHP中输入自己的参数以获取所需的文本。
This is the .java from the site: 这是来自站点的.java:
package org.apache.pdfbox.examples.util;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripperByArea;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
/**
* This is an example on how to extract text from a specific area on the PDF document.
*
* @author Ben Litchfield
*/
public final class ExtractTextByArea
{
private ExtractTextByArea()
{
//utility class and should not be constructed.
}
/**
* This will print the documents text in a certain area.
*
* @param args The command line arguments.
*
* @throws IOException If there is an error parsing the document.
*/
public static void main( String[] args ) throws IOException
{
if( args.length != 1 )
{
usage();
}
else
{
PDDocument document = null;
try
{
document = PDDocument.load( new File(args[0]) );
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition( true );
Rectangle rect = new Rectangle( 10, 280, 275, 60 );
stripper.addRegion( "class1", rect );
PDPage firstPage = document.getPage(0);
stripper.extractRegions( firstPage );
System.out.println( "Text in the area:" + rect );
System.out.println( stripper.getTextForRegion( "class1" ) );
}
finally
{
if( document != null )
{
document.close();
}
}
}
}
/**
* This will print the usage for this document.
*/
private static void usage()
{
System.err.println( "Usage: java " + ExtractTextByArea.class.getName() + " <input-pdf>" );
}
}
I made a .jar out of it but when I execute it, the CMD says: 我用它制作了一个.jar,但是执行时,CMD会说:
Error: main class not found
I don't know how to keep going. 我不知道该如何继续。
Use java -cp ExtractTextByArea.jar org.apache.pdfbox.examples.util.ExtractTextByArea
使用
java -cp ExtractTextByArea.jar org.apache.pdfbox.examples.util.ExtractTextByArea
If the class is not in a package then simply java -cp ExtractTextByArea.jar ExtractTextByArea
如果该类不在软件包中,则只需
java -cp ExtractTextByArea.jar ExtractTextByArea
If you are not within the directory where ExtractTextByArea.jar
is located, then you can do: 如果您不在
ExtractTextByArea.jar
所在的目录中,则可以执行以下操作:
On Unix or Linux platforms: 在Unix或Linux平台上:
java -cp /location_of_jar/ExtractTextByArea.jar org.apache.pdfbox.examples.util.ExtractTextByArea
On Windows: 在Windows上:
java -cp [D]:\location_of_jar\org.apache.pdfbox.examples.util..jar org.apache.pdfbox.examples.util.ExtractTextByArea
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.