We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting HTML to PDF by saving to MemoryStream

I'm trying to convert an Html- into a PDF document, but no matter which approach I tried, I'm getting one of these errors:
You are in direct-to-file mode,please use Close() instead of Save(). (Pdf pdf = new Pdf(), then BindToHtml and save to MemoryStream)
Input stream for html data must be FileStream (Document pdfDocument = new Document(memoryStream, htmlOptions))
The HTML is converted into a byte array, 

written into a MemoryStream,
should now be converted to PDF by creating Document/Pdf saving into a new MemoryStream
and finally returned as a byte array to be stored in SharePoint.

I’m using and it is not possibly to save the PDF to a harddrive.
The tricky part seems to be that I get a byte array and want to save the PDF to a MemoryStream…
I appreciate any help.

Hi Bea,

Thanks for your inquiry. I am afraid you are using a quite older version. I have tested the scenario with latest version Aspose.Pdf for .NET 10.6.0 and unable to notice the issue. Please check following code snippet for the purpose.

We will recommend you to use latest version of Aspose.Pdf for .NET as it includes lot of new feature and fixes from older versions. Moreover, we can not provide hotfix for old version as we maintain a single code base of our API, so any new enhancements/features and fixes is included in latest release only.

string testStr = "

Test for Inline style and CSS support

This text has yellow background color and is center aligned.

This text has no background color and is center aligned.


byte[] inputBytes = Encoding.UTF8.GetBytes(testStr);

MemoryStream stream = new MemoryStream(inputBytes);

// load HTML file

Document doc = new Document(stream, new HtmlLoadOptions());

// save output PDF into file/stream

doc.Save(myDir + "HTMLtoPDFDOM.pdf");

Please feel free to contact us for any further assistance.

Best Regards,


I am trying the same in Aspose

I have the same scenario to create PDF file. Below sample code giving me an exception " Atmost 4 arguments can be set". Highlighted statement is throwing the exception

Below is my sample code

byte[] inputstrngBytes = Encoding.UTF8.GetBytes(strBody);
MemoryStream Memstream = new MemoryStream(inputstrngBytes);
Document document = new Document(Memstream,new HtmlLoadOptions());

Hi Ravindra,

Thanks for your interest in Aspose.

You are getting the issue due to evaluation limitation. Aspose.Pdf
evaluation version has two limitations, evaluation watermark and at most
four elements of any collection can be viewed. Please make request a 30 days temporary license and apply it, it will resolve the issue.

Please feel free to contact us for any further assistance.

Best Regards,