Hello, Thanks Peter for the pointers…
I’ve kept up the hread through Georg’s answer Cheers Igor From: Peter Hancock [mailto:[email protected]] Sent: martes, 12 de enero de 2010 11:00 To: [email protected] Subject: Re: Absolute position of original text in final PDF Hi Igor, Is there more information on what Traits are? A defintion can be infered here http://www.w3.org/TR/2001/REC-xsl-20011015/slice4.html#area-common And a brief relation to fop here http://xmlgraphics.apache.org/fop/dev/design/areas.html#traits Am I right in thinking that when defined, block.getTraits().get(org. apache.fop.area.Trait.PROD_ID) will yield the original id that was defined in the <fo:block>? If you change you output to at (render using he fop command and use '-at out.at') you get the an xml serializtrio nof the area tree. e.g ...<fo:block id="1"> Block 1 </fo:block>... may look something like ... <block ipd="522720" bpd="14400" ipda="522720" bpda="14400" bap="0 0 0 0" prod-id="1"> − <lineArea ipd="522720" bpd="11100" ipda="522720" bpda="14400" bap="0 0 0 0" space-before="1650" space-after="1650"> − <text offset="0" baseline="8616" ipd="39348" bpd="11100" ipda="39348" bpda="11100" bap="0 0 0 0" font-name="sans-serif" font-style="normal" font-weight="400" font-size="12000" color="#000000"> <word offset="0">Block</word> <space offset="0"> </space> <word offset="0">1</word> </text> </lineArea> </block> ... This might help you debug you app. Pete On Tue, Jan 12, 2010 at 8:45 AM, Igor Rosenberg <[email protected]> wrote: Hello, Within the rendering classes, I understand that each Object within the AreaTree gets rendered individually. I hope that assumption's correct... Especially org.apache.fop.render.pdf.PDFRenderer.renderBlock (org.apache.fop.area.Block block) Within this method, I have discovered that the Block object retains the original id information: Map t = block.getTraits(); if (t!=null) for (Object key : t.keySet()) { Object tt = t.get(key); System.out.println(" TRAIT " + key + " ==> " + tt); } The output of that provides TRAITS TRAIT 8 ==> #N10011 TRAIT 30 ==> 8000 Is there more information on what Traits are? The javadoc states: public class org.apache.fop.area.Trait Area traits used for rendering. This class represents an area trait that specifies a value for rendering. Am I right in thinking that when defined, block.getTraits().get(org.apache.fop.area.Trait.PROD_ID) will yield the original id that was defined in the <fo:block>? And secondly, do I already have the positioning information of the Block in the final PDF, at the end of the renderBlock method? I would think that I have: Final width = ipd Final height = bpd But how do I get the x and y positioning? Thanks for the help... Igor --- From: Igor Rosenberg Sent: lunes, 11 de enero de 2010 18:44 To: [email protected] Subject: RE: Absolute position of original text in final PDF Hi, The ids get generated on the fly during the XML to FO transformation, for the original <text> tags, and get output in the FO format as <fo:block id=…> . This is expressed as <fo:block id="#{generate-id()}" in the XSL document. See generate-id() in http://www.w3schools.com/XSL/func_generateid.asp . So basically, I’m just doing the XSLT transformation (my own format to FO), and adding as bonus the id generation. Find the XSLT and FO details below Cheers Igor ------ The relevant parts of the XSL look like <xsl:template match="body"> <fo:block space-after.optimum="3pt" space-before.optimum="4pt"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="text"> <xsl:if test="@alignment='Left'"> <fo:block id="#{generate-id()}" font-size="8pt" font-weight="normal" font-family="sans-serif" line-height="9pt" space-after.optimum="8pt" text-align="left"> <xsl:value-of select="."/> </fo:block> </xsl:when> ------ A section of the output fo, as produced by apache fo, looks like this (indented by me) – see how the ids appear in the fo:block tags <fo:block> <fo:block text-align="right" space-after.optimum="8pt" line-height="9pt" font-family="sans-serif" font-weight="normal" font-size="8pt" id="#N10011"> Adress 1 line </fo:block> <fo:block text-align="right"space-after.optimum="8pt" line-height="9pt" font-family="sans-serif" font-weight="normal" font-size="8pt" id="#N10017"> Address 2 line </fo:block> <fo:block text-align="center" space-after.optimum="10pt" line-height="13pt" font-family="sans-serif" font-weight="normal" font-size="12pt" id="#N1001F"> Another text line in different font </fo:block> </fo:block> From: Peter Hancock [mailto:[email protected]] Sent: lunes, 11 de enero de 2010 18:30 To: [email protected] Subject: Re: Absolute position of original text in final PDF Hi Igor, It is not clear to me how these <text> elements are defined - in your xml input? If so how do you transform them to fo whilst retaining the id attribute? Could you provide a small example of the xml and the corresponding xsl that you wish to be input of fop. Thanks, Pete On Mon, Jan 11, 2010 at 4:39 PM, Igor Rosenberg <[email protected]> wrote: Dear FOP mailinglist readers, I’ve been fighting with the Apache FOP source for a week, but I can’t solve my problem alone… One of the features of the application I’m writing produces a PDF, based on an XML that follows a simple schema (header info, tables, images and text, but nothing fancy). Generating the FO then the PDF are the easy steps. Fop does the job marvelously. Now I need to output to the user the coordinates of bounding boxes. Those bounding boxes must represent the placement in the PDF of the original text within the XML. To provide an example: If I had in my original XML , <text id=”xxx”>This text appears somewhere in the PDF</text> I would want, during the XML to PDF process, to output something like Bounding_box {id=”xxx”, x=34, y=45, w=444,h=25} I understand this as “the original text of tag xxx is contained in the pdf in the rectangle starting at point (34,45), of width 444, and height 25” (if the text is split into several pages or areas, receiving a list of rectangles would be fine) To summarize: how can I know the position in the final PDF of the original text? I’ve tried decorating different classes of FOP, looking at the FOTreeBuilder, the AreaTreeParser, but failed to maintain the identifier of the original text tags. I’d prefer staying with release 0.95, but can also use the trunk if required. While browsing, I thought that the accessibility features might help, but couldn’t figure out how http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/accessibility.xml?view=markup I thought relying on the Area Tree, but couldn’t retrieve the original id that were set to the original XML tags. http://wiki.apache.org/xmlgraphics-fop/AreaTreeXMLDocumentation http://old.nabble.com/Area-Tree-Handling-to24431098.html Thanks for any help Igor ------------------------------------------------------------------ This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. Este mensaje y los ficheros adjuntos pueden contener informacion confidencial destinada solamente a la(s) persona(s) mencionadas anteriormente pueden estar protegidos por secreto profesional. Si usted recibe este correo electronico por error, gracias por informar inmediatamente al remitente y destruir el mensaje. Al no estar asegurada la integridad de este mensaje sobre la red, Atos Origin no se hace responsable por su contenido. Su contenido no constituye ningun compromiso para el grupo Atos Origin, salvo ratificacion escrita por ambas partes. Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor no puede garantizar nada al respecto y no sera responsable de cualesquiera danos que puedan resultar de una transmision de virus. ------------------------------------------------------------------ ------------------------------------------------------------------ This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. Este mensaje y los ficheros adjuntos pueden contener informacion confidencial destinada solamente a la(s) persona(s) mencionadas anteriormente pueden estar protegidos por secreto profesional. Si usted recibe este correo electronico por error, gracias por informar inmediatamente al remitente y destruir el mensaje. Al no estar asegurada la integridad de este mensaje sobre la red, Atos Origin no se hace responsable por su contenido. Su contenido no constituye ningun compromiso para el grupo Atos Origin, salvo ratificacion escrita por ambas partes. Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor no puede garantizar nada al respecto y no sera responsable de cualesquiera danos que puedan resultar de una transmision de virus. ------------------------------------------------------------------
