Converts HTML/ASPX file or url to PDF bytes

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 5.0.11.22

Syntax

      
 C#  Visual Basic 
public byte[] ConvertHtmlFileToPDFStream(
	string inputHtmlFile
)
Public Function ConvertHtmlFileToPDFStream ( _
	inputHtmlFile As String _
) As Byte()

Parameters

inputHtmlFile
String
Path or url to HTML/ASPX page

Return Value

PDF document as byte array - in case of converting successfully
null - in case of converting failed

Remarks



Examples

CopyASP.Net - Convert HTML-URL to PDF in C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{  
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBoxURl.Text == "")
        {
            Result.Text = "Please type any URL before start converting!";
            return;
        }

        SautinSoft.PdfVision v = new SautinSoft.PdfVision();

        // Set "Edge mode" to support all modern CSS.
        SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

        byte[] pdfBytes = null;

        //Specify top and bottom page margins
        v.PageStyle.PageMarginTop.Mm(5f);
        v.PageStyle.PageMarginBottom.Mm(5f);

        //convert URL to pdf stream
        pdfBytes = v.ConvertHtmlFileToPDFStream(TextBoxURl.Text);


        //show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            //Response.AddHeader("Content-Disposition:", "attachment; filename=Result.pdf");
            Response.AddHeader("Content-Disposition:", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
}
CopyASP.Net - Convert HTML-URL to PDF in VB.Net
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If TextBoxURl.Text = "" Then
            Result.Text = "Please type any URL before start converting!"
            Return
        End If

        Dim v As New SautinSoft.PdfVision()

        'Set "Edge mode" to support all modern CSS.
        SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry()

        Dim pdfBytes() As Byte = Nothing

        'Specify top and bottom page margins
        v.PageStyle.PageMarginTop.Mm(5.0F)
        v.PageStyle.PageMarginBottom.Mm(5.0F)

        'convert URL to pdf stream
        pdfBytes = v.ConvertHtmlFileToPDFStream(TextBoxURl.Text)


        'show PDF
        If pdfBytes IsNot Nothing Then
            Response.Buffer = True
            Response.Clear()
            Response.ContentType = "application/PDF"
            'Response.AddHeader("Content-Disposition:", "attachment; filename=Result.pdf");
            Response.AddHeader("Content-Disposition:", "inline; filename=Result.pdf")
            Response.BinaryWrite(pdfBytes)
            Response.Flush()
            Response.End()
        Else
            Result.Text = "Converting failed!"
        End If
    End Sub
End Class

See Also