【发布时间】:2011-11-18 03:36:21
【问题描述】:
嗨,请有人帮我解决这个简单问题,我相信...我已经在 java 聊天网站上询问了 8 位专家,但似乎没有人能帮助我:( . 我已经从 http://pdfbox.apache.org/download.html。 我打开了 blueJ IDE 并加载了罐子。当我输入时
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 台不同的电脑上试过了。
好的,伙计们给我更多信息。我下载了 jar 并将它们放在 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”时,你的意思是你已经将它添加到构建路径中了吗?
-
是的,我已将其添加到 Netbeans 的编译时库中
标签: java pdf netbeans pdfbox bluej