在pdf中查找所选矩形的坐标

时间:2015-01-21 07:49:29

标签: java

我正在使用pdf框将pdf页面转换为图像并将这些图像添加到jframe。我使用paint方法在jframe中绘制矩形并得到矩形的坐标。我的要求是使用这些坐标我必须清理pdf中的文字。对于我写下面的逻辑,但它不能正常工作。我认为我所选择的坐标与迭代矩形坐标不同。请给出一个解决方案。

public void manipulatePdf(String src,String 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();

}  

1 个答案:

答案 0 :(得分:0)

对这些对象不是很熟悉,但乍一看似乎有一些问题在线上&#34; float ury = page.getHeight() - selectRect.y;&#34; 。你想使用&#39; page.y&#39;相反!!