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

Free Support Forum - aspose.com

How do I return a PDF Document from a web api controller?

Instead of saving the PDF locally after created, I would like to: 1. Perform a mail merge, 2. Convert to PDF, then 3. Return the PDF or base64 string to the MVC View via web api controller. Do you have a recommended way for doing this? Thanks.


Thanks for contacting support.

Can you please share some details regarding the input file format, so that we can reply accordingly.

PS, If you intent to use MS Word files, then you may try using Aspose.Words to perform mail merge and conversion to PDF format. Finally you can save the output in Stream object and pass it to API controller capable of displaying the PDF file as Aspose.Words do not support the feature to display the PDF file.

We start with an MS Word file, open it, get data from SQL, perform mail merge. Then we want to convert to PDF and return it FROM a web api controller back to the client. We have a way to view the pdf on the client, I just need to know how you “save” as a “FileResult” from the web api controller to send it back to the client. In your sample code, the only samples I see are saving a pdf locally, not back to a stream or FileResult or ???.



Thanks for your inquiry. Please note Aspose.Words supports to save documents to file and stream. Please check following documentation link to save document to stream. Hopefully it will help you to accomplish the task.

Saving document to Stream