We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ASP.NET Core - Sending a generated PDF directly to browser

Thread ID:





125221 Jul 29,2016 03:28 PM UTC Aug 1,2016 11:42 AM UTC ASP.NET Web Forms 2
Tags: PDF
Asked On July 29, 2016 03:28 PM UTC


How can I send a generated PDF directly to the browser in ASP.NET Core 1.0 ?


Andrew Nambudripad
Replied On July 30, 2016 11:34 AM UTC

Your question isn't clear (e.g. what platform you're deploying to is a big factor) - but you've got two basic ways of doing this. 

1) Just use the standard return a FileResult object through your controller action (if it's a 'one and done' dynamically generated report, e.g.)
2) if you need to retain a local copy (audit reasons, or company policies, etc), I'd generate the PDF, persist the stream to disk, then either a) use IApplicationBuilder.UseStaticFiles() and a FileProvider, or b) place the item statically in front of the application server (e.g. if you're using S3, Azure Blob Storage, or Nginx to host your static files, serve the data from there --- no need to bog down your app servers)

Andrew Nambudripad
Amplete Software

Chinnu Muniyappan [Syncfusion]
Replied On August 1, 2016 11:42 AM UTC

Hi Clovis, 

Thank you for contacting Syncfusion support. 

We have created as simple sample for generating PDF files and downloading via browser in Asp.net Core for your reference, please refer the below code snippet and sample for more details. 
1.       Save the PDF to the local disk. 
            //Save the PDF file in local disk.            
            string path = hostingEnvironment.ContentRootPath; 
            document.Save(path + "/output.pdf"); 

2.       Download the PDF: 
//Saving the PDF to the MemoryStream 
MemoryStream ms = new MemoryStream(); 
   //If the position is not set to '0' then the PDF will be empty. 
   ms.Position = 0; 
   //Download the PDF document in the browser. 
   FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); 
   fileStreamResult.FileDownloadName = "Sample.pdf"; 
return fileStreamResult; 

Sample link: 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon