Export to Word / PDF file in ASP.NET

Export data to Word (DOCX) and PDF files in ASP.NET application with GemBox.Document component.

GemBox.Document is a C# / VB.NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, TXT) from .NET applications in a simple and efficient way without the need for Microsoft Word on either the developer or client machines.
GemBox.Document Free is free of charge while GemBox.Document Professional is a commercial version licensed per developer.
For more information, see GemBox.Document features and why GemBox.Document outperforms Word automation.

For more information about feature support and medium trust support for DOCX and PDF formats, see supported file formats.

Following example creates a document and exports it to a browser as a Word (DOCX) or PDF file stream.

C# code

// Create a new empty document.
var document = new DocumentModel();

// Add document content.
document.Sections.Add(
new Section(document,
new Paragraph(document, "Hello world!")));

// By specifying a location that is under ASP.NET application's control,
// GemBox.Document can use file system operations to retrieve font data
// when exporting to PDF in Medium Trust environment.
FontSettings.FontsBaseDirectory = this.Server.MapPath("Fonts/");

// Stream file to browser in requested file format.
document.Save(this.Response,
Path.ChangeExtension("Document", this.FileFormatRadioButtonList.SelectedValue));

VB.NET code

' Create a new empty document.
Dim document = New DocumentModel()

' Add document content.
document.Sections.Add(
New Section(document,
New Paragraph(document, "Hello world!")))

' By specifying a location that is under ASP.NET application's control,
' GemBox.Document can use file system operations to retrieve font data
' when exporting to PDF in Medium Trust environment.
FontSettings.FontsBaseDirectory = Me.Server.MapPath("Fonts/")

' Stream file to browser in requested file format.
document.Save(Me.Response,
Path.ChangeExtension("Document", Me.FileFormatRadioButtonList.SelectedValue))

For more detailed examples, see ASP.NET samples from GemBox.Document Sample Explorer.