You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Bernmeister <th...@hotmail.com> on 2009/04/24 06:40:20 UTC

Change the header/footer size in a PDF

Hi,

I have a simple XSL report with header, body and footer which renders to a
PDF.  My Java application passes variables to the XSL to set body-margin,
header/footer-extent and font sizes.

I set the header size (in point not mm) to be slightly larger than the font
size for text to appear in the header.  This works fine - gives enough space
for the header to hold all the text.  

However, if the text in the header (which is set by a user back in the
application) is "longer" than the width of the header, that text will carry
over to a next line...and so bleed into the body.

I've seen this post from a while back  
http://www.nabble.com/Auto-size-header-to-fit-with-content---td4765740.html#a4765740

...but it doesn't really help.  Hardcoding for line height, text height,
etc, etc is too dangerous.

I've scoured the FOP Javadoc and cannot seem to figure out if it's possible
to access the rendered PDF (as some sort of tree or data object) and work
out if the header text has wrapped.  Is it possible to determine this and so
fix it?  

Or is it possible to access the PDF itself and determine if wrapping has
occurred in the header?

If I can detect the header has wrapped text (or footer for that matter), I
can just increase the header by the original amount and re-render to PDF.


Thanks in advance,

Bernmeister.
-- 
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23209748.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


AW: AW: AW: Change the header/footer size in a PDF

Posted by Georg Datterl <ge...@geneon.de>.
Hi Bernmeister,

The one thing I see: the second parameter to evaluate, item, should not be a String but the root node of your document.  

Regards,
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Bernmeister [mailto:thebernmeister@hotmail.com] 
Gesendet: Montag, 27. April 2009 02:06
An: fop-users@xmlgraphics.apache.org
Betreff: Re: AW: AW: Change the header/footer size in a PDF


Hi Georg,

Thanks again for your help.  Getting there slowly...

I believe I've managed to get to the point of getting a document back from the transformation.  The code is below:


  FopFactory fopFactory = FopFactory.newInstance();
  FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

  SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory)TransformerFactory.newInstance();
  TransformerHandler transformerHandler = saxTransformerFactory.newTransformerHandler( new StreamSource( m_xslStylesheet ) );
  DOMResult domResult = new DOMResult();
  transformerHandler.setResult( domResult );
                
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                
  BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( new FileOutputStream( m_outputPDFFile ) );
  Fop fop = fopFactory.newFop( MimeConstants.MIME_FOP_AREA_TREE, foUserAgent, bufferedOutputStream );
  Transformer transformer = saxTransformerFactory.newTransformer();
                
  // Set report parameters...
  Set<String> xslKeys = m_xslParams.keySet();
  for( String xslKey : xslKeys )
    transformer.setParameter( xslKey, m_xslParams.get( xslKey ) );

  Source source = new StreamSource( m_xmlData );
  Result result = new SAXResult( transformerHandler );
  saxTransformerFactory.newTransformer().transform( source, result );
  Document document = (org.w3c.dom.Document)domResult.getNode(); 

  XPathFactory factory = XPathFactory.newInstance();

  String expression = ".//block[@id='" + "HeaderID" + "']/@bpd";
  String item = "fo:block";
  QName returnType = XPathConstants.NUMBER;

  Object returnValue = factory.newXPath().evaluate( expression, item, returnType );
  double height_in_milipoints = Double.parseDouble( (String)returnValue );


The for loop is used to set report parameters such as page size, page margins, report title, etc.

When I run the above code, I get an XPathExpressionException.  Unfortunately there is no detailed message.

The snippet of my XSL file is:

  <fo:static-content flow-name="xsl-region-before">
    <fo:block id="HeaderID" font-family="{$header-font-family}"
font-size="{$header-font-size}" font-style="{$header-font-style}"
text-align="center"><xsl:value-of select="$report-title"/></fo:block>
  </fo:static-content>

