We have a page in our application that renders a certificate for the user, with the certificate graphics as a background image for the page and then the name of the user displayed "on-top" of the image.
You can see the page in action using the following link:
http://www.sdsreg.com/AKA/TEST/registration/attendance-certificate.aspx?SHOW=16005000&KEY=EF1CD0C8-BB90-4F89-B365-F8063CB8679ASimple HTML design:
<!DOCTYPE html>
<html>
<head>
<title>SDS | AKA Certificate</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../styles/styles-reports.css" />
<script type="text/javascript" src="../js/SDSREG.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div style="width:1000px; height:800px; background: url(../images/certificate_16005000.jpg) no-repeat">
<div style="height:300px; float:left; clear:both"></div>
<div style="width:1000px; float:left; clear:both">
<p style="text-align:center" class="textREPORT_BLACKxlarge"><strong>Soror Betty N. James</strong></p>
</div>
<div style="height:300px; float:left; clear:both"></div>
</div>
</form>
</body>
</html>
When the HTML is converted to PDF using HtmlToPdf, the background image is lost and we just see the text on a white background. We have a common routine for converting HTML to PDF - see below. We are passing the registrationID of the user, the output type (CERTIFICATE) and the HTMLData (from above). The file is generated properly and I can send you a copy of the PDF file from our server. The certificate image is 243 KB in size, dimensions are 1000 x 773 pixels. We do not get any errors, just no image is displayed in the resulting PDF file. The code that creates the HTML for PDF rendering is generating the PDF above, we turned off the redirect to the PDF file so you can see the HTML is working.
/*
* convertHTML2PDF
* ------------------------------------------------------------------------
* Convert HTML to PDF Document, Return File Name
* ------------------------------------------------------------------------
* Inputs:
* registrationID (int) = Registration ID
* outputType (string) = Output Type (REPORT, CERTIFICATE)
* HTMLData (string) = HTML Data
* ------------------------------------------------------------------------
* Outputs:
* results (string) = File Name to PDF Document
*
*/
public string convertHTML2PDF(int registrationID, string outputType, string HTMLData)
{
// get registration record
tblRegistrations registration = new tblRegistrations();
registration.getRegistration(registrationID);
// file prefix
string filePrefix = "";
// perform action based on Output Type
switch (outputType)
{
case "CERTIFICATE":
// file prefix = output type
filePrefix = outputType;
// Page Size = Letter, Landscape, 0.5" Margins, Do Not Auto Fit, Zoom = 100%
EO.Pdf.HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(PdfPageSizes.Letter.Height, PdfPageSizes.Letter.Width);
EO.Pdf.HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.5f, 0.3f, 7.5f, 10.4f);
EO.Pdf.HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
EO.Pdf.HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.None;
EO.Pdf.HtmlToPdf.Options.ZoomLevel = 1;
break;
// ALL OTHER TYPES
default:
// file prefix = output type
filePrefix = outputType;
// Page Size = Letter, 0.5" Margins, Do Not Auto Fit, Zoom = 100%
EO.Pdf.HtmlToPdf.Options.PageSize = new System.Drawing.SizeF(PdfPageSizes.Letter.Width, PdfPageSizes.Letter.Height);
EO.Pdf.HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.5f, 0.3f, 7.5f, 10.4f);
EO.Pdf.HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
EO.Pdf.HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.None;
EO.Pdf.HtmlToPdf.Options.ZoomLevel = 1;
break;
}
// get file name for label export (file prefix-badge ID-YYYYMMDDhhmmss.pdf, where YYYYMMDD is current date, hhmmss is current time)
string fileName = filePrefix + "-" + registration.PtxtBadgeID + "-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".pdf";
// get root directory of application
string rootDirectory = AppDomain.CurrentDomain.BaseDirectory;
// get file path to file
string filePath = rootDirectory + "/exports/" + fileName;
// set large address space to handle embedded images
EO.Base.Runtime.EnableLargeAddressSpace = true;
// preserve high resolution images in document
HtmlToPdf.Options.PreserveHighResImages = true;
// convert HTML to PDF file
HtmlToPdf.ConvertHtml(HTMLData, filePath);
// return file name
return fileName;
}