It usually is silly, but it's these silly things that keep money in our 
bank accounts.

Anyway, if you want to break the line at the space closest to 80 (but not 
after 80), this stylesheet will do it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns:fo="http://www.w3.org/1999/XSL/Format"; 
xmlns:fox="http://xml.apache.org/fop/extensions"; 
exclude-result-prefixes="fo">
  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" 
indent="yes"/>

  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="only" margin-top="1in" 
margin-left="1in" margin-right="1in" margin-bottom="1in">
          <fo:region-body region-name="only"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="only">
        <fo:flow flow-name="only">
          <xsl:call-template name="makeBlocks">
            <xsl:with-param name="string" select="."/>
          </xsl:call-template>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template name="makeBlocks">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="string-length($string) &gt; 80">
        <xsl:variable name="firstString">
          <xsl:call-template name="findSpace">
            <xsl:with-param name="string" select="substring($string, 1, 
80)"/>
          </xsl:call-template>
        </xsl:variable>
        <fo:block font-size="8pt" font-family="monospace"><xsl:value-of 
select="$firstString"/></fo:block>
        <xsl:call-template name="makeBlocks">
          <xsl:with-param name="string" select="substring($string, 
string-length($firstString) + 1, string-length($string))"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <fo:block font-size="8pt" font-family="monospace"><xsl:value-of 
select="$string"/></fo:block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="findSpace">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="not(contains($string, ' '))">
        <xsl:value-of select="$string"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="substring($string, string-length($string), 
string-length($string)) = ' '">
            <xsl:value-of select="$string"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="findSpace">
              <xsl:with-param name="string" select="substring($string, 1, 
string-length($string) - 1)"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

I tested it on this oddball file:

<inputText>a ab abc abcd abcde abcdef abcdefg abcdefgh abcdefghi 
abcdefghij abcdefghijkl abcdefghijklm abcdefghijklmn abcdefghijklmno a ab 
abc abcd abcde abcdef abcdefg abcdefgh abcdefghi abcdefghij abcdefghijkl 
abcdefghijklm abcdefghijklmn abcdefghijklmno a ab abc abcd abcde abcdef 
abcdefg abcdefgh abcdefghi abcdefghij abcdefghijkl abcdefghijklm 
abcdefghijklmn abcdefghijklmno</inputText>

And its output is:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
   <fo:layout-master-set>
      <fo:simple-page-master master-name="only" margin-top="1in" 
margin-left="1in" margin-right="1in" margin-bottom="1in">
         <fo:region-body region-name="only"/>
      </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="only">
      <fo:flow flow-name="only">
         <fo:block font-size="8pt" font-family="monospace">a ab abc abcd 
abcde abcdef abcdefg abcdefgh abcdefghi abcdefghij abcdefghijkl 
</fo:block>
         <fo:block font-size="8pt" font-family="monospace">abcdefghijklm 
abcdefghijklmn abcdefghijklmno a ab abc abcd abcde abcdef abcdefg 
</fo:block>
         <fo:block font-size="8pt" font-family="monospace">abcdefgh 
abcdefghi abcdefghij abcdefghijkl abcdefghijklm abcdefghijklmn </fo:block>
         <fo:block font-size="8pt" font-family="monospace">abcdefghijklmno 
a ab abc abcd abcde abcdef abcdefg abcdefgh abcdefghi </fo:block>
         <fo:block font-size="8pt" font-family="monospace">abcdefghij 
abcdefghijkl abcdefghijklm abcdefghijklmn abcdefghijklmno</fo:block>
      </fo:flow>
   </fo:page-sequence>
</fo:root>

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Ashley Martens" <[EMAIL PROTECTED]> 
04/21/2005 01:23 PM
Please respond to
[email protected]


To
<[email protected]>
cc

Subject
RE: Basic help needed






It's really silly. I'm creating this software to interface another 
company. That company returns a report as a text file, however, my client 
does not want his employees to be able to change the text file so he wants 
it converted to a PDF.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thu 4/21/2005 2:02 PM
To: [email protected]
Subject: Re: Basic help needed
 
Well, FO doesn't have any sense of breaking at an arbitrary number of 
characters. The FO idiom is to fill the line until the end of the line or 
the end of the text is reached.

If you really want to break the text every eighty lines, you can do it 
with XSLT and then put each chunk in its own block. Getting the line break 

to be at the last space before 80 characters will be a bit more 
interesting, but not impossible.

I'm curious why you would want to create a PDF representation of what is 
usually a pure-text representation method. Why not let PDF do what PDF 
does well (make paragraphs, have bold for emphasis, and so on)?

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Ashley Martens" <[EMAIL PROTECTED]> 
04/21/2005 12:50 PM
Please respond to
[email protected]


To
<[EMAIL PROTECTED]>
cc

Subject
Basic help needed






I trying to convert a simple text document, with no line feeds, into a 
simple PDF that is wrapped at 80 characters. Can anyone suggest the FO 
syntax to do this? 

E-Mail Confidentiality Notification

-----------------------------------

This e-mail message (and any associated files) contains information from 
Associated Software Consultants (ASC), Inc. and is intended only for the 
use of the individual or entity to which it is addressed and may contain 
information that is confidential, subject to copyright or constitutes a 
trade secret. If you are not the intended recipient you are hereby 
notified that any dissemination, copying or distribution of this message, 
or files associated with this message, is strictly prohibited. If you have 

received this message in error, please notify us immediately by replying 
to the message and deleting it from your computer. Messages sent to and 
from us may be monitored.

---------------------------------------------------------------------
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] 

E-Mail Confidentiality Notification

-----------------------------------

This e-mail message (and any associated files) contains information from 
Associated Software Consultants (ASC), Inc. and is intended only for the 
use of the individual or entity to which it is addressed and may contain 
information that is confidential, subject to copyright or constitutes a 
trade secret. If you are not the intended recipient you are hereby 
notified that any dissemination, copying or distribution of this message, 
or files associated with this message, is strictly prohibited. If you have 
received this message in error, please notify us immediately by replying 
to the message and deleting it from your computer. Messages sent to and 
from us may be monitored.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: winmail.dat
Description: Binary data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to