Code: Select all
@model MyProjectLibrary.Model.PatientLetter[b]
@{
Layout = "~/Views/Shared/_LayoutPopup.cshtml";
}
body {
background-color: #FFF !important;
color: black !important;
font-size: 14px !important;
}
u {
font-size: 22px !important;
}
Certificate
@if (Model.LetterType != "Blank")
{
if (Model.LetterType == "Diagnosis Confirmation")
{
[u]To Whom It May Concern,[/u]
}
else if (Model.LetterType == "GP")
{
[u] CONFIDENTIAL[/u]
}
DATE:[/b]@Html.Raw(Model.AppointmentDateStr)[b]
Re:[/b]@Html.Raw(Model.modelPatient.FirstName) @Html.Raw(Model.modelPatient.SurName)[b]
DOB:[/b]@Html.Raw(Model.modelPatient.DateOfBirthDateOnly)[b]
if (Model.LetterType == "GP")
{
Dear Dr:[/b]@Html.Raw(Model.modelPatient.modelGPPractice?.Name)[b]
}
}
else
{
DATE:[/b]@Html.Raw(Model.AppointmentDateStr)
}
@Html.Raw(Model.LetterBody)
Regards,
@Html.Raw(Model.modelUser.DoctorSignature) (electronically sighted and signed)
[img]https://domain.com.au/Images/franzcp.png[/img]
Code: Select all
public FileResult DownloadPatientLetter(Int64 letterId)
{
PatientLetter model = objPatientLetterBLL.GetPatientLetterById(letterId);
model.modelPatient = objPatientBLL.GetPatientByPatientId(model.PatientId);
model.modelUser = objUserBLL.GetUserById(model.DoctorId);
// create a new pdf document converting an url
string htmlString = ViewToString(this, "ViewPatientLetter", model);
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.SerialNumber = "46u*****-ha+K*****-k****T-w9*****S-w9D*****-zd*****=";
SetHeader(htmlToPdfConverter.Document);
SetFooter(htmlToPdfConverter.Document);
string baseUrl = "https://domain.com.au";
byte[] pdfBytes = htmlToPdfConverter.ConvertHtmlToMemory(htmlString, baseUrl);
FileResult fileResult = new FileContentResult(pdfBytes, "application/pdf");
fileResult.FileDownloadName = model.modelPatient.FirstName + " " + model.modelPatient.SurName + "_Correspondence_" + model.AppointmentDateMonthYear + ".pdf";
if (!Convert.ToString(Session["_UserType"]).Equals("Super Admin"))
{
NotificationLogBLL objNotificationLogBLL = new NotificationLogBLL();
objNotificationLogBLL.AddPortalLog(Convert.ToInt64(Session["_UserId"]), "Download Patient Letter at " + LocalDateTime.ConvertToLocalTimeZoneStr(DateTime.UtcNow) + " by " + Convert.ToString(Session["_FullName"]));
}
return fileResult;
}
static string ViewToString(Controller controller, string viewName, object model)
{
controller.ViewData.Model = model;
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.ToString();
}
}
private void SetHeader(PdfDocumentControl htmlToPdfDocument)
{
// enable header display
htmlToPdfDocument.Header.Enabled = true;
if (!htmlToPdfDocument.Header.Enabled)
return;
// set header height
htmlToPdfDocument.Header.Height = 180;
float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;
float headerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left - htmlToPdfDocument.Margins.Right;
float headerHeight = htmlToPdfDocument.Header.Height;
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData("https://domain.com.au/Images/MyHeader.PNG");
MemoryStream ms = new MemoryStream(bytes);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
PdfImage logoHeaderImage = new PdfImage(0, 0, PdfPageSize.A4.Width, img);
htmlToPdfDocument.Header.Layout(logoHeaderImage);
PdfHtml headerHtml = new PdfHtml();
headerHtml.FitDestHeight = true;
headerHtml.FontEmbedding = true;
htmlToPdfDocument.Header.Layout(headerHtml);
}
private void SetFooter(PdfDocumentControl htmlToPdfDocument)
{
// enable footer display
htmlToPdfDocument.Footer.Enabled = true;
if (!htmlToPdfDocument.Footer.Enabled)
return;
// set footer height
htmlToPdfDocument.Footer.Height = 45;
float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData("https://domain.com.au/Images/Footer.JPG");
MemoryStream ms = new MemoryStream(bytes);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
PdfImage logoFooterImage = new PdfImage(0, 0, PdfPageSize.A4.Width, img);
htmlToPdfDocument.Footer.Layout(logoFooterImage);
PdfHtml footerHtml = new PdfHtml();
footerHtml.FitDestHeight = true;
footerHtml.FontEmbedding = true;
htmlToPdfDocument.Footer.Layout(footerHtml);
}
- Einstellen der Header- und Fußzeilenhöhen. Werte.