Skip Navigation Links.
In this demo you learn how to control the page breaks in the generated PDF document using CSS styles. There are 3 styles controlling the page breaks that can be applied to a HTML document:

'page-break-before : always' style forces a page break in PDF right before the box where the element is rendered
'page-break-after : always' style forces a page break in PDF right after the box where the element is rendered
'page-break-inside : avoid' style will make the converter to generate the PDF such that the element with this style is not cut between PDF pages if possible
Server Settings
IP: Port: Password:
HTML Code
HTML Code Base URL
Browser Width: px
Skip Navigation Links
C# Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 HiQPdfClient;

namespace HiQPdf_Demo
{
    public partial class PdfPageBreaksControl : System.Web.UI.Page
    {
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            string serverIP = textBoxServerIP.Text;
            uint serverPort = uint.Parse(textBoxServerPort.Text);
            string serverPassword = textBoxServerPassword.Text;

            // create the HTML to PDF converter
            HtmlToPdf htmlToPdfConverter = new HtmlToPdf(serverIP, serverPort);

            // use server password if necessary
            if (serverPassword.Length > 0)
                htmlToPdfConverter.ServerPassword = serverPassword;

            // set a demo serial number
            htmlToPdfConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set browser width
            htmlToPdfConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text);

            // convert HTML to PDF
            byte[] pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(textBoxHtmlCode.Text, textBoxBaseUrl.Text);

            // inform the browser about the binary data format
            HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

            // let the browser know how to open the PDF document, attachment or inline, and the file name
            HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=PageBreaksControl.pdf; size={0}",
                            pdfBuffer.Length.ToString()));

            // write the PDF buffer to HTTP response
            HttpContext.Current.Response.BinaryWrite(pdfBuffer);

            // call End() method of HTTP response to stop ASP.NET page processing
            HttpContext.Current.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                textBoxBaseUrl.Text = "http://www.hiqpdf.com/ClientDemo/";

                Master.SelectNode("pdfPageBreaksControl");

                Master.LoadCodeSample("PdfPageBreaksControl");
            }
        }
    }
}