问题描述
最近我编译使用FOP,因为我想一些XML转换为PDF文件中的Android应用程序。不过,我不认为FOP JAR文件mean't工作在Android上。是否有任何版本的FOP的可用于Android?或者有什么其他的XML PDF格式转换器,我可以在我的应用程序,而不是连接到FOP功能的服务器在互联网上使用?
我试过,包括fop.jar和xmlgraphics.jar但即使有这些加入到我的项目中,调用 FopFactory.newInstance()
失败。
下面是我的code段的按钮点击调用FOP:
//添加按钮监听器
btnCreatePDF.setOnClickListener(新OnClickListener()
{
@覆盖
公共无效的onClick(视图v)
{
FopFactory fopFactory = FopFactory.newInstance();
的OutputStream OUT =新的BufferedOutputStream(新的FileOutputStream(新文件(/ SD卡/的test.pdf)));
FOP FOP = fopFactory.newFop(MimeConstants.MIME_PDF,出);
工厂的TransformerFactory = TransformerFactory.newInstance();
变压器变压器= factory.newTransformer();
来源SRC =新StreamSource的(新的文件(/ SD卡/ test.fo));
结果RES =新的SAXResult(fop.getDefaultHandler());
transformer.transform(SRC,RES);
out.close();
}
});
编译器也给予了我一堆 Dxwarning的:忽略InnerClasses属性...
错误。这里的错误,当我点击按钮来创建PDF:
02-22 14:16:23.641:WARN / System.err的(5590):java.lang.UnsupportedOperationException:不知道如何处理应用程序/ PDF格式作为输出格式。既不是FOEventHandler,也没有渲染器可以找到此输出格式。
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:361)
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.fo.FOTreeBuilder(FOTreeBuilder.java:105)。
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.apps.Fop.createDefaultHandler(Fop.java:101)
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.apps.Fop(Fop.java:79)。
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.apps.FopFactory.newFop(FopFactory.java:271)
02-22 14:16:23.641:WARN / System.err的(5590):在org.apache.fop.apps.FopFactory.newFop(FopFactory.java:248)
02-22 14:16:23.641:WARN / System.err的(5590):在com.zebdor.signal88.ProposalCalculator $ 3.onClick(ProposalCalculator.java:158)
02-22 14:16:23.641:WARN / System.err的(5590):在android.view.View.performClick(View.java:2501)
02-22 14:16:23.641:WARN / System.err的(5590):在android.view.View $ PerformClick.run(View.java:9107)
02-22 14:16:23.641:WARN / System.err的(5590):在android.os.Handler.handleCallback(Handler.java:587)
02-22 14:16:23.641:WARN / System.err的(5590):在android.os.Handler.dispatchMessage(Handler.java:92)
02-22 14:16:23.641:WARN / System.err的(5590):在android.os.Looper.loop(Looper.java:123)
02-22 14:16:23.641:WARN / System.err的(5590):在android.app.ActivityThread.main(ActivityThread.java:3812)
02-22 14:16:23.641:WARN / System.err的(5590):在java.lang.reflect.Method.invokeNative(本机方法)
02-22 14:16:23.641:WARN / System.err的(5590):在java.lang.reflect.Method.invoke(Method.java:507)
02-22 14:16:23.641:WARN / System.err的(5590):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)
02-22 14:16:23.641:WARN / System.err的(5590):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-22 14:16:23.641:WARN / System.err的(5590):在dalvik.system.NativeStart.main(本机方法)
随着Android的,你不能只是采取的.jar从一个Java库,并用它在Android应用程序。 Android使用的Dalvik JVM(http://en.wikipedia.org/wiki/Dalvik_(software)),这是与通过Java SE API的完整的API不是100%兼容,而是仅支持API的子集。出于这个原因,许多Java库,你可能会使用到,比如FOP,不兼容Android的原样,并需要专业化以前那样库将正常运行在Android设备上。祝你好运。
I recently compiled an Android app using FOP as I want to convert some XML into a PDF file. However I don't think the FOP JAR files are mean't to work on Android. Are there any versions of FOP available for Android? Or any other XML to PDF converter I could use within my app instead of connecting to a FOP enabled server on the Internet?
I've tried including fop.jar and the xmlgraphics.jar but even with those added to my project, the call to FopFactory.newInstance()
fails.
Here's my code snippet for the button click that calls FOP:
// Add button listener
btnCreatePDF.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
FopFactory fopFactory = FopFactory.newInstance();
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("/sdcard/test.pdf")));
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(new File("/sdcard/test.fo"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
out.close();
}
});
The compiler is also giving a me a bunch of Dxwarning: Ignoring InnerClasses attribute...
errors. Here's the error when I click the button to create the PDF:
02-22 14:16:23.641: WARN/System.err(5590): java.lang.UnsupportedOperationException: Don't know how to handle "application/pdf" as an output format. Neither an FOEventHandler, nor a Renderer could be found for this output format.
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:361)
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.fo.FOTreeBuilder.(FOTreeBuilder.java:105)
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.apps.Fop.createDefaultHandler(Fop.java:101)
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.apps.Fop.(Fop.java:79)
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.apps.FopFactory.newFop(FopFactory.java:271)
02-22 14:16:23.641: WARN/System.err(5590): at org.apache.fop.apps.FopFactory.newFop(FopFactory.java:248)
02-22 14:16:23.641: WARN/System.err(5590): at com.zebdor.signal88.ProposalCalculator$3.onClick(ProposalCalculator.java:158)
02-22 14:16:23.641: WARN/System.err(5590): at android.view.View.performClick(View.java:2501)
02-22 14:16:23.641: WARN/System.err(5590): at android.view.View$PerformClick.run(View.java:9107)
02-22 14:16:23.641: WARN/System.err(5590): at android.os.Handler.handleCallback(Handler.java:587)
02-22 14:16:23.641: WARN/System.err(5590): at android.os.Handler.dispatchMessage(Handler.java:92)
02-22 14:16:23.641: WARN/System.err(5590): at android.os.Looper.loop(Looper.java:123)
02-22 14:16:23.641: WARN/System.err(5590): at android.app.ActivityThread.main(ActivityThread.java:3812)
02-22 14:16:23.641: WARN/System.err(5590): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 14:16:23.641: WARN/System.err(5590): at java.lang.reflect.Method.invoke(Method.java:507)
02-22 14:16:23.641: WARN/System.err(5590): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-22 14:16:23.641: WARN/System.err(5590): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-22 14:16:23.641: WARN/System.err(5590): at dalvik.system.NativeStart.main(Native Method)
With Android, you can't just take a .jar from a Java library and use it in an Android application. Android uses the Dalvik JVM (http://en.wikipedia.org/wiki/Dalvik_(software)) which is not 100% compatible with the full API from the Java SE API, and instead only supports a subset of the API. For this reason, many of the Java libraries you might be use to, like FOP, are not Android compatible as-is and require specialization before such libraries will function properly on an Android device. Good luck.
这篇关于FOP为Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!