I'm not sure what I am doing wrong.  When I debug the Java and inspect the "document" variable it seems to have lots of stuff - but can't actually figure out how to locate the node I want.


If easier or you prefer, send me a direct email and we can then work out how to IM each other.


Thanks again,

Bernmeister.
--
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23248181.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: AW: AW: Change the header/footer size in a PDF

Posted by Bernmeister <th...@hotmail.com>.
Hi Georg,

Thanks again for your help.  Getting there slowly...

I believe I've managed to get to the point of getting a document back from
the transformation.  The code is below:


  FopFactory fopFactory = FopFactory.newInstance();
  FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

  SAXTransformerFactory saxTransformerFactory =
(SAXTransformerFactory)TransformerFactory.newInstance();
  TransformerHandler transformerHandler = 
saxTransformerFactory.newTransformerHandler( new StreamSource(
m_xslStylesheet ) );
  DOMResult domResult = new DOMResult(); 
  transformerHandler.setResult( domResult );
                
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                
  BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( new
FileOutputStream( m_outputPDFFile ) );
  Fop fop = fopFactory.newFop( MimeConstants.MIME_FOP_AREA_TREE,
foUserAgent, bufferedOutputStream );
  Transformer transformer = saxTransformerFactory.newTransformer();
                
  // Set report parameters...
  Set<String> xslKeys = m_xslParams.keySet();
  for( String xslKey : xslKeys )
    transformer.setParameter( xslKey, m_xslParams.get( xslKey ) );

  Source source = new StreamSource( m_xmlData );
  Result result = new SAXResult( transformerHandler );
  saxTransformerFactory.newTransformer().transform( source, result );
  Document document = (org.w3c.dom.Document)domResult.getNode(); 

  XPathFactory factory = XPathFactory.newInstance();

  String expression = ".//block[@id='" + "HeaderID" + "']/@bpd";
  String item = "fo:block";
  QName returnType = XPathConstants.NUMBER;

  Object returnValue = factory.newXPath().evaluate( expression, item,
returnType );
  double height_in_milipoints = Double.parseDouble( (String)returnValue );


The for loop is used to set report parameters such as page size, page
margins, report title, etc.

When I run the above code, I get an XPathExpressionException.  Unfortunately
there is no detailed message.

The snippet of my XSL file is:

  <fo:static-content flow-name="xsl-region-before">
    <fo:block id="HeaderID" font-family="{$header-font-family}"
font-size="{$header-font-size}" font-style="{$header-font-style}"
text-align="center"><xsl:value-of select="$report-title"/></fo:block>
  </fo:static-content>

I'm not sure what I am doing wrong.  When I debug the Java and inspect the
"document" variable it seems to have lots of stuff - but can't actually
figure out how to locate the node I want.


If easier or you prefer, send me a direct email and we can then work out how
to IM each other.


Thanks again,

Bernmeister.
-- 
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23248181.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


AW: AW: Change the header/footer size in a PDF

Posted by Georg Datterl <ge...@geneon.de>.
Hi Bernmeister, 

Nope, sorry, I already send in the transformed fo file. But it hardly matters. You don't change the input, you don't change the process, you only change the output format and the result:

DOMResult domResult = new DOMResult();
handler.setResult(domResult);
Fop fop = getFopFactory().newFop(MimeConstants.MIME_FOP_AREA_TREE, foUserAgent);

And then you get the result for further processing:

return  (org.w3c.dom.Document)domResult.getNode();

For the xpath stuff you create your xpath object:

XPathFactory factory=XPathFactory.newInstance();
XPath xPath=factory.newXPath();

and ask it for the height:

double height_in_milipoints = xPath.evaluate(".//block[@prod-id='"+<your id>+"']/@bpd", <your document root>, XPathConstants.NUMBER)

That should be the difference to what you already have for PDf generation.

Mit freundlichen Grüßen
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Bernmeister [mailto:thebernmeister@hotmail.com] 
Gesendet: Freitag, 24. April 2009 14:26
An: fop-users@xmlgraphics.apache.org
Betreff: Re: AW: Change the header/footer size in a PDF


Thanks Georg for the quick response!

I must admit I'm not too familiar with java.xml.* package - just able to render out a PDF and that's it.  So I'm having difficulty following your example.

Assuming I have a template.xsl file and a data.xml file, I assumed I would have to simulate/emulate using FOP to transform the data.xml via the template.xsl into a PDF (or really a tree in memory).

In your example I follow that the xsl is passed in...but I don't see how/where the data.xml would come into it.

If this is not the right forum, any ideas where/who I should try?


Thanks again!



Georg Datterl wrote:
> 
> Hi Bernmeister,
> 
> You can do that. Take the block element, where your user can put the 
> text in. Give it an ID. Render to the area tree. Use Xpath and the ID 
> to find the block. Ask for ist height. Use this height/1000 (+ 
> paddings, spaces,
> ...) to set the extent. 
> 
>     private org.w3c.dom.Document multipass(Page p) {
>         StringBuffer sb = new StringBuffer();
>         sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
>         sb.append(("<fo:root
> xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"" +
>                 "
> xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\" >" +
>             "<fo:layout-master-set>"));
>         for(PageMaster pm : p.getPageMasters().values()) {
>             sb.append(pm);
>         }
>         sb.append(p.getPageSequence());
>         sb.append("</fo:layout-master-set>");
>         sb.append(p);
>         sb.append("</fo:root>");
>         return multipass(sb);
>     }
> 
>     private org.w3c.dom.Document multipass(StringBuffer sb) {
>         try{
>             return multipass(new StreamSource(new 
> ByteArrayInputStream(sb.toString().getBytes("UTF-8"))));
>         } catch (IOException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         }
>         return null;
>     }
> 
>     private org.w3c.dom.Document multipass(StreamSource source) {
>         try {
>             FOUserAgent foUserAgent = getFopFactory().newFOUserAgent();
>             Transformer transformer = 
> getMultipassFactory().newTransformer();
>             TransformerHandler handler = 
> getMultipassFactory().newTransformerHandler();
>             DOMResult domResult = new DOMResult();
>             handler.setResult(domResult);
> 
>             org.apache.fop.render.Renderer targetRenderer =
>             foUserAgent.getRendererFactory().createRenderer(
>                             foUserAgent, MimeConstants.MIME_PDF);
> 
>             XMLRenderer renderer = new XMLRenderer();
>             renderer.mimicRenderer(targetRenderer);
>             renderer.setContentHandler(handler);
>             renderer.setUserAgent(foUserAgent);
> 
>             foUserAgent.setRendererOverride(renderer);
>             
>             Fop fop =
> getFopFactory().newFop(MimeConstants.MIME_FOP_AREA_TREE, foUserAgent);
>             Result res = new SAXResult(fop.getDefaultHandler());
>             transformer.transform(source, res);
>             return  (org.w3c.dom.Document)domResult.getNode();
>         } catch (TransformerException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         } catch (FOPException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
> //        } catch (IOException e) {
> //            System.out.println(e.getMessage());
> //            e.printStackTrace();
>         } catch (SAXException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         }
>         return null;
>     }
> 
> double height_in_milipoints = 
> xPath.evaluate(".//block[@prod-id='"+<your
> id>+"']/@bpd", <your document root>, XPathConstants.NUMBER)
> 
> Mit freundlichen Grüßen
>  
> Georg Datterl
>  
> ------ Kontakt ------
>  
> Georg Datterl
>  
> Geneon media solutions gmbh
> Gutenstetter Straße 8a
> 90449 Nürnberg
>  
> HRB Nürnberg: 17193
> Geschäftsführer: Yong-Harry Steiert
> 
> Tel.: 0911/36 78 88 - 26
> Fax: 0911/36 78 88 - 20
>  
> www.geneon.de
>  
> Weitere Mitglieder der Willmy MediaGroup:
>  
> IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
> Willmy PrintMedia GmbH:                            www.willmy.de
> Willmy Consult & Content GmbH:                 www.willmycc.de 
> -----Ursprüngliche Nachricht-----
> Von: Bernmeister [mailto:thebernmeister@hotmail.com]
> Gesendet: Freitag, 24. April 2009 06:40
> An: fop-users@xmlgraphics.apache.org
> Betreff: Change the header/footer size in a PDF
> 
> 
> Hi,
> 
> I have a simple XSL report with header, body and footer which renders 
> to a PDF.  My Java application passes variables to the XSL to set 
> body-margin, header/footer-extent and font sizes.
> 
> I set the header size (in point not mm) to be slightly larger than the 
> font size for text to appear in the header.  This works fine - gives 
> enough space for the header to hold all the text.
> 
> However, if the text in the header (which is set by a user back in the
> application) is "longer" than the width of the header, that text will 
> carry over to a next line...and so bleed into the body.
> 
> I've seen this post from a while back
> http://www.nabble.com/Auto-size-header-to-fit-with-content---td4765740
> .html#a4765740
> 
> ...but it doesn't really help.  Hardcoding for line height, text 
> height, etc, etc is too dangerous.
> 
> I've scoured the FOP Javadoc and cannot seem to figure out if it's 
> possible to access the rendered PDF (as some sort of tree or data 
> object) and work out if the header text has wrapped.  Is it possible 
> to determine this and so fix it?
> 
> Or is it possible to access the PDF itself and determine if wrapping 
> has occurred in the header?
> 
> If I can detect the header has wrapped text (or footer for that 
> matter), I can just increase the header by the original amount and re-render to PDF.
> 
> 
> Thanks in advance,
> 
> Bernmeister.
> --
> View this message in context:
> http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp2320974
> 8p23209748.html Sent from the FOP - Users mailing list archive at 
> Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

