简体   繁体   English

iText正在使用Google App引擎

[英]iText working Google App engine

I'm trying create pdf in java with google app engine but it doesn't work yet: 我正在尝试使用谷歌应用引擎在java中创建pdf,但它还没有工作:

@SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("application/pdf");
            try {
                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
                document.open();
                document.add(new Paragraph("Hello World"));
                document.close();
            } catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}

This is the error: 这是错误:

HTTP ERROR 500

Problem accessing /guestbook. Reason:

    com/itextpdf/text/DocumentException
Caused by:

java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException

I have read the incompatibility with java.awt and java.nio with google appengine. 我已经阅读了与java.awt和java.nio与google appengine的不兼容性。 But I don't know how to do it. 但我不知道该怎么做。 Is there any special version of itext to google app engine? 是否有特殊版本的itext到谷歌应用程序引擎? Or do you know any clue that can help me? 或者你知道任何可以帮助我的线索吗?

Yes, there's a GAE version of iText. 是的,有一个GAE版本的iText。 See http://lowagie.com/iPadSchools to watch a demo. 请访问http://lowagie.com/iPadSchools观看演示。 The GAE port is distributed by iText Software. GAE端口由iText Software分发。 There's no link to get it online. 没有链接可以上网。

package mx.gob.campeche.sit.web.reportes;

import java.io.IOException;
import java.io.OutputStream;

import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import mx.gob.campeche.sit.doc.recibo_oficial.ReciboOficial;
@WebServlet("/reciboOficial")
public class ReporteReciboOficialServlet extends HttpServlet {

    @Inject
    ReciboOficial reciboOficial;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpServletRequestWrapper srw = new HttpServletRequestWrapper(request);
        String folio = "";

         if (request.getParameterMap().containsKey("folio")) {
                folio = request.getParameter("folio");
                System.out.println("contenido" + folio);
            }else
         if (request.getParameterMap().containsKey("numero")) {
                folio = request.getParameter("numero");
                System.out.println("contenido" + folio);
            }else{
                throw new ServletException("No ingreso parametro");
            }


        byte[] pdfData = reciboOficial.crearReciboOFicialCajas(folio,  srw.getRealPath(""));

        response.setContentType("application/pdf"); 
        response.reset();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition",  "inline; filename=\"" +"samplePDF2.pdf" +"\"");

        OutputStream output = response.getOutputStream();
        output.write(pdfData);
        output.close();

    }
this is small example, this help

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM