Hi Matthias

I don't think DestinationType would be the right place to hold the
configuration information. That's the Main class where the command-line
parameters are processed and then set on the SVGConverter using simple
bean-style calls. SVGConverter.computeTranscodingHints() is then where
the parameters are turned into transcoding hints that make the
configuration for the transcoders. I'd probably rather look in that
direction.

However, as you noticed, the bigger problem is that the PDFTranscoder
currently doesn't support setting a URIResolver. It does support setting
an EntityResolver programmatically but that doesn't help with resolving
fonts since only a dummy FontResolver is set up [1].
Also, a font configuration can currently only be set via
PDFTranscoder.configure() (i.e. no transcoding hint) which requires an
Avalon Configuration object as parameter.

So, the whole business is not quite as simple at the moment. I think you
have two options:

1. Improve FOP's PDFTranscoder and AbstractFOPTranscoder to enable
setting configuration files and URIResolvers (for font resolution) via
transcoding hints. Then improve SVGConverter to support them. I'd
probably use an URI/URL as data type for the configuration file and let
the PDFTranscoder actually load it (using URIResolver as a helper if
available).

2. Don't use SVGConverter for creating PDFs from SVG. From the
command-line, FOP supports the -imagein parameter where you can create
PDFs directly from SVGs. There's very little magic behind that if you
want to reproduce that programmatically: Look for image2fo.xsl in FOP
and wrap the URI for your SVG in an <image> tag. See [2]. That way you
can use all of FOP's power with configuration and URIResolvers. The only
downside is that you can't transcode only parts of an SVG and maybe some
other smaller options supported by SVGConverter. Depends on your
requirements.

[1] 
org.apache.fop.svg.PDFDocumentGraphics2DConfigurator.createFontInfo(Configuration)
[2] org.apache.fop.cli.ImageInputHandler

BTW, copying some classes from Batik/FOP and modifying them is one way.
The other, better way, would be to modify Batik/FOP directly and post
patches for them so that additional functionality can be incorporated in
the products themselves (it's useful stuff after all). And it's how open
source software evolves.

HTH

On 28.09.2011 09:06:57 gerber wrote:
> Dear Batik Developers/Users
> 
> Abstract: I have difficulty providing specific (not auto-detected) font 
> information to an SVGConverter instance for converting to PDF's.
> 
> What we do:
> We are using batik to convert svg images in to different formats.
> We also use fop for transforming xml-files in to PDF's.
> One major thing is to supply the correct fonts for these libraries.
> I did so for fop when used as xslt-fo engine to create PDF's by supplying 
> a user configuration and and custom URIResolver to the FOP-Factory.
> We use an SVGConverter of batik instance for converting SVG in different 
> formats.
> The fonts work fine for images like image/png. I took care of this by 
> using java GraphicsEnvironment.
> The problem is, when I want to transform an svg-image in to a PDF. 
> There the fonts have to be supplied to fop, that is used inside batik 
> (SVGConverter).
> The problem is, that I am not able to supply the font configuration and 
> and URIResolver to the PDFTranscoder used inside SVGConverter.
> So I thought about extending the DestinationType class, which is 
> responsible for creating the PDFTranscoder,
> so that DestinationType can suppliy the  PDFTranscoder with the needed 
> font configuration.
> Unfortunately the class DestinationType is declared as final, so I can not 
> extend it.
> And additionally, PDFTranscoder knows nothing about custom URIResolver, as 
> far as i saw.
> I don't want to use the auto-detect feature, becaus of performance issues 
> (scans to much directories/jars for finding the fonts).
> 
> Is there a way to add a font configuration and an URIResolver 
> programmatically (i think embedded is the term you use) to batik 
> SVGConverter for PDF-Transformation.
> I really would hate to copy the existing classes (SVGConverter, 
> DestinationType , PDFTranscoder ) and modify them :-)
> 
> thanks for your help and best regards.
> Matthias Gerber
> 

Gruess vo Lozärn uf Davos ufe,
Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org

Reply via email to