3

我正在尝试使用谷歌应用引擎在 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();
            }
    }
}

这是错误:

HTTP ERROR 500

Problem accessing /guestbook. Reason:

    com/itextpdf/text/DocumentException
Caused by:

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

我已经阅读了 java.awt 和 java.nio 与 google appengine 的不兼容性。但我不知道该怎么做。谷歌应用引擎是否有任何特殊版本的 itext?或者你知道任何可以帮助我的线索吗?

4

2 回答 2

1

Yes, there's a GAE version of iText. See http://lowagie.com/iPadSchools to watch a demo. The GAE port is distributed by iText Software. There's no link to get it online.

于 2012-09-25T10:01:12.920 回答
1
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
于 2012-12-06T19:47:44.077 回答