【问题标题】:iText working Google App engineiText 工作 Google App 引擎
【发布时间】:2012-09-25 09:56:34
【问题描述】:

我正在尝试使用谷歌应用引擎在 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?或者你知道任何可以帮助我的线索吗?

【问题讨论】:

    标签: java google-app-engine itext


    【解决方案1】:

    是的,有一个 GAE 版本的 iText。请参阅http://lowagie.com/iPadSchools 观看演示。 GAE 端口由 iText Software 分发。没有链接可以上网。

    【讨论】:

    • 表示只能通过在itextpdf.com上填写销售表格来索取。
    • 您好!我填写了销售表格,他们说我可以在这里进行测试下载:itextpdf.com/download.php 一个普通版本,因为我不能在没有证明 iText 有正确的 GAE 解决方案的情况下购买许可证。我可以工作吗?
    • 您是否要求提供 GAE 试用版?
    • 早上好 Bruno,我尝试使用特定库运行应用程序,但我遇到了同样的异常。我需要配置其他东西吗?我将库添加到项目中,仅此而已。你知道我为什么会有这个异常吗?
    • 它对我们有用。请参阅itextpdf.com/summit.php#talk2 您必须将 iText 集成到您的 APK 中,就像集成任何其他库一样。将 jar 添加到您的项目后,您的 APK 应该更大。有关不同产品的比较,请参阅stefan.fenz.at/creating-pdfs-on-android-an-evaluation。 iText 的应用程序文件大小最大,但比其他产品快得多。
    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 2018-04-04
      • 2016-11-22
      • 1970-01-01
      相关资源
      最近更新 更多