问题描述
我有一个appengine java项目,在某些时候包含了pdf创建。 PDF文件有特殊的字体,我试图包括:
BaseFont bf = BaseFont.createFont(resources / AlexBrush-Regular.ttf,,BaseFont.EMBEDDED);
代码在本地完美运行,但部署时我得到NoClassDefFoundError(下面的堆栈跟踪)。在appengine上有没有人成功地向iText添加自定义字体?我正在使用iTextg-5.4.4
java.lang.NoClassDefFoundError:java.nio.MappedByteBuffer是一个受限制的类。有关更多详细信息,请参阅Google App Engine开发人员指南。
at com.goxt.apphosting.runtime.security.shared.stub.java.nio.channels.FileChannel_.map(FileChannel.java)
at com.itextpdf.text.io.MappedChannelRandomAccessSource.open( MappedChannelRandomAccessSource.java:104)LT
。在com.itextpdf.text.io.FileChannelRandomAccessSource&;初始化>(FileChannelRandomAccessSource.java:71)
。在com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory的.java:212)
。在com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory.java:193)$ b $ LT b。在com.itextpdf.text.pdf.RandomAccessFileOrArray&; INIT>(RandomAccessFileOrArray。 java:147)
at com.itextpdf.text.pdf.TrueTypeFont.process(TrueTypeFont.java:625)
at com.itextpdf.text.pdf.TrueTypeFont。< init>(TrueTypeFont.java :369)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:705)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:621)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.ja VA:456)
。在ccfb.server.servlets.PaypalCheckoutServlet.doPost(PaypalCheckoutServlet.java:156)
。在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty .servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166)
在com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
在org.mortbay.jetty .servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty .servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)
在com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
在org.mortbay.jetty .servlet.ServletHandler $ CachedChain.doF ILTER(ServletHandler.java:1157)
处org.mortbay.jetty.servlet.ServletHandler $ CachedChain com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
。 doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler。
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay .jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConn ection $ RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection。通过com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)处理(HttpConnection.java:404)
;在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable处处理
。运行(JavaRuntime.java:446)
,位于com.google.tracing.TraceContext $ TraceContextRunnable.runInContext(TraceContext.java:435)
,位于com.google.tracing.TraceContext $ TraceContextRunnable $ 1.run(TraceContext .java:442)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
at com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
at com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
at com.google.tracing.TraceContext $ TraceCon textRunnable.run(TraceContext.java:439)
at com.google.apphosting.runtime.ThreadGroupPool $ PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread。 java:724)
GAE上的所有文件系统相关操作。正如您可以在上阅读的那样,iTextG中的某些方法只能用于Android,而不能用于GAE。我引用:
$ b
这意味着您需要使用 byte []
,如果你想创建一个 BaseFont
实例。您不能使用采用字体程序路径的 createFont()
方法。相反,您需要使用 createFont()
方法。
I have an appengine java project that includes pdf creation at some point. The pdf document has special font that I'm trying to include with:BaseFont bf = BaseFont.createFont("resources/AlexBrush-Regular.ttf", "", BaseFont.EMBEDDED);
Code runs perfect locally but when deployed I get the NoClassDefFoundError (stack trace below). Did any one succeeded in adding custom font to iText on appengine? I'm using iTextg-5.4.4
java.lang.NoClassDefFoundError: java.nio.MappedByteBuffer is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.apphosting.runtime.security.shared.stub.java.nio.channels.FileChannel_.map(FileChannel.java)
at com.itextpdf.text.io.MappedChannelRandomAccessSource.open(MappedChannelRandomAccessSource.java:104)
at com.itextpdf.text.io.FileChannelRandomAccessSource.<init>(FileChannelRandomAccessSource.java:71)
at com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory.java:212)
at com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory.java:193)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:147)
at com.itextpdf.text.pdf.TrueTypeFont.process(TrueTypeFont.java:625)
at com.itextpdf.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:369)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:705)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:621)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:456)
at ccfb.server.servlets.PaypalCheckoutServlet.doPost(PaypalCheckoutServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:724)
As you know, you should avoid all file system related operations on GAE. As you can read on the iTextG page, some methods in iTextG are to be used only on Android, not on GAE. I quote:
This means that you need to use a byte[]
if you want to create a BaseFont
instance. You can't use the createFont()
method that takes a path to a font program. Instead you need to use the createFont()
method that accepts the bytes of the font program.
这篇关于在AppEngine的iText中添加新字体时出现NoClassDefFoundError错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!