How to increase the accuracy of measurements in iTextSharp?

I want to resize a pdf to a specific size, but when I use scaling it loses accuracy because a float rounds the value. How can I avoid this and make measurements more accurate? Posted on StackOverfl

I want to resize a pdf to a specific size, but when I use scaling it loses accuracy because a float rounds the value. How can I avoid this and make measurements more accurate?

Posted on StackOverflow on Jul 21, 2014 by Stephen De Klerk

The ByteBuffer class has a public static variable named HIGH_PRECISION. By default, it is set to false. You can set it to true so that you get 6 decimal places when rounding a number:

iTextSharp.text.pdf.ByteBuffer.HIGH_PRECISION = true;

That will cost you some performance (but maybe you'll hardly notice that) and the resulting file will have more bytes (but measurements will be more accurate).



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now