Проблема преобразования PDF HIQ: текст тела перекрывается с заголовком и нижним колонтитуломC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Проблема преобразования PDF HIQ: текст тела перекрывается с заголовком и нижним колонтитулом

Сообщение Anonymous »

Я использую HIQ PDF, чтобы преобразовать свой HTML -контент в документ PDF. Иногда я сталкиваюсь с проблемой, когда текст тела перекрывается с заголовком и нижним колонтитулом. Эта проблема не возникает каждый раз, но происходит время от времени. Ниже приведен код, который я использую. view:

Код: Выделить всё

@model MyProjectLibrary.Model.PatientLetter

@{
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]









контроллер

Код: Выделить всё

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);
}

Проблема: Текст тела иногда перекрывается с заголовком и нижним колонтитулом в сгенерированном PDF. Кто -нибудь столкнулся с аналогичной проблемой, и если да, то как вы его решали? Значения.

Мне нужно решить проблему текста тела.>

Подробнее здесь: https://stackoverflow.com/questions/794 ... and-footer
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»