SelectPdf for .NET - Convert Multiple Urls into the same Pdf Document - C# / ASP.NET Sample

This sample shows how to convert 3 different urls to the same pdf document using SelectPdf Pdf Library for .NET.

Url 1: 

Url 2: 

Url 3: 



Sample Code C#



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SelectPdf;

namespace SelectPdf.Samples
{
    public partial class convert_multiple_urls_to_pdf : System.Web.UI.Page
    {
        protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            // read parameters from the webpage
            string url1 = TxtUrl1.Text;
            string url2 = TxtUrl2.Text;
            string url3 = TxtUrl3.Text;

            // create a new pdf document 
            PdfDocument doc = new PdfDocument();

            // add a new page to the document
            PdfPage page = doc.AddPage();

            // add the first url
            PdfHtmlElement html1 = new PdfHtmlElement(url1);
            PdfRenderingResult result = page.Add(html1);

            // get the last page of the previous conversion
            PdfPage page2 = doc.Pages[result.PdfPageLastIndex];

            // add the second url
            PdfHtmlElement html2 = new PdfHtmlElement(result.PdfPageLastRectangle.Left, 
                result.PdfPageLastRectangle.Bottom, url2);
            result = page2.Add(html2);

            // get the last page of the previous conversion
            PdfPage page3 = doc.Pages[result.PdfPageLastIndex];

            // add the third url
            PdfHtmlElement html3 = new PdfHtmlElement(result.PdfPageLastRectangle.Left, 
                result.PdfPageLastRectangle.Bottom, url3);
            result = page3.Add(html3);

            // save pdf document
            doc.Save(Response, false, "Sample.pdf");

            // close pdf document
            doc.Close();

        }
    }
}