C# ITEXTSHARP

string pathImagenPlantilla = Server.MapPath(<path_of_the_image_template>);

//generar el pdf al vuelo
string filenamePDF = "Your_Document_Name.pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filenamePDF);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

//load the image template
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(pathImagenPlantilla);

//define your HTML code
StringBuilder strTextoHTML = new StringBuilder();
strTextoHTML.Append("<html>");
strTextoHTML.Append("<body>");
strTextoHTML.Append(<your HTML CODE right here>);
strTextoHTML.Append("</body>");
strTextoHTML.Append("</html>");

// margins, in milimeters
float margenIzquierdo = 25;
float margenDerecho = 25 ;
float margenSuperior = 25 ;
float margenInferior = 10 ;
Document pdfDoc = new Document(PageSize.A4, margenIzquierdo, margenDerecho, margenSuperior, margenInferior);

//Adjust the size of image template , to the screen size
float pageWidth = pdfDoc.PageSize.Width - (margenIzquierdo + margenDerecho);
float pageHeight = pdfDoc.PageSize.Height - (margenInferior + margenSuperior);
jpg.SetAbsolutePosition(margenIzquierdo, margenInferior);
jpg.ScaleToFit(pageWidth, pageHeight);

//If you want to choose image as background then,
jpg.Alignment = iTextSharp.text.Image.UNDERLYING;

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();
pdfDoc.NewPage();

//add image template
pdfDoc.Add(jpg);

//add html code
foreach (IElement E in HTMLWorker.ParseToList(new StringReader(strTextoHTML.ToString()), new StyleSheet()))
{
    pdfDoc.Add(E);
}

//close doc  and display/download
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();