.vscode
Fab2ApprovalMKLink
Fab2ApprovalSystem
.vscode
App_Start
Content
Controllers
DMO
EmailTemplates
FTPBatch
JobSchedules
Jobs
Lib
Misc
Models
PdfGenerator
BinaryContentResult.cs
FakeView.cs
HtmlViewRenderer.cs
PdfViewController.cs
PrintHeaderFooter.cs
StandardPdfRenderer.cs
Properties
Scripts
Utilities
ViewModels
Views
fonts
.editorconfig
Fab2ApprovalSystem.csproj
Global.asax
Global.asax.cs
Project_Readme.html
README.md
Startup.cs
Test.html
Web.Debug.config
Web.Release.config
Web.config
favicon.ico
package.json
Fab2ApprovalTests
Kendo
MesaFabApproval.API
MesaFabApproval.Client
MesaFabApproval.Shared
SQL
references
.editorconfig
.gitignore
Fab2ApprovalSystem-Development.yml
Fab2ApprovalSystem.sln
Fab2ApprovalSystem.yml
README.md
azure-pipelines.yml
Removed nugetSource from pipeline Removed more comments Created Static Classes for most DMO / Controller Classes Push ConfigurationManager.AppSettings to controller Align Tests with other Projects
54 lines
2.1 KiB
C#
54 lines
2.1 KiB
C#
#if !NET8
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// <copyright file="PdfViewController.cs" company="SemanticArchitecture">
|
|
// http://www.SemanticArchitecture.net pkalkie@gmail.com
|
|
// </copyright>
|
|
// <summary>
|
|
// Extends the controller with functionality for rendering PDF views
|
|
// </summary>
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace Fab2ApprovalSystem.PdfGenerator {
|
|
using System.Web.Mvc;
|
|
using System.IO;
|
|
|
|
/// <summary>
|
|
/// Extends the controller with functionality for rendering PDF views
|
|
/// </summary>
|
|
public class PdfViewController : Controller {
|
|
private readonly HtmlViewRenderer htmlViewRenderer;
|
|
private readonly StandardPdfRenderer standardPdfRenderer;
|
|
|
|
public PdfViewController() {
|
|
this.htmlViewRenderer = new HtmlViewRenderer();
|
|
this.standardPdfRenderer = new StandardPdfRenderer();
|
|
}
|
|
|
|
protected ActionResult ViewPdf(string pageTitle, string viewName, object model) {
|
|
// Render the view html to a string.
|
|
string htmlText = this.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 = this.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 FileStream(fileName, FileMode.Create)) {
|
|
fs.Write(buffer, 0, buffer.Length);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif |