boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 155 forks source link

merged_metrics boundingbox is nil #167

Open shrikanth-bluesapling opened 4 years ago

shrikanth-bluesapling commented 4 years ago

Hello!

Thank you for the gem, it's come very handy in a lot of cases. I'm having an issue with textbox and a registered font, in this case, Roboto. When I load up a pdf with roboto and register the font, attempting to create a textbox raises the following error:

NoMethodError (undefined method ``[]' for nil:NilClass)

After a bit of debugging, I've figured out that the problem is with this line:

height = metrics_array.map { |m| m ? m[:boundingbox][3] : 0 } .max

From fonts.rb:141.

From what I can tell, when the font Robot is being registered the font metrics aren't being loaded appropriately, so the wx field is present but the boundingbox field is not.

boazsegev commented 4 years ago

Hi @shrikanth-bluesapling ,

Thank you for opening this issue.

I'm super busy this month, but I'll try to get o it as soon as I can.

Could you send me a file (to extract the fond) and an example script that would reproduce the issue? Thanks!

Kindly, Bo.

shrikanth-bluesapling commented 4 years ago

Thanks for the response. I've attached a sample pdf I use to get the font. I managed to get the font working by using ttfunk to manually extract metrics, but it tended to overestimate sizes and messed up alignment and the like. roboto_sample.pdf