Articles in this section
Category / Section

How can I open the generated PDF document directly into the browser window instead of displaying the Open or Save dialog in the browser

7 mins read

Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can create a PDF document and open it directly in the browser window.

Steps to open the generated PDF document directly in the browser window:

  1. Create a new ASP.NET MVC application project.

ASP.NET MVC application template

  1. Install the Syncfusion.Pdf.AspNet.MVC NuGet package as a reference to your .NET Framework application from NuGet.org.

 

NuGet reference

  1. A default controller with a name HomeController.cs gets added on the created ASP.NET MVC project. Include the following namespaces in that HomeController.cs.

C#

using Syncfusion.Pdf;
using System.Drawing;
using Syncfusion.Pdf.Graphics;

 

VB.NET

Imports Syncfusion.Pdf
Imports System.Drawing
Imports Syncfusion.Pdf.Graphics

 

  1. Add a new action method named CreateDocument in the HomeController.cs and include the following code snippet to create a PDF file and open it in a browser.

C#

// Create an instance of PdfDocument.
using (PdfDocument document = new PdfDocument())
{
    // Add a page to the document
    PdfPage page = document.Pages.Add();
 
    // Create the PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
 
    // Set the standard font
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
 
    // Draw the text
    graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
 
    // Open the document in the browser after saving it
    document.Save("Output.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open);
}

 

VB.NET

'Create an instance of PDF document 
Using document As PdfDocument = New PdfDocument()
 
    'Add a page to the document 
    Dim page As PdfPage = document.Pages.Add()
 
    'Create the graphics for the page 
    Dim graphics As PdfGraphics = page.Graphics
 
    'Set the standard font 
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
 
    'Draw the text 
    graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
 
    'Open the document in the browser after saving it
    document.Save("Output.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)
End Using

 

A complete working sample can be download from CreatePDFSample.zip.

 

By executing the program, the generated PDF document directly open in the browser.

 

Resultant pdf document

 

Take a moment to peruse the documentation, where you can find options like drawing right-to-left text, multi-column text, consuming TrueType fonts, Standard fonts, CJK fonts, etc., and features like PDF form filling, extract text, or images from PDF, and protect PDF documents, etc., with code examples. 

Refer here to explore the rich set of Syncfusion Essential® PDF features.

 

See Also:

Create a PDF file in Windows Forms

Create a PDF file in WPF

Create a PDF file in ASP.NET Core

Create a PDF file in Xamarin Forms

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Click this link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how you can open the generated PDF document directly in the browser window instead of displaying the Open or Save dialog in the browser.

You can refer to our ASP.NET MVC PDF feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our ASP.NET MVC PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied