<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
            近期在項目中使用到了大量的報表開發(fā),需要將html頁面中的表格內(nèi)容導(dǎo)出到pdf word excel和圖片,前三者都比較好實現(xiàn)。唯獨后者生成圖片使用ImageIo操作時生成的圖片有點慘不忍睹。經(jīng)過大量google后發(fā)現(xiàn),pdfbox這個組件不錯,可以將pdf文件輕松生成圖片。這不問題解決了,但在使用過程中不然,受到了很多致命性的打擊。pdfbox在處理中文pdf的時候就會表現(xiàn)的比較脆弱點。但對英文版的pdf導(dǎo)出圖片,那是杠杠的。盡管這樣,還是記錄一下,畢竟這方面的資料很少。我?guī)缀跛驯榱苏麄€google,baidu才搜集到那么一點點資料。這里跟大家分享下。
            所依賴的JAR:
            commons-logging-1.1.1.jar
            fontbox-1.2.1.jar
            pdfbox-1.2.1.jar
            示例代碼:
    /*
     * Licensed to the Apache Software Foundation (ASF) under one or more
     * contributor license agreements.  See the NOTICE file distributed with
     * this work for additional information regarding copyright ownership.
     * The ASF licenses this file to You under the Apache License, Version 2.0
     * (the "License"); you may not use this file except in compliance with
     * the License.  You may obtain a copy of the License at
     *
     *      
    http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     
    */

    package com.future.pdfbox.image;

    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;

    import javax.imageio.IIOImage;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageWriter;
    import javax.imageio.stream.ImageOutputStream;

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

    public class ExtractImages 
    {
        
    public static void main(String[] args) throws IOException 
            PDDocument doc 
    = PDDocument.load("F:\\1.pdf");
            
    int pageCount = doc.getPageCount(); 
            System.out.println(pageCount); 
            List pages 
    = doc.getDocumentCatalog().getAllPages(); 
            
    for(int i=0;i<pages.size();i++){
                PDPage page 
    = (PDPage)pages.get(i); 
                BufferedImage image 
    = page.convertToImage(); 
                Iterator iter 
    = ImageIO.getImageWritersBySuffix("jpg"); 
                ImageWriter writer 
    = (ImageWriter)iter.next(); 
                File outFile 
    = new File("C:/"+i+".jpg"); 
                FileOutputStream out 
    = new FileOutputStream(outFile); 
                ImageOutputStream outImage 
    = ImageIO.createImageOutputStream(out); 
                writer.setOutput(outImage); 
                writer.write(
    new IIOImage(image,null,null)); 
            }

            doc.close(); 
            System.out.println(
    "over"); 
        }


    }


            
    posted on 2010-07-23 08:46 雪山飛鵠 閱讀(11369) 評論(7)  編輯  收藏 所屬分類: javase

    Feedback

    # re: 輕松使用apache pdfbox將pdf文件生成圖片 2010-07-23 09:25 fengzl
    html轉(zhuǎn)pdf word excel和圖片不是那么容易的吧  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片 2010-07-23 13:19 cxh8318
    對于中文的pdf支持是脆弱點嗎?我看壓根就不支持嘛  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片 2010-07-23 13:31 雪山飛鵠
    @cxh8318
    我說過了,對于中文pdf目前那是相當(dāng)?shù)拇嗳酰W(wǎng)上搜了,說是這是源代碼的bug,期待下一個版本能夠改進(jìn)過來,但對英文版的pdf支持絕對完美,我在測試的時候?qū)⒂⑽陌娴膕pring參考手冊全部順利生成了jpg圖片,雖然控制臺有警告但不礙事的。比一般的工具軟件強(qiáng)悍多了。  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片 2010-07-23 20:19 cxh8318
    恩,對英文pdf轉(zhuǎn)換確實很強(qiáng)  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片[未登錄] 2010-07-26 09:21 conjs
    我可以轉(zhuǎn),HTML DOC,XLS,PPT,PDF,JPG 都可以轉(zhuǎn)  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片 2013-05-27 18:28 acmersch
    內(nèi)存溢出是什么問題  回復(fù)  更多評論
      

    # re: 輕松使用apache pdfbox將pdf文件生成圖片[未登錄] 2014-07-24 17:21 h
    姓名,,轉(zhuǎn)出來變成 姓姓,其他也是這樣。。重復(fù)第一個字  回復(fù)  更多評論
      

    主站蜘蛛池模板: 国产av无码专区亚洲av毛片搜| 亚洲国产美女福利直播秀一区二区| 亚洲中文字幕一二三四区苍井空| 日韩精品人妻系列无码专区免费| 亚洲AV无码国产在丝袜线观看| 国内精品免费久久影院| 亚洲国产精品一区二区第一页| 中文字幕无线码中文字幕免费| 亚洲国产精彩中文乱码AV| 久久香蕉国产线看免费| 亚洲手机中文字幕| 妞干网在线免费观看| 日韩精品亚洲专区在线影视| 亚洲精品成人久久久| 中文在线观看永久免费| 久久99国产亚洲精品观看| 亚洲高清免费在线观看| 亚洲中文字幕无码mv| 国产一精品一aⅴ一免费| 一出一进一爽一粗一大视频免费的| 中文亚洲AV片在线观看不卡 | 青青在线久青草免费观看| 亚洲国产精品久久人人爱| 在线A级毛片无码免费真人| 爱情岛论坛免费视频| 亚洲gv猛男gv无码男同短文| 毛片无码免费无码播放 | 亚洲国产精品日韩在线| 国产成人综合久久精品免费| 国产免费MV大全视频网站| 亚洲色图在线观看| 成人奭片免费观看| 成人免费夜片在线观看| 亚洲国产人成在线观看69网站| 好爽又高潮了毛片免费下载| 特黄特色的大片观看免费视频| 久久久久亚洲AV片无码| 国产成人无码免费视频97| 久久永久免费人妻精品| 亚洲中文字幕久久精品无码A| 国产亚洲精午夜久久久久久|