Link Search Menu Expand Document

Getting Started in ASP.NET

The following sample demonstrates how to convert PDF to PNG in ASP.NET using PDF Renderer SDK

->
C#
<legacyBold xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Default.aspx:</legacyBold>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BasicExample._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>


        <legacyBold xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">Default.aspx.cs:</legacyBold>
using System;
using System.Web.UI;
using Bytescout.PDFRenderer;

namespace BasicExample
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Prepare a test document.
            // Multipage.pdf file will be copied to the project directory on the pre-build event (see the project properties).
            String inputDocument = Server.MapPath("multipage.pdf");

            // Create an instance of Bytescout.PDFRenderer.RasterRenderer object and register it.
            RasterRenderer renderer = new RasterRenderer();
            renderer.RegistrationName = "demo";
            renderer.RegistrationKey = "demo";

            // Load PDF document.
            renderer.LoadDocumentFromFile(inputDocument);

            // Prepare response.
            Response.Clear();
            Response.ContentType = "image/png";
            Response.AddHeader("Content-Disposition", "inline;filename=result.png");

            // Render first page of the document to the output stream.
            renderer.RenderPageToStream(0, RasterOutputFormat.PNG, Response.OutputStream);

            Response.End();
        }
    }
}