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(".//blo...@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:[email protected]]
Gesendet: Freitag, 24. April 2009 14:26
An: [email protected]
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(".//blo...@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:[email protected]]
> Gesendet: Freitag, 24. April 2009 06:40
> An: [email protected]
> 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: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
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: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]