--
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23215438.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: AW: Change the header/footer size in a PDF

Posted by Bernmeister <th...@hotmail.com>.
Thanks Georg for the quick response!

I must admit I'm not too familiar with java.xml.* package - just able to
render out a PDF and that's it.  So I'm having difficulty following your
example.

Assuming I have a template.xsl file and a data.xml file, I assumed I would
have to simulate/emulate using FOP to transform the data.xml via the
template.xsl into a PDF (or really a tree in memory).

In your example I follow that the xsl is passed in...but I don't see
how/where the data.xml would come into it.

If this is not the right forum, any ideas where/who I should try?


Thanks again!



Georg Datterl wrote:
> 
> Hi Bernmeister,
> 
> You can do that. Take the block element, where your user can put the text
> in. Give it an ID. Render to the area tree. Use Xpath and the ID to find
> the block. Ask for ist height. Use this height/1000 (+ paddings, spaces,
> ...) to set the extent. 
> 
>     private org.w3c.dom.Document multipass(Page p) {
>         StringBuffer sb = new StringBuffer();
>         sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
>         sb.append(("<fo:root
> xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"" +
>                 "
> xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\" >" +
>             "<fo:layout-master-set>"));
>         for(PageMaster pm : p.getPageMasters().values()) {
>             sb.append(pm);
>         }
>         sb.append(p.getPageSequence());
>         sb.append("</fo:layout-master-set>");
>         sb.append(p);
>         sb.append("</fo:root>");
>         return multipass(sb);
>     }
> 
>     private org.w3c.dom.Document multipass(StringBuffer sb) {
>         try{
>             return multipass(new StreamSource(new
> ByteArrayInputStream(sb.toString().getBytes("UTF-8"))));
>         } catch (IOException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         }
>         return null;
>     }
> 
>     private org.w3c.dom.Document multipass(StreamSource source) {
>         try {
>             FOUserAgent foUserAgent = getFopFactory().newFOUserAgent();
>             Transformer transformer = 
> getMultipassFactory().newTransformer();
>             TransformerHandler handler =
> getMultipassFactory().newTransformerHandler();
>             DOMResult domResult = new DOMResult();
>             handler.setResult(domResult);
> 
>             org.apache.fop.render.Renderer targetRenderer =
>             foUserAgent.getRendererFactory().createRenderer(
>                             foUserAgent, MimeConstants.MIME_PDF);
> 
>             XMLRenderer renderer = new XMLRenderer();
>             renderer.mimicRenderer(targetRenderer);
>             renderer.setContentHandler(handler);
>             renderer.setUserAgent(foUserAgent);
> 
>             foUserAgent.setRendererOverride(renderer);
>             
>             Fop fop =
> getFopFactory().newFop(MimeConstants.MIME_FOP_AREA_TREE, foUserAgent);
>             Result res = new SAXResult(fop.getDefaultHandler());
>             transformer.transform(source, res);
>             return  (org.w3c.dom.Document)domResult.getNode();
>         } catch (TransformerException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         } catch (FOPException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
> //        } catch (IOException e) {
> //            System.out.println(e.getMessage());
> //            e.printStackTrace();
>         } catch (SAXException e) {
>             System.out.println(e.getMessage());
>             e.printStackTrace();
>         }
>         return null;
>     }
> 
> double height_in_milipoints = xPath.evaluate(".//block[@prod-id='"+<your
> id>+"']/@bpd", <your document root>, XPathConstants.NUMBER)
> 
> Mit freundlichen Grüßen
>  
> Georg Datterl
>  
> ------ Kontakt ------
>  
> Georg Datterl
>  
> Geneon media solutions gmbh
> Gutenstetter Straße 8a
> 90449 Nürnberg
>  
> HRB Nürnberg: 17193
> Geschäftsführer: Yong-Harry Steiert 
> 
> Tel.: 0911/36 78 88 - 26
> Fax: 0911/36 78 88 - 20
>  
> www.geneon.de
>  
> Weitere Mitglieder der Willmy MediaGroup:
>  
> IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
> Willmy PrintMedia GmbH:                            www.willmy.de
> Willmy Consult & Content GmbH:                 www.willmycc.de 
> -----Ursprüngliche Nachricht-----
> Von: Bernmeister [mailto:thebernmeister@hotmail.com] 
> Gesendet: Freitag, 24. April 2009 06:40
> An: fop-users@xmlgraphics.apache.org
> Betreff: Change the header/footer size in a PDF
> 
> 
> Hi,
> 
> I have a simple XSL report with header, body and footer which renders to a
> PDF.  My Java application passes variables to the XSL to set body-margin,
> header/footer-extent and font sizes.
> 
> I set the header size (in point not mm) to be slightly larger than the
> font size for text to appear in the header.  This works fine - gives
> enough space for the header to hold all the text.  
> 
> However, if the text in the header (which is set by a user back in the
> application) is "longer" than the width of the header, that text will
> carry over to a next line...and so bleed into the body.
> 
> I've seen this post from a while back
> http://www.nabble.com/Auto-size-header-to-fit-with-content---td4765740.html#a4765740
> 
> ...but it doesn't really help.  Hardcoding for line height, text height,
> etc, etc is too dangerous.
> 
> I've scoured the FOP Javadoc and cannot seem to figure out if it's
> possible to access the rendered PDF (as some sort of tree or data object)
> and work out if the header text has wrapped.  Is it possible to determine
> this and so fix it?  
> 
> Or is it possible to access the PDF itself and determine if wrapping has
> occurred in the header?
> 
> If I can detect the header has wrapped text (or footer for that matter), I
> can just increase the header by the original amount and re-render to PDF.
> 
> 
> Thanks in advance,
> 
> Bernmeister.
> --
> View this message in context:
> http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23209748.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23215438.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


