andyhutch77 / MvcRazorToPdf

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.
125 stars 105 forks source link

Expose Document and Writer objects to callers #15

Closed ElanHasson closed 10 years ago

ElanHasson commented 10 years ago

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:

  return new PdfActionResult(model, (writer, document) =>
            {
                document.SetPageSize(new Rectangle(1000f, 1000f, 90));
                document.NewPage();

            });
ElanHasson commented 10 years ago

This is done and ready to be merged :)