UPDATE:Sorry Monks, I didn't explain why I needed this. I am creating pdf's and I need to calculate space for a certain part of a pdf document I am creating. So, the calculation by pixels will tell me how far I can go with the text, where the left position can start, and if I have to split the line into smaller parts. Thanks again.
Your update is a little confusing. Are you creating a vector or a raster document? PDFs are vector-based and do not use pixels. If you are creating a raster graphic to be embedded in a PDF, that's something different.
Simply answering your question, determining the length of text is a basic function of any text rasterization package. For example, GD returns the bounds of a string rendered with stringFT. More conveniently, you can use GD::Text to get the information a little more easily. Similar functionality is available with nearly any text rasterizer I'm aware of.