NET8
This commit is contained in:
@ -1,43 +1,47 @@
|
||||
#if !NET8
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="BinaryContentResult.cs" company="SemanticArchitecture">
|
||||
// http://www.SemanticArchitecture.net pkalkie@gmail.com
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// An ActionResult used to send binary data to the browser.
|
||||
// </summary>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
#if NET8
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#endif
|
||||
|
||||
namespace Fab2ApprovalSystem.PdfGenerator {
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
#if !NET8
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// An ActionResult used to send binary data to the browser.
|
||||
/// </summary>
|
||||
public class BinaryContentResult : ActionResult {
|
||||
private readonly string contentType;
|
||||
private readonly byte[] contentBytes;
|
||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
||||
|
||||
public BinaryContentResult(byte[] contentBytes, string contentType) {
|
||||
this.contentBytes = contentBytes;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
public class BinaryContentResult : ActionResult {
|
||||
private readonly string contentType;
|
||||
private readonly byte[] contentBytes;
|
||||
|
||||
public override void ExecuteResult(ControllerContext context) {
|
||||
var response = context.HttpContext.Response;
|
||||
response.Clear();
|
||||
response.Cache.SetCacheability(HttpCacheability.Public);
|
||||
response.ContentType = this.contentType;
|
||||
public BinaryContentResult(byte[] contentBytes, string contentType) {
|
||||
this.contentBytes = contentBytes;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
using (var stream = new MemoryStream(this.contentBytes)) {
|
||||
stream.WriteTo(response.OutputStream);
|
||||
stream.Flush();
|
||||
}
|
||||
#if !NET8
|
||||
public override void ExecuteResult(ControllerContext context) {
|
||||
var response = context.HttpContext.Response;
|
||||
response.Clear();
|
||||
response.Cache.SetCacheability(HttpCacheability.Public);
|
||||
response.ContentType = contentType;
|
||||
|
||||
using (var stream = new MemoryStream(contentBytes)) {
|
||||
stream.WriteTo(response.OutputStream);
|
||||
stream.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
@ -1,79 +1,102 @@
|
||||
#if !NET8
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
#endif
|
||||
|
||||
#if !NET8
|
||||
namespace Fab2ApprovalSystem.PdfGenerator {
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
#if !NET8
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// This class represents the standard header and footer for a PDF print.
|
||||
/// application.
|
||||
/// </summary>
|
||||
public class PrintHeaderFooter : PdfPageEventHelper {
|
||||
private PdfContentByte pdfContent;
|
||||
private PdfTemplate pageNumberTemplate;
|
||||
private BaseFont baseFont;
|
||||
private DateTime printTime;
|
||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
||||
|
||||
public string Title { get; set; }
|
||||
#if !NET8
|
||||
|
||||
public override void OnOpenDocument(PdfWriter writer, Document document) {
|
||||
printTime = DateTime.Now;
|
||||
baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
|
||||
pdfContent = writer.DirectContent;
|
||||
pageNumberTemplate = pdfContent.CreateTemplate(50, 50);
|
||||
}
|
||||
public class PrintHeaderFooter : PdfPageEventHelper {
|
||||
|
||||
public override void OnStartPage(PdfWriter writer, Document document) {
|
||||
base.OnStartPage(writer, document);
|
||||
private PdfContentByte pdfContent;
|
||||
private PdfTemplate pageNumberTemplate;
|
||||
private BaseFont baseFont;
|
||||
private DateTime printTime;
|
||||
#endif
|
||||
|
||||
Rectangle pageSize = document.PageSize;
|
||||
#if NET8
|
||||
|
||||
if (Title != string.Empty) {
|
||||
pdfContent.BeginText();
|
||||
pdfContent.SetFontAndSize(baseFont, 11);
|
||||
pdfContent.SetRGBColorFill(0, 0, 0);
|
||||
pdfContent.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetTop(40));
|
||||
pdfContent.ShowText(Title);
|
||||
pdfContent.EndText();
|
||||
}
|
||||
}
|
||||
public class PrintHeaderFooter {
|
||||
|
||||
public override void OnEndPage(PdfWriter writer, Document document) {
|
||||
base.OnEndPage(writer, document);
|
||||
#endif
|
||||
|
||||
int pageN = writer.PageNumber;
|
||||
string text = pageN + " - ";
|
||||
float len = baseFont.GetWidthPoint(text, 8);
|
||||
public string Title { get; set; }
|
||||
|
||||
Rectangle pageSize = document.PageSize;
|
||||
pdfContent = writer.DirectContent;
|
||||
pdfContent.SetRGBColorFill(100, 100, 100);
|
||||
#if !NET8
|
||||
|
||||
public override void OnOpenDocument(PdfWriter writer, Document document) {
|
||||
printTime = DateTime.Now;
|
||||
baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
|
||||
pdfContent = writer.DirectContent;
|
||||
pageNumberTemplate = pdfContent.CreateTemplate(50, 50);
|
||||
}
|
||||
|
||||
public override void OnStartPage(PdfWriter writer, Document document) {
|
||||
base.OnStartPage(writer, document);
|
||||
|
||||
Rectangle pageSize = document.PageSize;
|
||||
|
||||
if (Title != string.Empty) {
|
||||
pdfContent.BeginText();
|
||||
pdfContent.SetFontAndSize(baseFont, 8);
|
||||
pdfContent.SetTextMatrix(pageSize.Width / 2, pageSize.GetBottom(30));
|
||||
pdfContent.ShowText(text);
|
||||
pdfContent.SetFontAndSize(baseFont, 11);
|
||||
pdfContent.SetRGBColorFill(0, 0, 0);
|
||||
pdfContent.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetTop(40));
|
||||
pdfContent.ShowText(Title);
|
||||
pdfContent.EndText();
|
||||
|
||||
pdfContent.AddTemplate(pageNumberTemplate, (pageSize.Width / 2) + len, pageSize.GetBottom(30));
|
||||
|
||||
pdfContent.BeginText();
|
||||
pdfContent.SetFontAndSize(baseFont, 8);
|
||||
pdfContent.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, printTime.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0);
|
||||
pdfContent.EndText();
|
||||
}
|
||||
|
||||
public override void OnCloseDocument(PdfWriter writer, Document document) {
|
||||
base.OnCloseDocument(writer, document);
|
||||
|
||||
pageNumberTemplate.BeginText();
|
||||
pageNumberTemplate.SetFontAndSize(baseFont, 8);
|
||||
pageNumberTemplate.SetTextMatrix(0, 0);
|
||||
pageNumberTemplate.ShowText(string.Empty + (writer.PageNumber - 1));
|
||||
pageNumberTemplate.EndText();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void OnEndPage(PdfWriter writer, Document document) {
|
||||
base.OnEndPage(writer, document);
|
||||
|
||||
int pageN = writer.PageNumber;
|
||||
string text = pageN + " - ";
|
||||
float len = baseFont.GetWidthPoint(text, 8);
|
||||
|
||||
Rectangle pageSize = document.PageSize;
|
||||
pdfContent = writer.DirectContent;
|
||||
pdfContent.SetRGBColorFill(100, 100, 100);
|
||||
|
||||
pdfContent.BeginText();
|
||||
pdfContent.SetFontAndSize(baseFont, 8);
|
||||
pdfContent.SetTextMatrix(pageSize.Width / 2, pageSize.GetBottom(30));
|
||||
pdfContent.ShowText(text);
|
||||
pdfContent.EndText();
|
||||
|
||||
pdfContent.AddTemplate(pageNumberTemplate, (pageSize.Width / 2) + len, pageSize.GetBottom(30));
|
||||
|
||||
pdfContent.BeginText();
|
||||
pdfContent.SetFontAndSize(baseFont, 8);
|
||||
pdfContent.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, printTime.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0);
|
||||
pdfContent.EndText();
|
||||
}
|
||||
|
||||
public override void OnCloseDocument(PdfWriter writer, Document document) {
|
||||
base.OnCloseDocument(writer, document);
|
||||
|
||||
pageNumberTemplate.BeginText();
|
||||
pageNumberTemplate.SetFontAndSize(baseFont, 8);
|
||||
pageNumberTemplate.SetTextMatrix(0, 0);
|
||||
pageNumberTemplate.ShowText(string.Empty + (writer.PageNumber - 1));
|
||||
pageNumberTemplate.EndText();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#if !NET8
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.html.simpleparser;
|
||||
using iTextSharp.text.pdf;
|
||||
#endif
|
||||
|
||||
using System.IO;
|
||||
|
||||
@ -31,6 +33,7 @@ public class StandardPdfRenderer {
|
||||
|
||||
public static MemoryStream GetPortableDocumentFormat(string pageTitle, string htmlText) {
|
||||
MemoryStream result = new();
|
||||
#if !NET8
|
||||
using (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
|
||||
using (PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, result)) {
|
||||
pdfWriter.CloseStream = false;
|
||||
@ -43,6 +46,7 @@ public class StandardPdfRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user