Mike Phares 83789cdd91 Added ControllerExtensions to be used instead of HtmlViewRenderer for net8
Added HttpException class for missing HttpException for net8

Wrapped HttpContext.Session, GetJsonResult, IsAjaxRequest and GetUserIdentityName in controllers for net8

Added AuthenticationService to test Fab2ApprovalMKLink code for net8

Compile conditionally flags to debug in dotnet core
2025-05-19 13:29:54 -07:00

41 lines
1.4 KiB
C#

#if !NET8
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
#endif
using System.IO;
namespace Fab2ApprovalSystem.PdfGenerator;
public class StandardPdfRenderer {
private const int HorizontalMargin = 40;
private const int VerticalMargin = 40;
public byte[] Render(string htmlText, string pageTitle) {
byte[] renderedBuffer;
using (MemoryStream outputMemoryStream = new()) {
#if !NET8
using (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);
pdfWriter.CloseStream = false;
pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
pdfDocument.Open();
using (StringReader htmlViewReader = new StringReader(htmlText)) {
using (HTMLWorker htmlWorker = new HTMLWorker(pdfDocument)) {
htmlWorker.Parse(htmlViewReader);
}
}
}
#endif
renderedBuffer = new byte[outputMemoryStream.Position];
outputMemoryStream.Position = 0;
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
}
return renderedBuffer;
}
}