• Seth
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have been able to successfully get PrintAnything to format data as necessary, but am having some troubles with one of the finishing touches:

In order to allow people to easily print the output, I've added a javascript "Print" button.  The problem is, however, that since PrintAnything does not accept stylesheet calls (I need to call a "media" stylesheet in this case), I am unable to use javascript code to "hide" the print button when the document is actually printed.

This means that every printout has a big "Print" button on it, which is obviously less than desirable.

Has anyone figured a way around this?

Thanks,
Seth
  • April 02, 2007
  • Like
  • 0
While using Print Anything, I extended the driver to include support for an equals tag. If anyone is using print anything, I found this very helpful when creating more advanced templates. It also supports nested equal statements.

Here's how it works:

<prtany:equal Contact1.FirstName="some value" Contact1.LastName="some other value" ........ >
  
    Displays this text only if:
    Contact1.FirstName="some value" and
    Contact1.LastName="some other value"

    <prtany:equal Contact1.LastName="some other value 2">
  
        Displays this text only if:
        Contact1.LastName="some other value 2" and
        parent equals tag is true

    </prtany:equal>

</prtany:equal>

<prtany:equal Contact1.FirstName!="some value" >
  
    Displays this text only if:
    Contact1.FirstName does not equal "some value"

</prtany:equal>



(Put new code inside the merge function after the last while statement)

Code:
 // remove any conditional content
while (result.indexOf("<prtany:equal") != -1) {
var level = 1;

// Find next start tag (<prtany:equal ... >)
var startTagStartPos = result.indexOf("<prtany:equal");
var startTagEndPos = result.indexOf(">", startTagStartPos);

var parsePos = startTagEndPos;

var nextStartTagPos;
var nextEndTagPos;

// Find corresponding end tag (</prtany:equal>)
do {
nextStartTagPos = result.indexOf("<prtany:equal",parsePos);
nextEndTagPos = result.indexOf("</prtany:equal", parsePos);
if( nextStartTagPos < nextEndTagPos && nextStartTagPos != -1 ) {
level = level + 1;
parsePos = nextStartTagPos + 1;
} else {
level = level - 1;
parsePos = nextEndTagPos + 1;
}
} while ( level > 0 )

if (nextEndTagPos == -1) {
throw "No equal end tag was found";
}

var endTagEndPos = result.indexOf(">", nextEndTagPos);

var conditionalString = result.substring(startTagEndPos+1,nextEndTagPos);

// Parse start tag conditions (<prtany:equal var="value" var2!="value" ... >
var statement = result.substring(startTagStartPos+1,startTagEndPos);
var reg = /(\S+?)\s*(\!?=)\s*\"(.+?)\"/g;

var match = reg.exec( statement );
while( match != null ) {
var conditionalValue = mergeData[match[1]];
if( match[2] == "!=" ) {
if (conditionalValue == match[3]) {
conditionalString = "";
}
} else {
if (conditionalValue != match[3]) {
conditionalString = "";
}
}
match = reg.exec( statement );
}

result = result.substring(0,startTagStartPos) + conditionalString + result.substring(endTagEndPos+1)
}

 





Message Edited by sduda on 03-29-2007 02:23 PM

Message Edited by sduda on 04-09-2007 09:28 AM

Message Edited by sduda on 04-09-2007 09:30 AM

  • March 29, 2007
  • Like
  • 0