pdf生成代码在localhost上工作正常,但在服务器上不起作用

时间:2016-10-31 12:50:27

标签: c# asp.net pdf-generation itext

生成的pdf的文件大小是13mb在localhost上正常工作但在服务器上不能正常工作..

生成的文件包含超过650页..

我无法弄清楚,因为我是Itextsharp的新手,有什么问题需要帮助

生成文件时是否可以减小文件大小..

C#CodeBehind文件

    Document doc = new Document(PageSize.A4.Rotate());
    doc.SetMargins(-55f, -80f, 15f, 20f);
    MemoryStream ots = new MemoryStream();
    PdfWriter pdfWriter = PdfWriter.GetInstance(doc, Response.OutputStream);
    doc.Open();

    SqlConnection conmain1 = new SqlConnection(conne);
    conmain1.Open();
    SqlCommand cmdmain1 = new SqlCommand(queryforvoucher, conmain1);
    SqlDataReader drmain1;
    drmain1 = cmdmain1.ExecuteReader();

    while (drmain1.Read())
    {
        string classname = (drmain1["ClassName"].ToString());
        string section = (drmain1["SectionName"].ToString());
        string session = (drmain1["SessName"].ToString());
        string grnum = (drmain1["StDeGrNumber"].ToString());
        string fname = (drmain1["StDeFatherName"].ToString());
        string sname = (drmain1["StDeName"].ToString());
        string dis = (drmain1["StDeDiscount"].ToString());
        string mfees = (drmain1["StDeFees"].ToString());
        string id = (drmain1["VoIssueDate"].ToString());
        string dd = (drmain1["VoDueDate"].ToString());
        string pd = (drmain1["VoPeriod"].ToString());
        string vd = (drmain1["VoValidDate"].ToString());
        string sli = (drmain1["VoSlipId"].ToString());

        doc = BindindData(doc, classname, id, section, session, grnum, pd, fname, sname, dis, mfees, dd, vd, Convert.ToInt32(sli));
    }
    conmain1.Close();
    pdfWriter.CloseStream = false;
    doc.Close();
    Response.Buffer = true;
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=Voucher_"+p+".pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Write(doc);
    Response.End();  

网络配置

  <location path="vouchergeneration.aspx">
    <system.web>
      <httpRuntime executionTimeout="600" maxRequestLength="29296" />
    </system.web>
    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="209715200" />
        </requestFiltering>
      </security>
    </system.webServer>
  </location>

0 个答案:

没有答案