簡體   English   中英

iText正在使用Google App引擎

[英]iText working Google App engine

我正在嘗試使用谷歌應用引擎在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到谷歌應用程序引擎? 或者你知道任何可以幫助我的線索嗎?

是的,有一個GAE版本的iText。 請訪問http://lowagie.com/iPadSchools觀看演示。 GAE端口由iText Software分發。 沒有鏈接可以上網。

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