Aspose.Pdf.Kit .Save() to MemoryStream Problem

Good morning,

I am evaluating Pdf.Kit and am having an issue with saving to a MemoryStream to pass as a browser attachment download. I have tried every example in every post in this Forum and cannot get it to work. I am using Pdf.Kit assembly version 1.4.2.0 and .NET runtime 1.1.4322.

If I open the file using syntax like Form form = new Form(@"e:\test\froi.pdf", @"e:\test\output.pdf") then read it in to a MemoryStream via a FileStream from the saved location, it works. This is the code I am using to save to a MemoryStream.

MemoryStream ms = new MemoryStream();
Form form = new Form(@"e:\test\froi.pdf", ms);

form.FillField("txtEmployerName", Employer.Name);
form.FillField("txtEmployerName", Employer.Name);
form.FillField("txtEmployerAddress", Employer.Address);
form.FillField("txtEmployerCity", Employer.City);
form.FillField("txtEmployerState", Employer.State);
form.FillField("txtEmployerZip", Employer.Zip);
form.FillField("txtEmployerPhone", Employer.Phone);
form.FillField("txtEmployerFax", Employer.Fax);
form.FillField("txtPolicyNo", Employer.PolicyNo);

// More code to fill the form.

form.Save();

byte[] byteArray = ms.ToArray();

ms.Close();

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "inline; attachment; filename=" + fileName);

HttpContext.Current.Response.AddHeader("Content-Length", byteArray.Length.ToString());

HttpContext.Current.Response.BinaryWrite(byteArray);
HttpContext.Current.Response.End();

If I try it this way I get the error from Adobe that it is "not a supported type or corrupted." I also get an ms.Length value of zero.

Any ideas?

George S
Boise, Idaho

Dear George,

Thank you for considering Aspose.

Please refer to Stream error .