Find x,y position of last line in pdf file - itextsharp

半腔热情 提交于 2019-12-25 05:18:08

问题


I want to add an image to a pdf file. the position of the image should be just above the last line in a pdf file.

How do I get the x,y position of the last line in the pdf or the x,y position of the end of the last text block.


回答1:


Look for an object named TextMarginFinder and use it like is done in this Java example: ShowTextMargins

public void addMarginRectangle(String src, String dest)
    throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    PdfReaderContentParser parser = new PdfReaderContentParser(reader);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
    TextMarginFinder finder;
    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        finder = parser.processContent(i, new TextMarginFinder());
        PdfContentByte cb = stamper.getOverContent(i);
        cb.rectangle(finder.getLlx(), finder.getLly(),
            finder.getWidth(), finder.getHeight());
        cb.stroke();
    }
    stamper.close();
    reader.close();
}


来源:https://stackoverflow.com/questions/12515968/find-x-y-position-of-last-line-in-pdf-file-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!