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

56 lines
1.6 KiB
C#

#if !NET8
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
#endif
#if !NET8
using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
#endif
namespace Fab2ApprovalSystem.PdfGenerator;
#if !NET8
public class PdfViewController : Controller {
private readonly HtmlViewRenderer htmlViewRenderer;
private readonly StandardPdfRenderer standardPdfRenderer;
public PdfViewController() {
htmlViewRenderer = new HtmlViewRenderer();
standardPdfRenderer = new StandardPdfRenderer();
}
protected ActionResult ViewPdf(string pageTitle, string viewName, object model) {
// Render the view html to a string.
string htmlText = htmlViewRenderer.RenderViewToString(this, viewName, model);
// Let the html be rendered into a PDF document through iTextSharp.
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
// Return the PDF as a binary stream to the client.
return new BinaryContentResult(buffer, "application/pdf");
}
protected void SavePdf(string fileName, string viewName, object model) {
// Render the view html to a string.
string htmlText = htmlViewRenderer.RenderViewToString(this, viewName, model);
// Let the html be rendered into a PDF document through iTextSharp.
byte[] buffer = standardPdfRenderer.Render(htmlText, "");
using (FileStream fs = new(fileName, FileMode.Create)) {
fs.Write(buffer, 0, buffer.Length);
}
}
}
#endif