Forum Bugs

Stream too long error

sstanelle
Hi,

I don't know if this is a bug, if I am not using the C# API correctly, or if I need to configure Prince differently. Maybe it's not even a Prince error. But I am trying to create a very large PDF from an input stream and receiving a "System.IO.IOException: Stream was too long" error from the Prince engine.Based on other PDFs that I generate and my knowledge of the data set, I would expect the final output to be several hundred megabytes in size. Just wondering if Prince supports the generation of such a large PDF or if there is a configuration setting to allow large streams of input. Or perhaps a different way to do it? Maybe generate several smaller PDFs and merge?

Thanks,
Scott Stanelle
mikeday
Can you try creating the PDF from the command-line first to check the final size? It's possible that the final PDF could be over 2GB in size. Which convert method are you calling and how are you saving the result?
sstanelle
Hi Mike,

Thanks for your reply! I will try generating it from the command line in the morning. I'm sure though that the final size will be larger than 2GB. So is there a limit then? I am using the Prince.ConvertString(string xmlInput, Stream pdfOutput) method. I am converting the pdfOutput stream to a byte array and saving it to a file.

Regards,
Scott
mikeday
Could you specify an output filename instead and let Prince save the file itself? Using the Convert(string inputPath, string outputPath) method.
sstanelle
Hi Mike,

A couple updates:

1. I tried creating the PDF from the command line. It worked, and the final size was 3.68GB. So is the size limit in the C# wrapper?

2. I tried using the Convert(string inputPath, string outputPath) method to save the file. However, I received an error, "System.ApplicationException: The filename or extension is too long". My filename is "C:\temp\out.pdf". Am I supposed to only specify a filename, "out.pdf", that will then be created in the same directory?

Regards,
Scott

Edited by sstanelle

mikeday
There is a size limit in the MemoryStream class, you could avoid using this by passing the file output stream directly to the Convert() method instead of buffering it in a byte array first.

I'm not sure where the filename error message is coming from, that seems strange!
sstanelle
Hi Mike,

So the way I'm specifying the file name path seems okay to you? I should specify the full path name?

Regards,
Scott
sstanelle
Hi Mike,

I see my mistake now using the Prince.Convert() method. Both arguments to the method are expected to be file names: the first containing the html input and the second specifying where the pdf output will be written. I was passing the html input string as the first argument rather than a file name containing the html input string. Now I am able to create PDFs > 2GB in size.

In any case, there is no issue with Prince. It was all due to my misuse/misunderstanding that objects in .Net CLR 4.0 are limited to 2GB in size. To put a positive spin on it, I feel like I have learned "my something new" for today. :) Appreciate all your help! Prince support has always been great - very responsive and helpful!

Regards,
Scott
mikeday
Oh I see now, that certainly explains why it thought the the filename was too long! :D