亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PDF Box Reader 中獲取當前頁碼

在 PDF Box Reader 中獲取當前頁碼

弒天下 2022-07-06 17:23:38
我正在嘗試使用 PDF 框閱讀器獲取當前頁面。聽到的是我寫的代碼。公共類 PDFTextExtractor{ArrayList extractText(String fileName) 拋出異常 {PDDocument document = null;try {    document = PDDocument.load( new File(fileName) );    PDFTextAnalyzer stripper = new PDFTextAnalyzer();    stripper.setSortByPosition( true );    stripper.setStartPage( 0 );    stripper.setEndPage( document.getNumberOfPages() );    Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());    stripper.writeText(document, dummy);    return stripper.getCharactersList();}finally {    if( document != null ) {        document.close();    }}}當我試圖獲取詳細信息時,我正在編寫以下代碼。public class PDFTextAnalyzer extends PDFTextStripper {    public PDFTextAnalyzer() throws IOException {        super();        // TODO Auto-generated constructor stub    }    private ArrayList<CharInfo> charactersList = new ArrayList<CharInfo>();    public ArrayList<CharInfo> getCharactersList() {        return charactersList;    }    public void setCharactersList(ArrayList<CharInfo> charactersList) {        this.charactersList = charactersList;    }    @Override    protected void writeString(String string, List<TextPosition> textPositions)            throws IOException {        System.out.println("----->"+document.getPages().getCount());/*      for(int i = 0 ; i < document.getPages().getCount();i++)        {        */        float docHeight = +document.getPage(1).getMediaBox().getHeight();        for (TextPosition text : textPositions) {            /*             * System.out.println((int)text.getUnicode().charAt(0)+" "+text.             * getUnicode()+ " [(X=" + text.getXDirAdj()+" "+text.getX() + ",Y="             * + text.getYDirAdj() + ") height=" + text.getHeightDir() +             * " width=" + text.getWidthDirAdj() + "]");             */            );        }但我無法獲取頁碼。請參閱行注釋“當前文本的頁碼”。有沒有辦法獲取頁碼。
查看完整描述

1 回答

?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

this.getCurrentPageNo()怎么樣?



查看完整回答
反對 回復 2022-07-06
  • 1 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號