Thanks again to @user2768665 for the best answer to my troubles. This is my gameplan:
Since I have the files named as in the link, I first grab the WP link of the product using GET, then store that in a variable, preg_replace it to erase the rest of the link (with regex), store that result in a new var, let's say $link2p
.
Then I add the call to the product (Download) to open up the processing php script, use tcpdf (user2768665's answer) to delete anything that goes after page 5, add the page with the company's logo as being page 6, and at the end of it add the
Click <a href="http://domain.ltd/saleProcessPage/<?php echo $link2p;?>"here</a> to download <?php echo $link2p;?> FULL PDF
Or, in my case (since I have the a 3rd party paying platform -and you might have the same-), we first run a database check on the product(based on its name) to retrieve the link to our product in our paying platform and then we do the same as above.
Then, we modify the the original's pdf name and output it differently;
$pdf->Output($link2p.'.pdf', 'Insert w/e random string generator.pdf');
It's a great solution as it keeps original pdf files out of any "Inspect Element" user, it runs in the backend and hey, random name si given out.
// Other things I`m thinking about:
Since I haven't read the full documentation for tcpdf, can't be sure on this but I haven't seen any page count ability (which is needed in order to do this fully automatically for the files: i.e. $pdf->deletePage(6,100); becomes $pdf->deletePage(6,endofpdf);
For that purpose, I add what I've read before placing the question : Count the number of pages in a PDF in only PHP . So we store that into a $count
variable (to see how many files the pdf has) so that we can use $pdf->deletePage(6,$count);
Again, haven't read the tcpdf full documentation, so this may be useless.
I'm going to do a full code workup on this after I get some sleep and post the example in its final form. Hopefully this will help others stuck in the same place.
A great thank you again to @user2768665 and @Monts_mind_hacker for the interest in the topic. Awesome guys.