AW: Change the header/footer size in a PDF

Posted by Georg Datterl <ge...@geneon.de>.
Hi Bernmeister,

You can do that. Take the block element, where your user can put the text in. Give it an ID. Render to the area tree. Use Xpath and the ID to find the block. Ask for ist height. Use this height/1000 (+ paddings, spaces, ...) to set the extent. 

    private org.w3c.dom.Document multipass(Page p) {
        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        sb.append(("<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"" +
                " xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\" >" +
            "<fo:layout-master-set>"));
        for(PageMaster pm : p.getPageMasters().values()) {
            sb.append(pm);
        }
        sb.append(p.getPageSequence());
        sb.append("</fo:layout-master-set>");
        sb.append(p);
        sb.append("</fo:root>");
        return multipass(sb);
    }

    private org.w3c.dom.Document multipass(StringBuffer sb) {
        try{
            return multipass(new StreamSource(new ByteArrayInputStream(sb.toString().getBytes("UTF-8"))));
        } catch (IOException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    private org.w3c.dom.Document multipass(StreamSource source) {
        try {
            FOUserAgent foUserAgent = getFopFactory().newFOUserAgent();
            Transformer transformer =  getMultipassFactory().newTransformer();
            TransformerHandler handler = getMultipassFactory().newTransformerHandler();
            DOMResult domResult = new DOMResult();
            handler.setResult(domResult);

            org.apache.fop.render.Renderer targetRenderer =
            foUserAgent.getRendererFactory().createRenderer(
                            foUserAgent, MimeConstants.MIME_PDF);

            XMLRenderer renderer = new XMLRenderer();
            renderer.mimicRenderer(targetRenderer);
            renderer.setContentHandler(handler);
            renderer.setUserAgent(foUserAgent);

            foUserAgent.setRendererOverride(renderer);
            
            Fop fop = getFopFactory().newFop(MimeConstants.MIME_FOP_AREA_TREE, foUserAgent);
            Result res = new SAXResult(fop.getDefaultHandler());
            transformer.transform(source, res);
            return  (org.w3c.dom.Document)domResult.getNode();
        } catch (TransformerException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (FOPException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
//        } catch (IOException e) {
//            System.out.println(e.getMessage());
//            e.printStackTrace();
        } catch (SAXException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

double height_in_milipoints = xPath.evaluate(".//block[@prod-id='"+<your id>+"']/@bpd", <your document root>, XPathConstants.NUMBER)

Mit freundlichen Grüßen
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Bernmeister [mailto:thebernmeister@hotmail.com] 
Gesendet: Freitag, 24. April 2009 06:40
An: fop-users@xmlgraphics.apache.org
Betreff: Change the header/footer size in a PDF


Hi,

I have a simple XSL report with header, body and footer which renders to a PDF.  My Java application passes variables to the XSL to set body-margin, header/footer-extent and font sizes.

I set the header size (in point not mm) to be slightly larger than the font size for text to appear in the header.  This works fine - gives enough space for the header to hold all the text.  

However, if the text in the header (which is set by a user back in the
application) is "longer" than the width of the header, that text will carry over to a next line...and so bleed into the body.

I've seen this post from a while back
http://www.nabble.com/Auto-size-header-to-fit-with-content---td4765740.html#a4765740

...but it doesn't really help.  Hardcoding for line height, text height, etc, etc is too dangerous.

I've scoured the FOP Javadoc and cannot seem to figure out if it's possible to access the rendered PDF (as some sort of tree or data object) and work out if the header text has wrapped.  Is it possible to determine this and so fix it?  

Or is it possible to access the PDF itself and determine if wrapping has occurred in the header?

If I can detect the header has wrapped text (or footer for that matter), I can just increase the header by the original amount and re-render to PDF.


Thanks in advance,

Bernmeister.
--
View this message in context: http://www.nabble.com/Change-the-header-footer-size-in-a-PDF-tp23209748p23209748.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org