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 Saptarshi Sen <Sa...@mindtree.com> on 2004/12/22 08:23:33 UTC

Handling multiple spaces

Hi,
	We are using FOP to convert SVG images into PDF. The SVG images are
generated using a tool called PopChart.

	When we view the SVG image, multiple spaces are collapsed into a
single space. This can be offset using the xml:space="preserve" attribute in
the text tags. Is there any other method by which we can preserve multiple
spaces.

	Since I do not have any control over the SVG image produced by
PopChart, can I set any parameters during the FOP call? Alternatively, I
could include the  xml:space="preserve" attribute in my text tags, but this
would be very messy. Is there an easier approach?

Thanks,
Saptarshi.

Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
On 23.12.2004 17:29:45 Saptarshi Sen wrote:
> This is getting increasingly away from FOP and closer to
> Batik.....

I hope that's not a problem for you. FOP is a XSL-FO converter while
Batik is an SVG converter. FOP just happens to implement the part that
converts SVG to PDF. This aspect is suboptimal and is going to be
addressed. The PDF Transcoder will move to a different location closer
to the Batik subproject in the near future.

> nevertheless, I am continuing along this thread to get some more
> inputs.
> 
> I have added all the jar's under batik's lib folder into my project as well
> as my Weblogic domain (where other libraries are placed).
> 
> However, when I try to run the application I get a
> java.lang.NoClassDefFoundError:
> org/apache/batik/transcoder/TranscoderException. Is there anything that I am
> missing. (I found a similar query by another person who was using Tomcat. The
> reply simply asked him to include the jars under the web container's lib
> directory).
> 
> 
> In my case, I have all the jar's already in my Weblogic's application folder.

The TranscoderException is in batik-transcoder.jar. Looks like you've
fallen victim to classloading problems with Weblogic. As I don't have
Weblogic it's certainly a bit difficult to provide assistance here. I'd
simply make sure that the necessary JARs for SVG processing are all at
the same location so they make it into the same ClassLoader. Make sure
not to create strange setups with XML Parsers (Xerces et al.) as they
are covered by the JDK/JRE assuming you work with >=1.4.

Jeremias Maerki


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


Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
Uh, now it gets complicated....

On 23.12.2004 14:32:56 Saptarshi Sen wrote:
> Hi,
> 	I got the desired output using Batik. I am now trying to integrate it
> into my application.
> 
> 	Since Batik uses the PDFTranscoder class from FOP, what are the
> various jar's that I need to include in my project path. I understand that I
> should remove the fop.jar (from version 0.20.5) from my project path. Which
> are the jar's from batik 1.5.1 that I need to include.

I think you need all JARs from the lib directory of the binary
distribution except batik-svggen.jar and batik-swing.jar. Not sure. I'd
have to do a trial-and-error. pdf-transcoder.jar contains all classes
needed by FOP's PDF Transcoder.

> 	A few requirements in my application is that I'll be embedding custom
> fonts and using batik just for SVG to PDF conversion.

Now for the tricky part. Font configuration for the new transcoder is
not documented, yet, and it's a bit different than in FOP 0.20.5 and may
even change again until the first release of the redesign code.

Here's a snippet to create an Avalon Configuration Object with the font
configuration:

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.container.ContainerUtil;

import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.XMLAbstractTranscoder;
import org.apache.batik.transcoder.image.ImageTranscoder;

[..]

//Transcoder instantiation
Transcoder transcoder = transcoder = new org.apache.fop.svg.PDFTranscoder();

[..]

//Font configuration
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(new File("src/xml/pdf-transcoder-cfg.xml"));
ContainerUtil.configure(transcoder, cfg);

[..]

//Transcoder properties supported by the PDF Transcoder
int dpi = 300;
transcoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 
        new Float((float)(25.4 / dpi))); 
transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE);
transcoder.addTranscodingHint(PDFTranscoder.KEY_STROKE_TEXT, Boolean.FALSE);

[..]

//On with the normal transcoding process as documented in Batik...



