Set left page margin

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 7.1.4.17

Syntax

      
 C#  Visual Basic 
public HtmlToRtf..::.CPageStyle..::.CUnit PageMarginLeft { get; set; }
Public Property PageMarginLeft As HtmlToRtf..::.CPageStyle..::.CUnit

Remarks



Examples

CopyASP.Net - Convert HTML to RTF using 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;
using System.Net;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        Result.Text = "";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();

        // After purchasing the license, please insert your serial number here to activate the component.
        // h.Serial = "XXXXXXXXX";

        //here we specify page numbers
        h.PageStyle.PageNumbers.Appearance = SautinSoft.HtmlToRtf.ePageNumberingAppearence.PageNumFirst;

        //specify HTML format as string
        h.PageStyle.PageHeader.Html("<table border=\"1\"><tr><td>We added this header using the property \"Header.Html\"</td></tr></table>");

        //add footer from HTML file
        h.PageStyle.PageFooter.FromHtmlFile(Path.Combine(Server.MapPath(""), @"footer.htm"));

        //get content of the ASPX page in HTML format
        string htmlString = GetHtmlFromAspx(Path.Combine(Server.MapPath(""), @"Default.aspx"));

        h.BaseURL = Server.MapPath("");

        string rtfString = String.Empty;

        if (h.OpenHtml(htmlString))
            rtfString = h.ToRtf();

        // Show result in the default RTF viewer app.
        if (!String.IsNullOrEmpty(rtfString))
        {
            Response.Clear();
            Response.ContentType = "application/rtf";
            Response.AddHeader("content-disposition", "inline; filename=\"Result.rtf\"");
            byte[] data = System.Text.Encoding.UTF8.GetBytes(rtfString);
            Response.BinaryWrite(data);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }

    public static string GetHtmlFromAspx(string url)
    {
        string contents = "";

        if (url.Length > 6)
        {
            //open 'http://' file
            if ((url[0] == 'h' || url[0] == 'H') && (url[1] == 't' || url[1] == 'T') &&
                (url[2] == 't' || url[2] == 'T') && (url[3] == 'p' || url[3] == 'P') &&
                url[4] == ':' && url[5] == '/' && url[6] == '/')
            {
                Stream StreamHttp = null;
                WebResponse resp = null;
                HttpWebRequest webrequest = null;

                try
                {
                    webrequest = (HttpWebRequest)WebRequest.Create(url);
                    resp = webrequest.GetResponse();
                    StreamHttp = resp.GetResponseStream();
                    StreamReader sr = new StreamReader(StreamHttp);
                    contents = sr.ReadToEnd();
                    return contents;
                }
                catch
                {
                }
            }

            //local file
            else
            {
                try
                {
                    StreamReader sr = new StreamReader(url);
                    contents = sr.ReadToEnd();
                    sr.Close();
                }
                catch
                {
                }
            }
        }
        return contents;
    }
}
CopyASP.Net - Convert HTML to RTF using 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
Imports System.Net

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Result.Text = ""
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim rtfString As String = Nothing

        Dim h As New SautinSoft.HtmlToRtf()

        ' Page properties.
        h.PageStyle.PageSize.Letter()
        h.PageStyle.PageMarginLeft.Mm(25)

        If h.OpenHtml(Path.Combine(Server.MapPath(""), "Default.aspx")) Then
            rtfString = h.ToRtf()
        End If

        ' Show result in the default DOCX viewer app.
        If rtfString IsNot Nothing Then
            Response.Clear()
            Response.ContentType = "application/rtf"
            Response.AddHeader("content-disposition", "inline; filename=""Result.rtf""")
            Response.Write(rtfString)
            Response.Flush()
            Response.End()
        Else
            Result.Text = "Converting failed!"
        End If
    End Sub
End Class

See Also