2015-01-21 86 views
0

我使用pdf格式將PDF頁面轉換爲圖像並將這些圖像添加到jframe中。我使用繪圖方法在jframe中繪製矩形並獲得了矩形的座標。我的要求是使用這些座標我必須清理pdf中的文本。對於我在邏輯下面寫的內容,但它不能正常工作。我認爲我選擇的座標不同於迭代矩形座標,請給出解決方案。查找所選矩形的座標pdf

公共無效manipulatePdf(SRC字符串,字符串DEST, java.awt.Rectangle中selectRect)拋出IOException異常, DocumentException {

PdfReader reader = new PdfReader(src); 
    Rectangle page = reader.getBoxSize(1, "media"); 

    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); 
    List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>(); 

    float lly = page.getHeight() - selectRect.height; 
    float ury = page.getHeight() - selectRect.y; 
    System.out.println("new pagesize" + lly + " " + ury); 
    cleanUpLocations.add(new PdfCleanUpLocation(1, new Rectangle(0f, lly, 
      page.getWidth(), ury), BaseColor.GRAY)); 

    PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, 
      stamper); 

    cleaner.cleanUp(); 
    stamper.close(); 
    reader.close(); 

} 

回答

0

沒有多少熟悉這些對象,但乍一看似乎有一些問題在行「float ury = page.getHeight() - selectRect.y;」 。你想使用'page.y'來代替!

+0

不,通過計算伊利,烏里我得到錯誤的結果,所以請告訴我如何計算這些。 – amar 2015-01-21 08:31:58