簡體   English   中英

我正在嘗試使用 PDF Box 加載 PDF,但是 PDF 無法打開。 我不確定我的代碼有什么問題

[英]I'm trying to load a PDF using PDF Box however, the PDF just wont open. I'm not sure whats wrong in my code

“我不確定這里到底是什么問題,所以如果有人有任何建議,請隨時向我提出建議。我全神貫注!”

     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {         
      try {                                      
        //Loading an existing PDF document
        File file = new File("C:\\Users\\Cayde\\OneDrive\\Desktop");
        PDDocument document = PDDocument.load(file);

        //Instantiating the PDFRenderer class
        PDFRenderer renderer = new PDFRenderer(document);

        //Rendering an image from the PDF document
        BufferedImage image = renderer.renderImage(0);

        try {
            //Writing the image to a file
            ImageIO.write(image, "JPEG", new File("C:\\Users\\Cayde\\OneDrive\\Desktop\\Open"));
        } catch (IOException ex) {
            Logger.getLogger(AFTO781.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println("Image created");

        //Closing the document
        document.close();
    } catch (IOException ex) {
        Logger.getLogger(AFTO781.class.getName()).log(Level.SEVERE, null, ex);
    }                               

"C:\\\\Users\\\\Cayde\\\\OneDrive\\\\Desktop"很可能是一個目錄。 您的文件可能命名為"C:\\\\Users\\\\Cayde\\\\OneDrive\\\\Desktop\\\\myfile.pdf"

您保存圖像的文件很可能也是一個目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM