Geeks With Blogs
Łukasz Kuryło's blog

Some time ago I showed how to get an intellisense and how to configure the FO.NET to acquire national characters inside the generated pdf files.

Due to the limitations that I mensioned in my previous post, I started playing with the Apache FOP. In this post I want to show, how to acquire the same result as I showed in the two posts related to FO.NET.

 

Intellisense

 

To get the intellisense from the XSL-FO templates set the xsi:schemaLocation the same way I showed it in this post.

The only diffrence to FO.NET is that, during generating the document by the code I showed last time we will get an exception:

 

org.apache.fop.fo.ValidationException: Invalid property encountered on "fo:root": xsi:schemaLocation (See position 6:11)

 

Fortunatelly there is a very easy way to resolve this without removing the entire attribute along with the intellisense.

Add to the FopFactory the ignoreNamespace by:

 

FopFactory fopFactory = FopFactory.newInstance();

fopFactory.ignoreNamespace(http://www.w3.org/2001/XMLSchema-instance);

 

Notice that, the url specified in this method this is a namespace for the xmlns:xsi namespace, not xsi.schemaLocation.

 

Fonts / national characters

 

This point is a little dfferent to acquire, but not more complicated that it was with FO.NET.

To set the fonts in Apache FOP 1.0, we need a configuration file. A sample one can be get from the directory where we unpacked the fop binaries, from conf subdirectory. There is a file called fop.xconf. We must copy this file to our solution.

In the simplest way, in the <fonts> tag we can add  <auto-detect/>. Thanks to this, FOP will index all fonts available on the installed operating system. There probably should be no problem, if we have a http handler or a WCF Service on the server that serves the generated pdf documents. In this situation we can use all available fonts on this server.

 

To use this config file, we must set a path to it:

 

FopFactory fopFactory = FopFactory.newInstance();

fopFactory.setUserConfig(new File("fop.xconf"));

Posted on Monday, October 15, 2012 9:23 PM XSL FO | Back to top


Comments on this post: XSL-FO intellisense and national languages with Apache FOP

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
FopException on fopFactory.setUserConfig("fop.xconf");
What I do wrong?
Left by Kukas on Oct 18, 2012 3:12 PM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
what the error says?
do you have this file in the output catalog bin/Debug or bin/Release, the same where the compiled binaries are?
Left by Łukasz Kuryło on Oct 18, 2012 7:26 PM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
Yes. fop.xconf exist in bin/Debug

org.apache.fop.apps.FOPException
Message=""
Source=fop
StackTrace:
org.apache.fop.util.LogUtil.handleException(Log log, Exception e, Boolean strict)
org.apache.fop.apps.FopFactoryConfigurator.configure(FopFactory factory)
org.apache.fop.apps.FopFactoryConfigurator.setUserConfig(Configuration cfg)
org.apache.fop.apps.FopFactoryConfigurator.setUserConfig(String uri)
org.apache.fop.apps.FopFactory.setUserConfig(String uri)
.........
I'm using last version fop & ikvm.
No configuration works fine. Maybe some DLL missing? I add in project IKVM.OpenJDK.*.dll and IKVM.Runtime.dll
Thanks.
Left by Kukas on Oct 19, 2012 7:39 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
Oh, sorry. I get exception, because config path contain cyrilic symbols or some bad symbols. Thank you for the reply.



Left by Kukas on Oct 19, 2012 7:59 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
I'm glad it works
Left by Łukasz Kuryło on Oct 19, 2012 6:09 PM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
Hi again! I have a problem with fopFactory.setUserConfig(new File("fop.xconf"))
where path of config file it's folder on the network. Do you have this problem too?
Left by Kukas on Oct 29, 2012 8:17 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
I haven't checked this with shared catalog on the network, but I believe there could be a problems with the permissions. What error did you get?
Left by Łukasz Kuryło on Oct 29, 2012 11:56 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
look here: http://www.allinterview.com/showanswers/63120.html
Left by Łukasz Kuryło on Oct 29, 2012 2:41 PM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
Empty exception message. But, when I add construction fopFactory.setUserConfig(new File("fop.xconf")) in try catch block - this work fine, config loaded and my font uses.I don't like strange things.
Left by Kukas on Oct 30, 2012 10:11 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
If you get an empty exception, try to look into the Inner one. Maybe there is an additional info.
Left by Łukasz Kuryło on Oct 30, 2012 10:17 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
"((System.Type)(((System.Reflection.MethodInfo)(((System.Exception)($exception)).TargetSite)).ReturnType)).DeclaringMethod" launched an exception of type "System.InvalidOperationException"

"The method can only be called the method for which the value Type.IsGenericParameter is true."
What does this mean?
Left by Kukas on Oct 31, 2012 5:58 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
If path of net folder not include cyrilic symbols i get exception [java.net.ConnectException]
{"Connection refused: connect"} java.net.ConnectException
Else empty inner exception.
Left by Kukas on Oct 31, 2012 6:25 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
In all cases i get empty exception
Left by Kukas on Oct 31, 2012 6:52 AM

# re: XSF-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
As a result, when path include cyrylic symbols:

File f = new File(@"T:\some_cyrilic\Report\bin\fop.xconf");
when T:\ is mapped network drives, i use
fopFactory.setUserConfig(f.toURI().toString()); - fine!
If file not exist i have {"Connection refused: connect"} java.net.ConnectException

Another,
File f = new File("\\\\Server\\Report\\bin\\fop.xconf");
fopFactory.setUserConfig(f.toURI().toString()); - empty exception!
Left by Kukas on Oct 31, 2012 7:31 AM

# re: XSL-FO intellisense and national languages with Apache FOP
Requesting Gravatar...
Right now I get an empty exception from fopFactory.newFop(..)
with no other inner exceptions. It worked before I embedded this in the wcf service.
I understand your pain. If I remove the config file, the exception not occur. I try to figure out what is going on and make some post with explanation.
Left by Łukasz Kuryło on Nov 02, 2012 11:03 AM

Comments have been closed on this topic.
Copyright © Łukasz Kuryło | Powered by: GeeksWithBlogs.net