Java - pdfbox无法导入jar?
大家好,请有人帮我解决这个简单问题,我相信...我已经在 java 聊天网站上询问了超过 8 位专家,但似乎没有人可以帮助我:(。 我已经从以下位置下载了 jar 文件 http://pdfbox.apache.org/download.html。 我已经打开 blueJ IDE 并加载了 jars。当我输入时,
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>" );
}
}
Hi there Please can someone help me with this simple problem I believe... I've already asked over 8 experts on a java chat website yet no-one can seem to help me :(.
I have downloaded the jar files from
http://pdfbox.apache.org/download.html.
I have opened blueJ IDE and loaded the jars. When I type in
import org.apache.pdfbox.*;
import org.apache.pdfbox.pdmodel;
import org.apache.pdfbox.pdmodel.PDPage;
I get an error message:
error has occured cannot find org.apache.pdfbox
I have tried netbeans also and gone to project properties and added the jar, I've also gone to the side menu on netbeans and tried that way. I still get the same error. Can someone please help? I've tried this on 3 different pc's.
okay guys to give me more info. I downloaded the jars and put them in a folder in blueJ i went to options and selected the jar files they say 'loaded'. I also did the same in Netbeans, I've shown the IDE where the Jars are it still does not work here is the full code, its just a sample code taken from the PDFBOX website I am trying.
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>" );
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是排序的。我下载的 JAR 文件错误。我检查了文件大小,发现它只有 20kb,而原本应该超过 9mb。谢谢大家!
This is sorted. I was downloading the JAR file wrong. I checked the file size and noticed it was only 20kb when it was meant to be over 9mb. Thank you to everyone !
下载这些 jar 文件后,您对它们做了什么?您是如何将它们添加到您的项目中的? Netbeans 无法猜测 jar 位于您的计算机上的位置,这就是为什么当您导入时它不起作用...将 jar 添加到您的 Netbeans 项目:
假设 jar 文件位于 c:\downloads
并选择项目在 netbeans 中,转到“属性”->“源”并选择“编译”选项卡,然后导航到 jar 所在的位置并添加它们。现在您的导入错误应该已清除。
What did you do with those jar files once you downloaded them? How did you add them to your project? Netbeans cannot guess where on your computer the jars are located, that's why it doens't work when you do import.... Add the jars to your Netbeans project:
Let's say the jar files are in c:\downloads
With the project selected in netbeans, go to Properties->sources and select Compile Tab, then anvigate to where the jars are and add them. Now your import error should be cleared.
我找不到这个“Pdfbox”产品的Javadoc,但我确实找到了一些示例代码,并且似乎没有一个使用
org.apache.pdfbox
中的任何类,而是像org.apache.pdfbox
这样的子包代码>org.apache.pdfbox.pdmodel。现在,知道了这一点,我可以在您的 import 语句中看到两件事错误:如果org.apache.pdfbox
中实际上没有类,并且您没有,第一行将给出您显示的错误需要导入该包;第二行会给出错误,因为`org.apache.pdfbox.pdmodel
本身就是一个包,但您试图将它导入为一个类。我确信这两个问题之一或两者都是您的实际问题。I can't find the Javadocs for this "Pdfbox" product, but I did find some sample code, and none of it seemed to use any classes in
org.apache.pdfbox
, but rather subpackages likeorg.apache.pdfbox.pdmodel
. Now, knowing this, I can see two things wrong in your import statements: the first line will give the error you show if there are in fact no classes inorg.apache.pdfbox
and you don't need to import that package; the second line will give an error because`org.apache.pdfbox.pdmodel
is itself a package, but you're trying to import it as if it's a class. I am sure one of these two issues -- or both -- are your actual problem.