PdfTemplating.XslFO.Razor.AspNet 1.0.0

Suggested Alternatives

PdfTemplating.XslFO.Razor.AspNetMvc

Additional Details

Package has been renamed for more clear delineation for the future.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package PdfTemplating.XslFO.Razor.AspNet --version 1.0.0
NuGet\Install-Package PdfTemplating.XslFO.Razor.AspNet -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PdfTemplating.XslFO.Razor.AspNet" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PdfTemplating.XslFO.Razor.AspNet --version 1.0.0
#r "nuget: PdfTemplating.XslFO.Razor.AspNet, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PdfTemplating.XslFO.Razor.AspNet as a Cake Addin
#addin nuget:?package=PdfTemplating.XslFO.Razor.AspNet&version=1.0.0

// Install PdfTemplating.XslFO.Razor.AspNet as a Cake Tool
#tool nuget:?package=PdfTemplating.XslFO.Razor.AspNet&version=1.0.0

PdfTemplating.XslFO

This is a C#.Net solution that provides the capability to easily generate Pdf files using a templated approach that provides great separation between presentation (the template) and data (the Model); as opposed to extremely complex code based approaches most libraries provide. It's based on the Xsl-FO standard and currently is dependent on an old but still very functional libray "Fonet" -- which is port of Apache FOP to C#.

In addition, this is a completely open-source and free solution to use (even commercially). Many of the complex (powerful maybe, but horribly difficult to develop and maintain) API libraries out there require licenses and are no longer possible solutions when simply due to steep licensing costs.

I hope this helps anyone looking to dynamically generate PDF files in C# or .Net with a templating approach that is far more maintainable than other code based generation/manipulation approaches . . .

Project Overview:

This project illustrates the capabilities of using templating based approaches to render Xsl-FO for dynamically generating PDF documents. This project illustrates the use and support of two of the most common/well-known templating engines for .Net web development -- Razor Templating & XSLT Templating.

The Razor & Xslt template based approaches to rendering PDF files gives you the benefits of separating the presentation from the Data model, allows different team members to work at the same time because the Template can be developed offline with sample Model data that can be easily loaded, and the code can be made very manageable with the use of Xslt include files, variables, etc. to divide your code into modular "DRY" components for re-use across multiple reports, etc.

In addition, the Razor & Xslt engines are extensible and can support virtually unlimited capabilities with C# based extension functions. For Razor templates the world of .Net is immediately available (e.g. Linq). And, for XSLT custom extension functions can be defined in the assembly or inlinein the Xslt, and this project has many custom extensions already included to augment the Xslt v1.0 engine that .Net provides.

Finally, this project also provides basic a Windows Client (WinForms) application that provides a UI that can be used for developing when using the Xslt templating engine.

NOTE: Currently the Razor Implementation requires Microsoft.AspNet.MVC and does not yet support .Net Core. I plan to extend this as soon as I have a real need to render Pdf file from a .Net Core web application; or a console app for that matter (useful info. [https://stackoverflow.com/questions/38247080/using-razor-outside-of-mvc-in-net-core](here on StackOverflow).)

Usage is as easy as:
Xslt (.Net Standard 2.0):
//Initialize the Model to use in the templating process...
MovieSearchResults movieSearchResults = GetMovieSearchResults();

//Initialize the appropriate Renderer based on the Model to use in the Template...
string xsltFullyQualifiedPath = HttpContext.Current.Server.MapPath("~/Reports.Xslt/MoviePdfReport/MoviesReport.xsl");

IPdfTemplatingRenderer<MovieSearchResponse> pdfTemplatingRenderer = new XsltPdfTemplatingRenderer<MovieSearchResponse>(
    new FileInfo(xsltFullyQualifiedPath)
);

//Execute the Pdf Renderer template for the specified Model to generate the Pdf Document...
byte[] pdfBytes = pdfTemplatingRenderer.RenderPdf(movieSearchResults);
Razor View (.Net Framework and requires Microsoft.AspNet.Mvc):
//Initialize the Model to use in the templating process...
MovieSearchResults movieSearchResults = GetMovieSearchResults();

//Initialize the appropriate Renderer based on the Model to use in the Template...
IPdfTemplatingRenderer<MovieSearchResponse> pdfTemplatingRenderer = new AspNetMvcRazorPdfTemplatingRenderer<MovieSearchResults>(
    "~/Reports.Razor/MoviePdfReport/MoviesReport.cshtml",
    ControllerContext
);

//Execute the Pdf Renderer template for the specified Model to generate the Pdf Document...
byte[] pdfBytes = pdfTemplatingRenderer.RenderPdf(movieSearchResults);
Caveats:

Unfortunately the FONET library that this currently uses doesn't support all features that Xsl-FO can provide, and it's not as up to date as the Apache FOP project that it ported over from. But, in my experience it's still very capable and has worked very well for my projects for many many years.

More Markdown details are available in Github here:

https://github.com/cajuncoding/PdfTemplating.XslFO

/*
Copyright 2012 Brandon Bernard

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

	 http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated

Initial package upload for PdfTemplating with Razor Templates.