The XML file for the font configuration would look approximately like
this:

      <cfg>
        <fonts>
          <font metrics-url="file:C:/Dev/FOP/temp/fonts/FUTURAL.ttf.xml" kerning="no" embed-url="file:C:/Dev/FOP/Temp/fonts/FUTURAL.ttf">
            <font-triplet name="Futura" style="normal" weight="200"/>
            <font-triplet name="Futura" style="normal" weight="normal"/>
          </font>
          <font metrics-url="file:C:\Dev\FOP\temp\fonts\ARIAL.TTF.xml" kerning="no" embed-url="file:C:/Dev/FOP/Temp/fonts/ARIAL.ttf">
            <font-triplet name="Arial" style="normal" weight="normal"/>
          </font>
          <font metrics-url="file:C:\Dev\FOP\temp\fonts\ARIALBD.TTF.xml" kerning="no" embed-url="file:C:/Dev/FOP/Temp/fonts/ARIALBD.ttf">
            <font-triplet name="Arial" style="normal" weight="bold"/>
          </font>
        </fonts>
      </cfg>


There's one potential problem, though: I don't know what version of the
PDF Transcoder is in the Batik 1.5.1 release. That part didn't get
released properly. It could be that the font configuration doesn't work,
but I hope so.


Jeremias Maerki


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


Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
Same here. That's why I said earlier, that you should use the PDF
Transcoder (not FOP itself) if you can live without XSL-FO, because if
you need XSL-FO (which I don't know) then you've got bad luck because
there's currently no work-around. The CVS HEAD code is our code
currently being redesigned and it will probably not work for any
real-life application at the moment.

I've just verified the following with success:
- Download Batik 1.5.1 (http://xml.apache.org/batik/)
- Extract the SVG from the FO file into a plain SVG file.
- On the command-line say: 
java -jar batik-rasterizer.jar -m application/pdf pieUnicode.svg

(This uses FOP's PDF Transcoder to convert SVG to PDF. No XSL-FO
involved.)

Produces a nice PDF with spaces respected. If you need to integrate that
in a Java application, then look at the Transcoder documentation here:
http://xml.apache.org/batik/rasterizerTutorial.html
http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleSVG2PDF.java?rev=HEAD

On 23.12.2004 12:07:50 Saptarshi Sen wrote:
> Hi,
> 	I tried to download the latest Code from
> http://cvs.apache.org/snapshots/xml-fop/xml-fop_20041223052817.tar.gz and
> then did a build on it. While converting the fo file into a PDF, I get the
> error:
> 
> Exception in thread "main" java.lang.OutOfMemoryError
>         <<no stack trace available>>
> 
> Attaching the fo file. What could be the possible reason?
> 
> Thanks,
> Saptarshi.
> 
> P.S. I performed the build using the "build.bat" file from FOP 0.20.5; The
> build was successful. Could this have anything to do with this error?


Jeremias Maerki


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


Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
(this is from fop-user@)

We seem to have the same problem we once had in the old code. The single
block with the instream-foreign-object doesn't fit the page for some
reason I haven't checked, yet, and gets sent over to the next page, and
the next, and the next.....You get the picture. With 64MB of Java heap
we get around 45000 empty pages into memory before the OutOfMemoryError
happens. :-) I'll put this on my todo list because I need to get into
layout anyway. But if someone has an easy solution already in mind, all
the better. ;-)

On 23.12.2004 12:07:50 Saptarshi Sen wrote:
> Hi,
> 	I tried to download the latest Code from
> http://cvs.apache.org/snapshots/xml-fop/xml-fop_20041223052817.tar.gz and
> then did a build on it. While converting the fo file into a PDF, I get the
> error:
> 
> Exception in thread "main" java.lang.OutOfMemoryError
>         <<no stack trace available>>
> 
> Attaching the fo file. What could be the possible reason?


Jeremias Maerki


Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
Please, always follow up on the fop-users mailing list so other people
can profit, too.

The right URL is actually this one:
http://cvs.apache.org/viewcvs.cgi/xml-fop/src/java/org/apache/fop/svg/PDFTranscoder.java

You need to download the HEAD tag (i.e. without any additional
parameters) from CVS as documented here:
http://xml.apache.org/fop/dev/index.html
http://xml.apache.org/cvs.html

Alternatively, CVS snapshots are here:
http://cvs.apache.org/snapshots/xml-fop/

Note to fop-devs: We don't seem to have a link to
http://xml.apache.org/fop/download.html in the menu structure anymore.

