Support Center

Returning a PDF Image from an ASP.Net Page with ImageMan.Net

Last Updated: May 09, 2013 09:45AM EDT
The following code shows how easy it is to use ImageMan.Net Version 3.x in an asp.net server side application. The following code will load an image in any supported format and then stream it back to the client as a PDF image which can be displayed in the browser.

This could also be easily modify to use return the image in another image format such as GIF or PNG but PDF has the advantage of easily supporting multiple pages. 


VB.Net Code Behind

Imports DTI.ImageMan
Imports System.IO
Imports DTI.ImageMan.Codecs

Partial Class DisplayImage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Dim imgs As ImageCollection = New ImageCollection()

        ' Of course you would want to load your own image(s) here
        imgs.Load("d:\FAX-13Pgs-Test.FMP")

        ' We need to use a MemoryStream object to contain the PDF Image
        ' which we then write to the Response.OutputStream
        ' We need to do this as the .Save method cannot write directly to the 
        ' Response.OutputStream object

        Dim strm As MemoryStream = New MemoryStream()

        Dim pdf As PdfEncoder = New PdfEncoder()


        imgs.Save(strm, pdf)


        Response.Clear()

        Response.ContentType = "application/pdf"

        ' Send the bytes for the PDF image data to the browser
        strm.WriteTo(Response.OutputStream)

        ' Clean up our resources
        strm.Dispose()
        imgs.Dispose()

    End Sub

End Class 


C# Code 

ImageCollection imgs = new ImageCollection();

// Of course you would want to load your own image(s) here
        imgs.Load("d:\FAX-13Pgs-Test.FMP");
// We need to use a MemoryStream object to contain the PDF Image // which we then write to the Response.OutputStream // We need to do this as the .Save method cannot write directly to the // Response.OutputStream object MemoryStream strm = new MemoryStream(); PdfEncoder pdf = new PdfEncoder(); imgs.Save(strm, pdf); Response.Clear(); Response.ContentType = "application/pdf"; // Send the bytes for the PDF image data to the browser strm.WriteTo(Response.OutputStream); // Clean up our resources strm.Dispose(); imgs.Dispose();

Contact Us