I want to search a string from a pdf file in a way strstr()
does. But when a pdf is read as plain text, it gives you a non-understandable junk. How do I do it?
Perhaps pdflib has some solution, but my hosting provider doesn't help me install it.
I want to search a string from a pdf file in a way strstr()
does. But when a pdf is read as plain text, it gives you a non-understandable junk. How do I do it?
Perhaps pdflib has some solution, but my hosting provider doesn't help me install it.
Copyright © 2021 Jogjafile Inc.
using the link from the previous response I changed the code a little in order fill my needs, which were SEARCH AND REPLACE, the functions from the article don't need additional libraries but you do need the FPDI library for the REPLACE part.
Now this code isn't perfect either but it's a good start for anyone searching something similar.
The main problem this script has is that the new data is overwritten over a kind of image of the original pdf template, this means that if your are trying to replace 2 lines of text with 5 lines of text it wont insert the text, but overwrite the 2 lines plus 3 more. It also means that whatever you try to overwrite will have to have a matching background.
But for some basic needs, like for example having a nice business proposal or quote on pdf like a template, this script can overwrite the date or client name, all within the php app.
Now for the usage:
What I did was saving the pdf template file with some "keywords" which will be overwritten, for example in order to change the date on the template PDF I placed the keyword @DATE where I wanted, and so on for other keywords.
The modified
pdf2text
function returns false if the search word your looking is not found on the pdf. If it is found it returns an array with the searched keyword, the page on which it was found, the font size of the word, and the X and Y value.Hope it helps anyone
bye