I am trying to underline justified test in a pdf with itextpdf and I think I have uncovered a bug, and I'd really like a work around.
When I call getBaseline() as described on the mailing lists the underline extends far passed the end of the text into the next column.
float lx = renderInfos.get(i).getBaseline().getStartPoint().get(0);
float rx = renderInfos.get(i).getBaseline().getEndPoint().get(0);
You can download the original pdf from the publisher's website
thanks!
I have seen this on all versions of itextpdf I have tried, from 4.1.0
to the most recent 5.5.0
.
It would take some effort to separate the underlining code from other proprietary code that I cannot share. If you think it would help, I can do that.
If this is a bug, is there an issue tracker I can log it with?
PS (mkl): Here a short code fragment to reproduce the issue:
PdfReader reader = new PdfReader(...);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(...));
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
final List<TextRenderInfo> infos = new ArrayList<TextRenderInfo>();
PdfTextExtractor.getTextFromPage(reader, page, new TextExtractionStrategy()
{
public void renderText(TextRenderInfo renderInfo)
{
infos.add(renderInfo);
}
public void renderImage(ImageRenderInfo renderInfo) { }
public void endTextBlock() { }
public void beginTextBlock() { }
public String getResultantText() { return "";}
});
PdfContentByte content = stamper.getOverContent(page);
for (TextRenderInfo info : infos)
{
float lx = info.getBaseline().getStartPoint().get(0);
float rx = info.getBaseline().getEndPoint().get(0);
float y = info.getBaseline().getEndPoint().get(1);
content.moveTo(lx, y);
content.lineTo(rx, y);
content.stroke();
}
}
stamper.close();