Wow!
Sorry for this long post
I had a problem. When a user generated a replacement diagram (showing the damaged area on a car), the replacement diagram would not show when recreating a PDF.
What I needed was to add a dynamically changing parameter to the URL for the diagram, something like this '?v=123'
. After lots of faffing around, trial and error etc I found that the PHP PDF Conversion Library I was using (html2pdf) would not process a URL parameter inside the template, nor would it accept any of these meta tags.
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
This was a major problem and I had to think outside of the box (for me anyway )
Initially I had the diagram saved with each job, so in this case 'damagedarea.png'
was saved under job number '15'
. This made it easy to reference and keep for future use.
'admin/repository/reports/15/damagedarea.png'
I now knew I could not use URL parameters like this
'admin/repository/reports/15/damagedarea.png?v=1600251135'
I thought of putting the dynamic reference as part of the file name, but this would be a nightmare to reference in the future as I would have to store this info in a database etc, adding more complexity. And if the user kept making more and more changes, then the number of diagrams would build up, and this would be uncontrollable ie
'admin/repository/reports/15/damagedarea1600251135.png'
'admin/repository/reports/15/damagedarea1606587546.png'
'admin/repository/reports/15/damagedarea1573548444.png'
etc. We only ever need the last diagram created.
My solution
Because the PDF was generated in one instance using a Server Action, I thought of saving and keeping the PNG file as originally planned
'admin/repository/reports/15/damagedarea.png'
but then to create a temporary copy
- create a
'temp'
folder within the job folder
- inside which I create a dynamically referenced folder using TIMESTAMP ie
'1600251135'
- inside which I put a copy of the PNG file
like this
'admin/repository/reports/15/temp/1600251135/damagedarea.png'
I could then set a session variable 'for_PDF_img'
and use this dynamic file link in the PDF Template and it would work, it linked to the newly created PNG file.
If the user kept making changes and updating the diagram, it would always overwrite the original
'admin/repository/reports/15/damagedarea.png'
To prevent a built up of files in the 'temp'
folder, this folder would be emptied at the beginning of each process. Not at the end of the Server Action because the file was yet to be referenced in the PDF Template and so was still required after the Server Action had finished processing.
My simple Server Action
And here are each of the Server Action components…
This is how part of the process looks to the user
Here the user puts arrows and crosses on a diagram of a car using HTML5 Canvas and Saves.
That diagram is then saved as a PNG file and used in various parts of the website.
They can then create a fresh PDF when changes have been made.
There is a link to the newly created PDF
And here is part of the PDF Report showing the inserted diagram which cam from
'admin/repository/reports/15/temp/1600251135/damagedarea.png'
Conclusion
That’s my experience and my solution. It works well but I would certainly welcome any comments or even alternative solutions.