zkh152 / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Generating PDF from ODT in appengine #209

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I configured my java appengine application to use the ODF 2 PDF, like 
http://code.google.com/p/xdocreport/wiki/ODTReportingJavaMain and 
http://code.google.com/p/xdocreport/wiki/ODFDOMConverterPDFViaIText instructed.
2. I open an ODT file using OdfTextDocument document = 
OdfTextDocument.loadDocument(inputStream), changed some parameters using 
report.createContext() 
3. If I use report.process(context, ((HttpServletResponse) 
resp).getOutputStream()) the ODT is returned with the parameters changed as 
expected

What is the expected output? What do you see instead?
PdfOptions options = PdfOptions.create();
PdfConverter.getInstance().convert(document, out, options);

The browser receives an empty PDF, but one exception is thrown 
Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
com.google.apphosting.runtime.security.shared.stub.java.awt.Color
at 
org.odftoolkit.odfdom.converter.pdf.internal.ColorRegistry.createColor(ColorRegi
stry.java:47)
at 
fr.opensagres.xdocreport.itext.extension.color.AbstractColorRegistry.internalCre
ateColor(AbstractColorRegistry.java:53)
at 
fr.opensagres.xdocreport.itext.extension.color.AbstractColorRegistry.getColor(Ab
stractColorRegistry.java:41)

What version of the product are you using? On what operating system?
1.0.0 with appengine-api-1.0-sdk-1.7.2 and itext-2.1.7-gae.jar (attached)

Please provide any additional information below.
Is it possible to create a branch to be used in appengine, using the same 
approach like itext? 
http://blog.rubypdf.com/2009/12/17/how-to-run-itext-on-google-app-engine/

BR

Original issue reported on code.google.com by rco...@ciandt.com on 19 Dec 2012 at 11:21

Attachments:

GoogleCodeExporter commented 9 years ago
If I use the original itext-2.1.7, the error is different:
Caused by: java.lang.NoClassDefFoundError: java.awt.Color is a restricted 
class. Please see the Google App Engine developer's guide for more details.
at java.awt.Color.<clinit>(Color.java)
at 
org.odftoolkit.odfdom.converter.pdf.internal.ColorRegistry.createColor(ColorRegi
stry.java:47)

Original comment by rco...@ciandt.com on 19 Dec 2012 at 11:24

GoogleCodeExporter commented 9 years ago
Hi,

If I understand the gae patch, it uses a custom java.axt.Color with 
com.lowagie.text.awt.Color. The big problem with that is that itext-2.1.7.jar 
will not work if we create our own Color class.

I don't know how we could manage both  itext-2.1.7-gae.jar and  itext-2.1.7.jar 
(perhaps with Java reflection).

Just for your information, you can use report.convert to generate report and 
convert it (it uses internally PdfConverter)

Regards Angelo

Original comment by angelo.z...@gmail.com on 19 Dec 2012 at 1:36

GoogleCodeExporter commented 9 years ago
Hi Angelo,

I'm using only one itext.jar per time. But actually I only have 
itext-2.1.7-gae.jar in WEB-INF/lib.

I tried report.convert but the same error occurs.

Options options = 
Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM);
report.convert(context, options, out);

I guess the error is when ColorRegistry is loaded. It imports java.awt.Color 
and uses the decode method in that line.  

Regards

Original comment by rco...@ciandt.com on 19 Dec 2012 at 2:05

GoogleCodeExporter commented 9 years ago
I got the com.lowagie.text.awt files from the gae patch and changed to the 
desired com.google.apphosting.runtime.security.shared.stub.java.awt in my app. 

Looks like ColorRegistry.java:47 tried to call the static method, perhaps the 
"alternative" Color class was loaded correctly.

Original comment by rco...@ciandt.com on 19 Dec 2012 at 2:09

Attachments:

GoogleCodeExporter commented 9 years ago
> I tried report.convert but the same error occurs.

Yes it's normal, it uses PdfConverter. As you said, problem is to use 
java.awt.Color, but I think it's very hard to manage both java.awt.Color and 
com.lowagie.text.awt.Color

I would like to avoid 2 version of the converter, just to change package name 
"java.awt" to "com.lowagie.text.awt" in our classes. 

I think reflection could be a solution, but I don't know if it will be easy to 
do that?

Regards Angelo

Original comment by angelo.z...@gmail.com on 19 Dec 2012 at 2:13

GoogleCodeExporter commented 9 years ago
It seems that ODFDOM has some dependencies to java.awt.Color in some classes, 
but perhaps we don't use it for our converter. Could you test if you can load 
ODT with OdfTextDocument document = OdfTextDocument.loadDocument(inputStream) 
and save it to your http response to check you have none problem, please.

If you have problem with java.awt.Color, we cannot do nothing. Before studying 
how to replace java.awt.Color with our custom Color clases, I would know if 
ODFDOM can be used with GAE.

Thankr's for your help.

Regards Angelo

Original comment by angelo.z...@gmail.com on 21 Dec 2012 at 10:33

GoogleCodeExporter commented 9 years ago
Hi Angelo,

Yes, I can open an ODT file using OdfTextDocument document = 
OdfTextDocument.loadDocument(inputStream), change some parameters using 
report.createContext(), and if I use report.process(context, 
((HttpServletResponse) resp).getOutputStream()) the ODT is downloaded with the 
parameters changed as expected.

Regards

Original comment by rco...@ciandt.com on 21 Dec 2012 at 10:46

GoogleCodeExporter commented 9 years ago
Have you tried google drive to do your conversion ? Remember you need a license 
to use iText, even when your only offering a service, because itext is licensed 
with AGPL (http://en.wikipedia.org/wiki/Affero_General_Public_License)

Original comment by k...@koma.be on 28 Dec 2012 at 7:02

GoogleCodeExporter commented 9 years ago
Our PDF converter uses iText 2.1.7 which is licensed with MPL.

Original comment by angelo.z...@gmail.com on 29 Dec 2012 at 12:09

GoogleCodeExporter commented 9 years ago
Hi,

I have created several project with *-gae extension (not commited for the 
moment) which (I hope) supports GAE
for that I have copy/paste our Java code converter and replace java.awt.Color 
with com.lowagie.text.awt.Color.

I had to modify itext-gae source code to avoid the StackOverFlow 
(StackOverflowError at com.lowagie.text.pdf.RandomAccessFileOrArray.seek) 
problem described in the 
http://code.google.com/p/xdocreport/issues/detail?id=197

I have attached 3 JARs, could you test it please : 

 * use itext-gae-1.0.1-SNAPSHOT.jar instead of itext-gae.jar
 * use org.odftoolkit.odfdom.converter.pdf-gae-1.0.1-SNAPSHOT.jar instead of org.odftoolkit.odfdom.converter.pdf.jar
 * use fr.opensagres.xdocreport.itext.extension-gae-1.0.1-SNAPSHOT.jar instead of org.odftoolkit.odfdom.converter.pdf.jar

It works for me with simple Java Main but I don't know with GAE context (I'm 
afraid that it doesn't work, because I have replaced RandomAccessFileOrArray 
from itext-gae with RandomAccessFileOrArray from itext).

Many thank's for your help.

Regards Angelo

Original comment by angelo.z...@gmail.com on 2 Jan 2013 at 10:24

Attachments:

GoogleCodeExporter commented 9 years ago
Hi, 

I have commited my work on Git (see projects nammed with *-gae at 
http://code.google.com/p/xdocreport/source/browse/thirdparties-extension/)

It will be available soon on maven central with SNAPSHOT.

I'm waiting for your test on GAE with the attached JARs.

Regards Angelo

Original comment by angelo.z...@gmail.com on 3 Jan 2013 at 10:46

GoogleCodeExporter commented 9 years ago
Pascal has developed a demo on Google App Engine with XDocReport converters and 
it works great. So you must use the new *-gae project converters. Please read 
http://code.google.com/p/xdocreport/wiki/XDocReportGAE for more information.

Original comment by angelo.z...@gmail.com on 7 Jan 2013 at 1:09

GoogleCodeExporter commented 9 years ago
XDocReport 1.0.1 supports now Google App Engine with new *-gae projects 
converters.

Original comment by angelo.z...@gmail.com on 7 Jan 2013 at 1:10

GoogleCodeExporter commented 9 years ago
Great news Angelo ! I'll try it and let you know.

BR

Original comment by rco...@ciandt.com on 8 Jan 2013 at 10:21