使用itextsharp生成pdf时出现OutOfMemory异常 [英] OutOfMemory Exception while generating pdf using itextsharp

查看:212
本文介绍了使用itextsharp生成pdf时出现OutOfMemory异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用itextsharp生成pdf。对于高达100的页面,它正在下载。但是对于超过100的页面,它给了我outOfMemory Exception'内存不足以继续执行程序。'请为我提供解决问题的方法:



I我在PdfPTable中插入我的数据。这是我的简短代码:



pdfPage page = new pdfPage();



string attachment = attachment; filename =+ PDF_Name +。pdf;

Response.ClearContent();

Response.AddHeader(content-disposition,附件);

Response.ContentType =application / pdf;



iTextSharp.text.Document doc = new iTextSharp.text.Document();

PdfWriter writer = PdfWriter.GetInstance(doc,Response.OutputStream);

doc.Open();

Hi All,

I'm generating pdf using itextsharp. for pages upto 100, it is downloading. But for pages more than 100, It is giving me outOfMemory Exception 'Insufficient memory to continue the execution of the program.' Please provide me solution for the problem:

I'm inserting my data in PdfPTable. Here is my code in short:

pdfPage page = new pdfPage();

string attachment = "attachment; filename=" + PDF_Name + ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";

iTextSharp.text.Document doc = new iTextSharp.text.Document();
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();

for (int i = 0; i < dt.Rows.Count; i++)
        {



PdfPTable tablePage1 = new PdfPTable (2);












PdfPTable tablePage1 = new PdfPTable(2);
.
.
.
.
.

doc.Add(tablePage1);
           if (i != (dt.Rows.Count - 1))
               doc.NewPage();
           writer.PageEvent = page;



}


}

doc.Close();
       Response.Write(doc);











pdfPage是我的应用页眉和页脚到pdf的每一页的类。



请给我解决方案。



提前使用Thanx,






pdfPage is my class for applying header and footer to every page of pdf.

please provide me solution.

Thanx in advance,

推荐答案

您需要使用内存流媒体,以便所有信息都不会存储到内存中作为一个pdf文件,因为它增长。



这是一个你可以看看的例子:

使用iTextSharp创建PDF文档 [ + ]
You need to use a memory streamer so that all of the info does not get stored into memory as a pdf file as it grows.

Here are an example you can go look at:
Creating PDF documents with iTextSharp[+]


这篇关于使用itextsharp生成pdf时出现OutOfMemory异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