Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 10, 2010 7:31 AM
Hi all,
I am using rdlc reports in my appln. Am trying to generate a huge pdf file which almost consists of 1500 - 2000 pages.
I have used ReportViewer and am adding datasource (Generic collection) to report. But am getting system out of Memory exception as it is a huge file.
Can any one suggest me how to generate large pdf files in asp.net c#
All replies (26)
Tuesday, August 10, 2010 8:20 AM ✅Answered
ITextSharp seems to be popular:
http://sourceforge.net/projects/itextsharp/
Thursday, August 12, 2010 4:05 AM ✅Answered
...i would be happy if u suggest me any solution...!!
Create mutiple smaller pdf's...
Tuesday, August 10, 2010 8:45 AM
try again by setting request timeout and loading timeout on in SSRS Server.
Tuesday, August 10, 2010 9:10 AM
Try to sets max request length at web.config:
<system.web>
<httpRuntime maxRequestLength="2000000"/>
...
Tuesday, August 10, 2010 12:35 PM
Honestly: You Don't. For comparison the paperbacks of Atlas Shrugged and War and Peace are about 1200 and 1400 pages respectively. If your report is meant to be human readable and is that big is it really providing any value? If your report is meant to me machine readable why on earth are you producing pdfs?
Tuesday, August 10, 2010 12:47 PM
Honestly: You Don't.
Thursday, August 12, 2010 1:25 AM
Hi Becker,
Pdf which am trying to generate is human readable...am displaying transactions in pdf...if there are huge no.of transactions then my pdf is going to be very large...i would be happy if u suggest me any solution...!!
Thursday, August 12, 2010 1:34 AM
hi
use itextsharp.you can do your requirement easily and fast
http://sourceforge.net/projects/itextsharp/
http://www.devshed.com/c/a/Java/Creating-Simple-PDF-Files-With-iTextSharp/
http://kuujinbo.info/cs/itext.aspx
http://somewebguy.wordpress.com/2009/05/08/itextsharp-simplify-your-html-to-pdf-creation/
Thursday, August 12, 2010 4:05 AM
use itextsharp.you can do your requirement easily and fast
The problem is not HOW to generate pdf's, but how to generate LARGE pdf's!!!!
Thursday, August 12, 2010 4:14 AM
hans_v , you correct
Thursday, August 12, 2010 4:16 AM
hans_v, have you any idea
Thursday, August 12, 2010 4:25 AM
I already gave you one! I totaly agree that it makes no sence to create such large files!!!!
Thursday, August 12, 2010 7:34 AM
Create mutiple smaller pdf's...
or enforce a UI limit on how many transactions can be placed into a single report request.
Thursday, August 12, 2010 7:40 AM
Create mutiple smaller pdf's...
or enforce a UI limit on how many transactions can be placed into a single report request.
Or, if you insist of creating such large file, you can try to NOT create the file in memory but on the filesystem and try to append new pages. I'm not sure if it will work not do I want to try it myself......
Thursday, August 12, 2010 9:00 AM
Or, if you insist of creating such large file, you can try to NOT create the file in memory but on the filesystem and try to append new pages. I'm not sure if it will work not do I want to try it myself......
My experience with pdf libraries is that they dont generally support this. Even if you could: would the users pdf reader even be able to open it?
Thursday, August 12, 2010 9:21 AM
My experience with pdf libraries is that they dont generally support this
I've done this many times ? However, I'm not sure if you open an existing file on the filesystem to append a new page, if the whole pdf will be copied into memory, because if it does, then the problem remains the same!
Even if you could: would the users pdf reader even be able to open it?
I've found no indication that there's a limit to a pdf file size.
But then where back to the other problem you identified. Is somebody really interested in opening a large file like this with so many pages?
Saturday, August 14, 2010 8:41 PM
But then where back to the other problem you identified. Is somebody really interested in opening a large file like this with so many pages?
One example is a report containing billing transactions for many people that needs to be printed and snail-mailed.
Not sure what the OP needs or exactly what type of 'transactions' are involved and never have used the ReportViewer control or RDLC, but depending the type/purpose of report PDF generated, this is definitely possible using iTextSharp:
http://kuujinbo.info/cs/itext_template1.aspx
http://kuujinbo.info/cs/itext_template2.aspx
If you take a look at the second example there's a simple demo. Use something similar at work to generate PDF with between 1000-1300 pages. If your worried about memory/CPU overhead, the application runs on a pathetic VM host server (my laptop runs faster) without problem. The file size usually ends up being around 1-3MB. (that's not a typo)
However, this method will take a little effort to achieve. You'll need to invest some time in learning the API and may even have to, perish the thought, actually take a look into the source code.
The mailing list is also very helpful as long as you put some thought into asking a question.
Saturday, August 14, 2010 9:15 PM
but depending the type/purpose of report PDF generated, this is definitely possible using iTextSharp:
Off couse this can be done with iTextSharp (or any other pdf library). The problem is that it grows to big, using up all resources.
your worried about memory/CPU overhead, the application runs on a pathetic VM host server (my laptop runs faster) without problem. The file size usually ends up being around 1-3MB. (that's not a typo)
I've seen many pdf's with a couple of pages being larger. It all depands what you put in the file, and in this situation with large files, you're right that you need to keep the filesize as small as possible. In this case, the pdf is apparantly much larger than yours (pictures?), resulting in a memory problem. Perhaps optimizing the code to generate the file will solve the problem (but what if the number of pages grows, their can be a moment that the memory becomes an issue again!) When you increase the number of pages in your examples, at one moment you'll get this problem also.
Sunday, August 15, 2010 1:21 AM
I've seen many pdf's with a couple of pages being larger. It all depands what you put in the file, and in this situation with large files, you're right that you need to keep the filesize as small as possible. In this case, the pdf is apparantly much larger than yours (pictures?), resulting in a memory problem. Perhaps optimizing the code to generate the file will solve the problem (but what if the number of pages grows, their can be a moment that the memory becomes an issue again!) When you increase the number of pages in your examples, at one moment you'll get this problem also.
I don't disagree with any of what you're saying. That's why I was careful to say it's one possible solution. The OP didn't indicate if there are indeed images in the PDF, so it's hard to tell. And besides images there could be a number of other reasons for large file size even for a two or three page PDF; embedded fonts, not properly re-using a template (if a template is being used at all), etc.
The OP did say the PDF only contains 1500 - 2000 pages, so I didn't read anything further into the answer. As stated I use something similar to the examples (but a lot more complicated) at work that easily generates 1000-1300 page PDFs on a crippled server and it runs fine. It's common sense that you need to rethink the approach if, for example, you want to generate a PDF with let's say 10,000 pages instead.
Sunday, August 15, 2010 7:01 AM
It's common sense that you need to rethink the approach if, for example, you want to generate a PDF with let's say 10,000 pages instead.
And I think, like JeffreyABecker, that you need to rethink the approach if you generated a pdf of 1000 pages also!If I would get a report like the exmaple you gave, I want it in a digital format, because I will never ever read a pdf with just numbers that's over 10 pages long, let alone more than 1000 pages. In a digital format, I can do calculations, group things together etc, in pdf I can't.
Sunday, August 15, 2010 7:08 PM
And I think, like JeffreyABecker, that you need to rethink the approach if you generated a pdf of 1000 pages also!If I would get a report like the exmaple you gave, I want it in a digital format, because I will never ever read a pdf with just numbers that's over 10 pages long, let alone more than 1000 pages. In a digital format, I can do calculations, group things together etc, in pdf I can't.
No offense, but you're reading a lot more into OP's question and my potential answer to that question, i.e getting off topic. Only the OP knows exactly what's needed. The OP specifically asked for a way to generate a PDF file, NOT a digital format that "can do calculations, group things together etc" - that's what you want, not what the OP has asked for.
And I already said what I'M using the report for, to quote:
* One example is a report containing billing transactions for many people that needs to be printed and snail-mailed.*
In this case the report isn't meant to be read by the person generating the report, only by the customers that get a hard-copy via snail-mail.
Sunday, August 15, 2010 9:45 PM
There is another option you may wish to explore (in case you aren't confused enough).
The application on this site installs a printer driver: When you print to it, a PDF file is created. I've used it with many applications but never programmatically tried to print to it.
Monday, August 16, 2010 2:12 AM
Hi,
I see that many people recommend you to use ITextSharp, in my view this is right solutuion but:
1) Use ITextSharp to generate PDF small files, for example with 50 pages at once
2) Next merge that PDF files into one large single document
To merge PDF files you may use the PDF Metamorphosis .Net, it's commercial product and I'm owner of company who created this product.
But I don't offer you to purchase it, you may simply use the method MergePDF, it doesn't have any limits and in my view will help you to solve this task for free.
I've tried to merge PDF rereference 1.3 which contains 700 pages with another PDF, it takes ~ 8 sec.
This is C# sample:
SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
string [] pdfFiles = {@"D:\PDFReference13.pdf",@"D:\dest1.pdf"};
p.MergePDF(pdfFiles, @"d:\dest2.pdf");
Actually the best way is merge PDF in memory, you may also do this with method 'MergePDF'.
Let me know if you will have questions.
Max
Monday, August 16, 2010 3:32 AM
Actually the best way is merge PDF in memory, you may also do this with method 'MergePDF'.
But will this solve his problem? Because now the memory is the problem. When you merge 2 documents with the same data into 1 document in memory, the amount of memory need will be the same, or not? I think in this case, the merging of the smallerr documents into 1 should NOT be done in memory?
Monday, August 16, 2010 3:48 AM
Hi
u cant create direct from html or aspx. the easy way is bring all ur data in one server side control and then create pdf of it. i have used itextsharp dll for that code is as follow
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Quotation.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
tblall.RenderControl(hw);
//here is tblall as server side table
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
pdfDoc.AddHeader("this is header part ", "this is header content remeber spell");
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Thursday, August 19, 2010 6:16 AM
Hi,
You must refer a article http://www.adobe.com/designcenter/acrobat/articles/acr7lgpg.html at this link. It will help u.
Thanks