On 23.12.2004 10:38:10 Saptarshi Sen wrote:
> Hi,
> 	I was trying to get the PDFTranscoder from the head version (as you
> had mentioned). Was checking the logs at the following location:
> http://cvs.apache.org/viewcvs.cgi/xml-fop/src/org/apache/fop/svg/PDFTranscode
> r.java?hideattic=0&rev=1.25&view=log. Can you tell me which one will have the
> required fix; for respecting the xml:preserve attribute.
> 
> Thanks,
> Saptarshi.
> 
> -----Original Message-----
> From: Jeremias Maerki [mailto:dev.jeremias@greenmail.ch]
> Sent: Wednesday, December 22, 2004 7:07 PM
> To: fop-user@xml.apache.org
> Subject: Re: Handling multiple spaces
> 
> 
> Seems to be a bug in the SVG part in FOP 0.20.5. The attribute is
> respected in the new SVG transcoder (in FOP CVS HEAD), however. If you
> only need to convert the SVG into PDF (without any real need for XSL-FO),
> you can try the PDF Transcoder for Batik. Try the one shipped with the
> latest Batik release or if this still doesn't help, download the FOP
> source code from CVS (or using a CVS snapshot) to build the PDF
> Transcoder yourself.
> 
> On 22.12.2004 10:47:51 Saptarshi Sen wrote:
> > The xml:space="preserve" attribute does not seem to have any effect on the
> > PDF generated. The SVG image is within a fo:instream-foreign-object tag. I
> > could not find any attribute that will preserve white spaces.
> > 
> > I am attaching a typical fo file that we generate.
> > 
> > Thanks,
> > Saptarshi.
> > 
> >  <<pieUnicodeSVG.fo>> 
> > 
> > >  -----Original Message-----
> > > From: 	Saptarshi Sen  
> > > Sent:	Wednesday, December 22, 2004 12:54 PM
> > > To:	FOP Mailing List (E-mail)
> > > Subject:	Handling multiple spaces
> > > 
> > > Hi,
> > > 	We are using FOP to convert SVG images into PDF. The SVG images are
> > > generated using a tool called PopChart.
> > > 
> > > 	When we view the SVG image, multiple spaces are collapsed into a
> > > single space. This can be offset using the xml:space="preserve" attribute
> > > in the text tags. Is there any other method by which we can preserve
> > > multiple spaces.
> > > 
> > > 	Since I do not have any control over the SVG image produced by
> > > PopChart, can I set any parameters during the FOP call? Alternatively, I
> > > could include the  xml:space="preserve" attribute in my text tags, but
> this
> > > would be very messy. Is there an easier approach?
> > > 
> > > Thanks,
> > > Saptarshi.



Jeremias Maerki


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


Re: Handling multiple spaces

Posted by Jeremias Maerki <de...@greenmail.ch>.
Seems to be a bug in the SVG part in FOP 0.20.5. The attribute is
respected in the new SVG transcoder (in FOP CVS HEAD), however. If you
only need to convert the SVG into PDF (without any real need for XSL-FO),
you can try the PDF Transcoder for Batik. Try the one shipped with the
latest Batik release or if this still doesn't help, download the FOP
source code from CVS (or using a CVS snapshot) to build the PDF
Transcoder yourself.

On 22.12.2004 10:47:51 Saptarshi Sen wrote:
> The xml:space="preserve" attribute does not seem to have any effect on the
> PDF generated. The SVG image is within a fo:instream-foreign-object tag. I
> could not find any attribute that will preserve white spaces.
> 
> I am attaching a typical fo file that we generate.
> 
> Thanks,
> Saptarshi.
> 
>  <<pieUnicodeSVG.fo>> 
> 
> >  -----Original Message-----
> > From: 	Saptarshi Sen  
> > Sent:	Wednesday, December 22, 2004 12:54 PM
> > To:	FOP Mailing List (E-mail)
> > Subject:	Handling multiple spaces
> > 
> > Hi,
> > 	We are using FOP to convert SVG images into PDF. The SVG images are
> > generated using a tool called PopChart.
> > 
> > 	When we view the SVG image, multiple spaces are collapsed into a
> > single space. This can be offset using the xml:space="preserve" attribute
> > in the text tags. Is there any other method by which we can preserve
> > multiple spaces.
> > 
> > 	Since I do not have any control over the SVG image produced by
> > PopChart, can I set any parameters during the FOP call? Alternatively, I
> > could include the  xml:space="preserve" attribute in my text tags, but this
> > would be very messy. Is there an easier approach?
> > 
> > Thanks,
> > Saptarshi.



Jeremias Maerki


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