Hello devs.
Though this is not a fix nor a perfect solution (actually, I think
this is a very big hack), we created a workaround that seems to suit
our PDF exporting needs.
The hack is based on changing the renderedContent for the children or
linked pages to make sure the generated ids are unique, i.e., find and
replace of the ids to include the full name of the child page as
prefix for the heading id, at the moment, by changing the macros
includeChildren and includeLinks in the macros.vm file. However, if we
keep this hack, we'll probably define equivalent functions inside the
pdf.vm file to make sure we do not break any other code using the
original includeChildren and includeLinks macros from macros.vm and
use those instead of the ones from macros.vm.
Next, we present the hack for the macro includeChildren in macros.vm:
#macro(includeChildren $page $withPageBreaks)
 #if($clevel!=0)
  #foreach($childDocName in $xwiki.searchDocuments("where
doc.parent='$page' order by doc.creationDate"))
    #set($childDoc = $xwiki.getDocument($childDocName))
#if(($childDoc)&&($childDoc.getSpace()!="Panels")&&($childDoc.getSpace()!="XWiki"))
     #if($withPageBreaks)
     #pagebreak()
     #end
     ## Changes performed for the successful generation of the PDF
     #set ($renderedContent = $childDoc.getRenderedContent())
     #set ($renderedContent = $renderedContent.replaceAll("<h1 id=\"",
"<h1 id=\"$childDoc.fullName"))
     #set ($renderedContent = $renderedContent.replaceAll("<h2 id=\"",
"<h2 id=\"$hildDdoc.fullName"))
     #set ($renderedContent = $renderedContent.replaceAll("<h3 id=\"",
"<h3 id=\"$childDoc.fullName"))
     #set ($renderedContent = $renderedContent.replaceAll("<h4 id=\"",
"<h4 id=\"$childDoc.fullName"))
     #set ($renderedContent = $renderedContent.replaceAll("<h5 id=\"",
"<h5 id=\"$childDoc.fullName"))
     #set ($renderedContent = $renderedContent.replaceAll("<h6 id=\"",
"<h6 id=\"$childDoc.fullName"))
     ## End changes performed for the successful generation of the PDF
     $renderedContent
     #set($clevel = $xwiki.add($clevel,-1))
     #includeChildren($childDocName $withPageBreaks)
     #set($clevel = $xwiki.add($clevel,1))
    #end
  #end
 #end
#end
Best,
Paulo Zenida
On 23 September 2010 09:35, Marius Dumitru Florea
<mariusdumitru.florea(a)xwiki.com> wrote:
  Hi Ricardo,
 Does this happen only for headings or is it a general problem? What if
 the same ID is used in two different pages, inside the page content
 (e.g. on a paragraph). The ID can come from an user and not from the
 rendering.
 I have more or less the same problem when integrating XWiki in a portal:
 I have to make sure XWiki's IDs don't collide with IDs of other portlets
 displayed on the same portal page.
 Namespacing the IDs of HTML elements generated by XWiki is not always
 enough because IDs are used:
 * in CSS to style unique elements, so if you don't update the CSS also
 you could loose styles
 * in JavaScript to access known elements
 Marius
 On 09/22/2010 08:25 PM, Ricardo Espírito Santo wrote:
  Hello there,
 I have been asked to develop something on top of the pdf export facilities
 on the xwiki. But I run into a small problem:
 When *generating a pdf with multiple pages*, say all the pages from one
 space, the ids of elements within the pages get duplicated and the *pdf
 exportation fails*.
 i.e.:
 *Page A* with a title *TheQuickBrownFox...* some text under it and then *page
 B* with the same title: *TheQuickBrownFox...* with some other text under
 this. Both will get an auto ID of *TheQuickBrownFox...
 *Now this doesn't happen for items on the same page since the ID generation
 mechanism counts all items of the same name and increments it if necessary.
 But this mechanism does not contemplate cross page duplicated items.
 To avoid the following error:
 Property ID "lipsum" (found on "fo:block") previously used; ID values
 must be unique within a document! (See position 12:39)
 We thought some changes to the ID generation mechanism could be made:
 We could* prefix the ID* with the space and page name and this would
 be a simple elegant solution.
 Now:
 Is this the best solution?
 Will someone point out the best place to do this?
 If I post a patch with this fix will it be included on the trunk?
 Thank you in advance,
 » Ricardo Espírito Santo
 » Linkare TI - Tecnologias de Informação, Lda
 _______________________________________________
 devs mailing list
 devs(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/devs 
_______________________________________________
 devs mailing list
 devs(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/devs