Shortcuts

How to generate large pdf's?

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#

Re: How to generate large pdf's?

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?

If the answer I provided is useful or informative please check the "answer" button.

Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.

Re: How to generate large pdf's?

JeffreyABecker

Re: How to generate large pdf's?

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...!!

Re: How to generate large pdf's?

JeffreyABecker

hans_v

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......

Re: How to generate large pdf's?

hans_v

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?

If the answer I provided is useful or informative please check the "answer" button.

Warning: Code is often uncompiled and possibly started life written on the back of a napkin. Beware typos.

Re: How to generate large pdf's?

JeffreyABecker

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!

JeffreyABecker

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?

Re: How to generate large pdf's?

hans_v

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.

Re: How to generate large pdf's?

kuujinbo

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.

kuujinbo

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.

Re: How to generate large pdf's?

hans_v

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 possiblesolution. 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.

Re: How to generate large pdf's?

kuujinbo

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.

Re: How to generate large pdf's?

hans_v

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.

Re: How to generate large pdf's?

SautinSoft

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?