Create pdf documents within an asp .net mvc project by generating your views as normal but returning a PdfActionResult. This converts regular produced razor/html to pdf documents in the browser using the iTextXmlWorker.
The ability to access the Document and PdfWriter objects during document generation was needed. It allows me to do things like set page size and rotation, and control how metadata of the PDF.
I chose to expose it by exposing an Action<PdfWriter, Document> in the constructor for PdfActionResult.
Note: Using this functionality requires the calling project to reference iTextSharp and itextsharp.xmlworker. Hey, if you need it, go for it. I'm open to suggestions.
Example code for setting page size and using landscape mode:
The ability to access the
Document
andPdfWriter
objects during document generation was needed. It allows me to do things like set page size and rotation, and control how metadata of the PDF.I chose to expose it by exposing an
Action<PdfWriter, Document>
in the constructor forPdfActionResult
.Note: Using this functionality requires the calling project to reference
iTextSharp
anditextsharp.xmlworker
. Hey, if you need it, go for it. I'm open to suggestions.Example code for setting page size and using landscape mode: