3

I have a PDF and I want to programmatically change text, not fonts, colors, just letters.

I tried

  • pdf-toolkit - just metadata
  • prawn - templates not supported any more
  • combine_pdf - some fonts not supported

Is there easier way to change just text? Just decode the XML inside the PDF file, change a encode back?

DonPaulie
  • 2,004
  • 17
  • 26
  • It'll be good to see examples of your implementation, to see if its the fault of the gems or something on your end. – Maxim Fedotov Jun 13 '17 at 09:25
  • There was a bug in combine_pdf... just dealing with that with the author. Will update, when I know more. – DonPaulie Jun 13 '17 at 13:24
  • Please be aware that for generic PDFs text replacement may not be feasible. E.g. a font might only be embedded as a subset and not indicate which original font it is a subset from. In that case replacement by text with characters not in the subset will result in trash. – mkl Jun 13 '17 at 18:40
  • @mkl, yeah, I see... I managed to add text with the same font to the pdf to see if it's the same, and it's exactly the trash... investigating more during the nights... – DonPaulie Jun 14 '17 at 07:07
  • 1
    CombinePDF will let you import fonts from other PDF files... it's more of a hash than a feature, but I use it (I'm CombinePDF's author) so I have no intention of breaking it... you can see example code in [the CombinePDF demo application's code](https://github.com/boazsegev/combine_pdf_demo/blob/6049f4ba3b185cc9a1e27bacc28c7c4f8f9618d4/pdf_controller.rb#L56-L67)... maybe this helps, maybe it doesn't. Make sure the font you're importing has a full subset of the alphabet you need (I created the PDF with the font file I needed). – Myst Jul 05 '17 at 03:50

0 Answers0