iText的工作谷歌应用程序引擎(iText working Google App engine)

2019-09-22 23:23发布

我试图在与谷歌应用程序引擎的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与谷歌的AppEngine上的不兼容性。 但我不知道该怎么做。 有iText的,以谷歌应用程序引擎的任何特殊版本? 或者你知道任何线索,可以帮助我吗?

Answer 1:

是的,有的iText的GAE版本。 见http://lowagie.com/iPadSchools观看演示。 在GAE端口被iText的软件分发。 有没有链接到网上得到它。



Answer 2:

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


文章来源: iText working Google App engine