簡體   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