Home Porting from itextsharp to itext 7 - Why is itext7 giving me a slightly larger value for the Height of text for the same PDF?
Reply: 0

Porting from itextsharp to itext 7 - Why is itext7 giving me a slightly larger value for the Height of text for the same PDF?

user1298
1#
user1298 Published in April 23, 2018, 9:33 am

I am in the process of porting my code to itext 7. While running some unit tests, I noticed that there was a difference of about 2 pixels or more in the height of text elements when I compared the same PDF with itextsharp and itext7.

The difference becomes progressively higher with increasing text size. I have a custom strategy class with the following code snippet. The variables width and height shows how I am arriving at the dimensions.

public void RenderText(TextRenderInfo renderInfo)
{
        var baseline = renderInfo.GetBaseline();
        var ptStartBaseline = baseline.GetStartPoint();
        var ptEndBaseline = baseline.GetEndPoint();

        var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
        var topRight = renderInfo.GetAscentLine().GetEndPoint();

        float xbotleft = bottomLeft.Get(iText.Kernel.Geom.Vector.I1);
        float ybotleft = bottomLeft.Get(iText.Kernel.Geom.Vector.I2);
        float xtopright = topRight.Get(iText.Kernel.Geom.Vector.I1);
        float ytopright = topRight.Get(iText.Kernel.Geom.Vector.I2);

        float width =   xtopright - xbotleft;
        float height =  ytopright - ybotleft;

}

Where am I going wrong? Thanks, Sau

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.425188 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO