Search code examples
macospdfdevanagari

Extract Devanagari text from PDF file and insert into NSTextView while retaining original font?


I have a PDF document rendered in the Devanagari character set. I can extract attributedStrings from it, but only Helvetica fonts show up in the string attributes. My locale is US English; I am developing a macOS app.

How can I extract the Devanagari text and retain the correct font?


Solution

  • I've discovered that the fonts used within the PDF files were fonts that had not been installed on my macOS system. The PDF files used "Kruti Dev 010" and "Kruti Dev 011". After downloading these fonts, and then installing them with the Font Book app, the Hindi text is rendered as expected, and can be extracted via PDFDocument and PDFPage attributedString methods.