繁体   English   中英

Java - pdfbox无法导入jar?

[英]Java - pdfbox cannot import jar?

嗨,请有人帮我解决这个简单的问题我相信...我已经在java聊天网站上询问过8位专家但是没有人可以帮助我:(。我从http下载了jar文件: //pdfbox.apache.org/download.html 。我打开了blueJ IDE并加载了jar。当我输入时

import org.apache.pdfbox.*; 
import org.apache.pdfbox.pdmodel; 
import org.apache.pdfbox.pdmodel.PDPage; 

我收到一条错误消息:

error has occured cannot find org.apache.pdfbox

我也试过netbeans并且去了项目属性并添加了jar,我也去了netbeans的侧边菜单并尝试了这种方式。 我仍然得到同样的错误。 有人可以帮忙吗? 我在3台不同的电脑上试过这个。

好的家伙给我更多信息。 我下载了罐子并将它们放在blueJ的文件夹中我去了选项并选择了他们说'加载'的jar文件。 我也在Netbeans中做了同样的事情,我已经展示了IDE,其中Jars仍然不起作用,这里是完整的代码,它只是从我正在尝试的PDFBOX网站上获取的示例代码。

import org.apache.pdfbox.exceptions.*;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;

/**
 * This will create a blank PDF and write the contents to a file.
  */
public class CreateBlankPDF
{

/**
 * This will create a blank PDF and write the contents to a file.
 *
 * @param file The name of the file to write to.
 *
 * @throws IOException If there is an error writing the data.
 * @throws COSVisitorException If there is an error while generating the document.
 */
public void create( String file ) throws IOException, COSVisitorException
{
    PDDocument document = null;
    try
    {
        document = new PDDocument();
        //Every document requires at least one page, so we will add one
        //blank page.
        PDPage blankPage = new PDPage();
        document.addPage( blankPage );
        document.save( file );
    }
    finally
    {
        if( document != null )
        {
            document.close();
        }
    }
}

/**
 * This will create a blank document.
 *
 * @param args The command line arguments.
 *
 * @throws IOException If there is an error writing the document data.
 * @throws COSVisitorException If there is an error generating the data.
 */
public static void main( String[] args ) throws IOException, COSVisitorException
{
    if( args.length != 1 )
    {
        usage();
    }
    else
    {
        CreateBlankPDF creator = new CreateBlankPDF();
        creator.create( args[0] );
    }
}

/**
 * This will print the usage of this class.
 */
private static void usage()
{
    System.err.println( "usage: java org.apache.pdfbox.examples.pdmodel.CreateBlankPDF <outputfile.pdf>" );
}

}

这是排序的。 我正在下载JAR文件错误。 我检查了文件大小,注意到它只有20kb,当它意味着超过9mb。 谢谢大家!

下载后,您对这些jar文件做了什么? 你是如何将它们添加到项目中的? Netbeans无法猜出你的计算机上的罐子位于哪里,这就是为什么它在你导入时不起作用....将罐子添加到你的Netbeans项目中:

假设jar文件位于c:\\ downloads中

在netbeans中选择项目后,转到Properties-> sources并选择Compile Tab,然后转到jar所在的位置并添加它们。 现在应该清除导入错误。

我无法找到的Javadoc这个“PDFBOX”的产品,但我没有找到一些示例代码,没有它似乎使用任何类org.apache.pdfbox ,而是像子包org.apache.pdfbox.pdmodel 现在,知道这一点,我可以在import语句中看到两个错误:如果org.apache.pdfbox中实际上没有类,并且您不需要导入该包,则第一行将显示您显示的错误; 第二行会出错,因为`org.apache.pdfbox.pdmodel本身就是一个包,但你试图导入它就像它是一个类一样。 我确信这两个问题中的一个 - 或两者 - 都是你的实际问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM