DEV Community

loading...

How I can replace text in it with a value from a PDF file using PHP?

pcmagas profile image Dimitrios Desyllas ・1 min read

I was provided with a pdf file containing placeholder texts: https://drive.google.com/file/d/1jdfde-enJ5_MksYm2CmakNQyLbDNExgE/view?usp=sharing

In that I want using php to replace the text ${NAME} Into a specified value.

But as long as I searched I found no example on how to do that. Do you have any idea on how to do…

Discussion

pic
Editor guide
Collapse
itsmukulmishra profile image
Mukul Mishra

It's simple thing. Use domPDF to parse the file. Store content in some variable and then apply str_replace()

Collapse
pcmagas profile image
Dimitrios Desyllas Author

Can you provide me an example? Also DOMPdf generates Pdf from html files.

Collapse
ivanjeremic profile image
Ivan Jeremic

This is easy with JavaScript + ReactJS + react-pdf. But sadly you are in the PHP world.