blasalle
Posts: 69
|
| Posted: 07/02/2009, 2:49 PM |
|
I need to print forms but not the entire web page. I initially added a button and using the Client On Click event and the javascript window.print();' and I can print the entire page. I would like to just print just the form without the header and footer and tried using the following:
function printDiv()
{
var divToPrint=document.getEelementById('areaToPrint');
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
and defined areaToPrint using:
<div id="areaToPrint">
form code goes here
</div>
this javascript does nothing. If anyone has some insights on how to approach this I would like to hear from you.
regards,
bernie
_________________
Bernie
University of Utah
Salt Lake City, UT USA |
 |
 |
DonP
|
| Posted: 07/02/2009, 3:02 PM |
|
What I did on one of my sites was to put in some remarks at the
beginning and ending of where I wanted to print <!--print--> and created
a print_page script which used the explode() function to grab that
section and insert the HTML into a temp table. The code then took the
code and pasted it into a label where it had its own headers and footers
that I created just for the print version. It works well even on
different pages where the content comes from other tables since it is
not dependent upon the source.
Don (DonP)
blasalle wrote:
> I need to print forms but not the entire web page. I initially added a button
> and using the Client On Click event and the javascript window.print();' and I
> can print the entire page. I would like to just print just the form without
> the header and footer and tried using the following:
>
>
> function printDiv()
> {
> var divToPrint=document.getEelementById('areaToPrint');
> newWin= window.open("");
> newWin.document.write(divToPrint.outerHTML);
> newWin.print();
> newWin.close();
> }
>
> and defined areaToPrint using:
>
> <div id="areaToPrint">
> form code goes here
> </div>
>
> this javascript does nothing. If anyone has some insights on how to approach
> this I would like to hear from you.
>
> regards,
>
> bernie
>
> _________________
> bernie
> university of utah
> slc, ut usa
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
damian
Posts: 838
|
| Posted: 07/02/2009, 3:54 PM |
|
you can define print regions using css style sheets.
its something i have always been meaning to learn....
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
DonP
|
| Posted: 07/02/2009, 4:14 PM |
|
CSS printing may not work well with some browsers but you're right, it
is a good solution and one I've never learned either. I would like to!
Anyway, below is an example of the code I wrote for the purpose in case
it helps.
Don (DonP)
// On page you want to print, surround area to be printed with
// <!--print--> (one above and one after) add an HTML label with Before
// Show event including something like this (for clarity, the JavaScript
// and CSS for the popup are not shown; do it however you want):
global $FileName;
if ($FileName == "page.php") {
$ServerName = getenv("HTTP_HOST");
$ScriptName = getenv("SCRIPT_NAME");
$PageID = CCGetParam("ID");
CCSetSession("PrintVersionPath", $ServerName . $ScriptName . "?ID=" .
$PageID);
CCSetSession("PrintVersionParam", "?ID=" . $PageID);
$PrintableVersion->SetValue("<a href=\"print_page.php\"
onClick=\"newWindow('600', '400', 'yes', 'PrintWindow');\"
class=\"PrintButton\" target=\"PrintWindow\">Printable Version</a>");
} else {
$PrintableVersion->SetValue("");
}
// The print_page.php script has an HTML label with Before Show event:
$PageCode = getFile(CCGetSession("PrintVersionPath"),
CCGetSession("PrintVersionParam"));
if ($PageCode) {
$pieces = explode("<!--print-->", $PageCode);
$PageCode = $pieces[1]; // Main page body, between <!--print--> tags
// Strip all links but leave link text
$PageCode = eregi_replace('(<a [^<]*href=["|\']?([^
"\']*)["|\']?[^>]*>)','', $PageCode);
$PageCode = str_replace("</a>", "", $PageCode);
// Set tables to full width
$PageCode = str_replace("80\%", "100\%", $PageCode);
// Strip all scripts
$PageCode = eregi_replace('<script("|\')?([^
"\']*)("|\')?.*>([^<]*)</script>', '', $PageCode);
// Strip all remarks
$PageCode = eregi_replace("<!--([^-]*([^-]|-([^-]|-[^>])))*-->", "",
$PageCode);
// Strip background image
$PageCode = str_replace("background=\"/php/show_background.php?ID=8\"",
"", $PageCode);
// Strip all forms
$PageCode = eregi_replace('<form("|\')?([^
"\']*)("|\')?.*>([^<]*)</form>', '', $PageCode);
$DBconnection = new clsDBconnection();
// Create a temp table using custom random character function as name,
drop when finished
$TableName = randchr(15);
$SQL1 = "CREATE TABLE " . $TableName . " (`PageContents` TEXT)";
$SQL2 = "INSERT INTO " . $TableName . " (PageContents) ".
"VALUES (". CCToSQL($PageCode,ccsText) .")";
$SQL3 = "DROP TABLE `" . $TableName . "`";
// For testing purposes only
// CCSetSession("TableName", $TableName);
$DBconnection->query($SQL1);
$DBconnection->query($SQL2);
$PageHTML->SetValue(CCDLookup("PageContents", $TableName, "PageContents
IS NOT NULL", $DBconnection));
$DBconnection->query($SQL3);
$DBconnection->close();
}
blasalle wrote:
> I need to print forms but not the entire web page. I initially added a button
> and using the Client On Click event and the javascript window.print();' and I
> can print the entire page. I would like to just print just the form without
> the header and footer and tried using the following:
>
>
> function printDiv()
> {
> var divToPrint=document.getEelementById('areaToPrint');
> newWin= window.open("");
> newWin.document.write(divToPrint.outerHTML);
> newWin.print();
> newWin.close();
> }
>
> and defined areaToPrint using:
>
> <div id="areaToPrint">
> form code goes here
> </div>
>
> this javascript does nothing. If anyone has some insights on how to approach
> this I would like to hear from you.
>
> regards,
>
> bernie
>
> _________________
> bernie
> university of utah
> slc, ut usa
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
|