Print Section Snippet

This macro let the user select one section from the page and print it. By Vitantonio Messa

#macro(allowPrintSection)

<form action=$doc.getURL() method=post>
  <input type="hidden" name="pageName" value="$doc.getFullName()" />
  <select name="printSection">
    #set ($i = 0)
    #set ($tocData = ${doc.getTOC(2, 2, false)})
    #foreach ($tocEntry in $tocData.entrySet())
      #set ($i = $i+1)
      <option value="$i">$xwiki.parseContent($tocEntry.value.text)</option>
    #end
  </select>
  <input type="submit" class="button" style="margin:auto;" value="Print section"/>
</form>

#if($request.printSection)
  #set ($sections = $doc.getContent())
  #set ($i = 0)
  #foreach ($section in $sections.split("
1.1 "))
    #if ($i == $xwiki.parseInt($request.printSection))
      #set ($newContent = $section)
    #end
    #set ($i = $i+1)
  #end
  #set ($newContent = "1.1 "+$newContent)
  #set ($newDoc = $xwiki.getDocument("Main.PRINT_tmpSectionToPrint"))
  #if ($newDoc == $xwiki.getNull())
    #if (!$xwiki.copyDocument($request.pageName, "Main.PRINT_tmpSectionToPrint"))  
      *Error while printing section...*
    #end
  #end
  $newDoc.setContent($newContent)
  $newDoc.save()
  Section ready to be printed: <a href="$newDoc.getURL('view', 'xpage=print')">click here</a>.
#end
#end
Version 7.2 last modified by VincentMassol on 22/02/2008 at 20:51

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: VitantonioMessa on 2008/02/22 12:35
This wiki is licensed under a Creative Commons license
1.4.1.10194