CREATING PDF'S FROM SEARCH RESULTS - Nov 18th, 2019


I had a rather complex search form and needed to create a PDF of the search results so they could be easily downloaded
and printed.

Daniel Louwe from Interactive Tools came to the rescue (again) with the following suggestion:

"Because you want to create a PDF of the search results, you need to simulate the form being submitted at the same time
as the PDF generation. Clicking the link with "?pdf=1" clears all of the search values, as well as the "save" value that
tells the page to show the search results.

One fairly minimal solution I can think of is instead of using a "convert this page to PDF" link, you could add a
checkbox to the form with the name "pdf" and value "1" labelled something like "View search results as a PDF" so that
the user can choose to receive a PDF of the results instead of a web page when they submit the form, rather than
clicking a link afterwards."

For example, the final code in my form was

<tr>
<td align="right" class="text_font">&nbsp;</td>
<td align="left" valign="bottom" colspan="2"> <input type = "checkbox" id="pdf" name="pdf" value = "1"
<?php checkedIf(1,
@
$_REQUEST['pdf']);?> /> <span class="text_font"><b>Check to create a downloadable PDF of the search results instead of
a web page</b></span></td>

</tr>

Daniel went on to suggest:
"Another simple - but more tedious - solution is to add "save=1" to the URL in addition to the relevant form values. A
simple working example is http://your_site.com/your_search_page.php?pdf=1&save=1&your_search_field_keyword[]=1. The two
main tasks you'd have are 1) building the URL string based on the submitted form values, and 2) updating the code to
account for when both $_REQUEST['pdf'] and $_REQUEST['save'] are on; e.g. removing the original "convert this page to
PDF" link."

Note: The brackets [] after _keyword are because in my form this field in the table that I'm searching got its values
from a pulldown list that accessed second table, and so this was that field's name in the form.




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service