<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://www.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://www.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ù)  更多評論
      

    主站蜘蛛池模板: 亚洲伊人色欲综合网| 亚洲中文字幕无码中文字| 91福利免费体验区观看区| 亚洲一区二区无码偷拍| 亚洲色一色噜一噜噜噜| 国产白丝无码免费视频| 久久精品国产亚洲av品善| 亚洲精品无码成人片久久| 手机在线看永久av片免费| a级毛片免费观看网站| 亚洲人成777在线播放| 亚洲中文无韩国r级电影| 国产在线观看麻豆91精品免费| 99亚洲男女激情在线观看| 久久精品国产亚洲夜色AV网站| 好吊妞在线成人免费| 久久免费美女视频| 国产精品亚洲专区一区| 亚洲黄色免费电影| 国产亚洲午夜高清国产拍精品| 中字幕视频在线永久在线观看免费| aa在线免费观看| 亚洲精品无码少妇30P| 亚洲另类激情综合偷自拍| 亚洲A∨午夜成人片精品网站| 国产91免费在线观看| 中文字幕无码一区二区免费| 亚洲欧美自偷自拍另类视| 亚洲欧洲在线观看| 国产亚洲精午夜久久久久久| 国产大片91精品免费看3| 免费看黄视频网站| 久久中文字幕免费视频| 国产免费福利体检区久久| 亚洲AⅤ男人的天堂在线观看| 亚洲精品亚洲人成在线观看麻豆| 亚洲中文字幕无码一久久区| 免费一级毛片女人图片| 日本午夜免费福利视频| 日本XXX黄区免费看| 日本免费人成视频在线观看|