Problem saving a pdf edited in C# using "save as"

I am working with a pdf in asp.net and filling in its form fields with C# code. After this is done, I would like the user to be able to download the finished document. I know I can use the Aspose save method, but I would like to have a Save As prompt (like with html headers, where the user chooses where the file is downloaded to).

string filename = “sample.pdf”;
Response.ContentType = “application/pdf”;
Response.AppendHeader(“Content-Disposition”, “Attachment; Filename="” + filename + “"”);
Response.Flush();
Response.Write(thePdf); //“thePdf” is the pdf file that was edited

Whenever I try to do this, I end up with a completely empty pdf file that cannot be opened. Any help on this matter would be great.

@wahehsoe

Thank you for contacting support.

You can save the PDF document to MemoryStream object after generating it, and then pass bytes from that MemoryStream to Response object, as explained in Sending PDF to Browser for Download. Also, ensure using Aspose.PDF for .NET 18.7 in your environment.

In case the problem persists, kindly create a narrowed down sample application reproducing this issue so that we may try to reproduce and investigate it further.

@Farhan.Raza

That works perfectly! It’s exactly what I was looking for. Thank you for the assistance. Will return here for any future issues (hopefully none).

Thanks and regards,

1 Like

@wahehsoe

Thanks for your kind feedback.

It is good to know that your issue has been resolved. Please keep using our API and in event of any further query, please feel free to let us know.