Coder Social home page Coder Social logo

razorpdf's Introduction

RazorPDF

RazorPDF is a simple project that makes it a breeze to create PDFs using the Razor view engine. Since Razor is really a template syntax, it can do lot more than just generate HTML. RazorPDF uses it to generate iText XML. Then using the iTextSharp library, we turn that iText XML into a PDF to return. The end result is a easy to use, clean method for generating PDFs.

##Usage The easiest way to get started with RazorPDF is to add the Nuget package to your MVC project. There is a short screencast on my blog to get you started so well as a sample project and some syntax samples.

##Acknowledgements RazorPDF likely wouldn't exist without the Spark view engine. The ability to create PDFs with the Spark view engine is something I've missed often since switching to using Razor as my default view engine in MVC projects. Huge thanks to Louis DeJardin for putting together the Spark view engine many years ago and for the idea of mixing Spark with iTextSharp as a nice way to make PDFs.

Also, RazorPDF is worthless without iTextSharp. Thanks so much to the team that works on that incredible project.

razorpdf's People

Contributors

razorant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

razorpdf's Issues

PageBreak

Hi, how can I add a page break?

I tried using the following css, but it didn't work.

<div style="page-break-before: always;">&nbsp;</div>

Any idea?

Thanks

Not compatible with last iTextSharp Version

Hi,

After update iTextSharp Nuget package to the last 5.3.3 version the parse failed because iTextSharp.text.xml.XMLParse can not be found.

Thank's for work.

Best regard's

Arabic Support

Hi,
awesome work, does it support Arabic Right to Left ?

thanks in advanced.

Css External

Hi, I am Brazilian, this is possible used css external, in the conversion of the html for pdf?
i am need many this. Thank You.

Cannot Create a PDF

I am getting an error

Expected > for tag: < 1000)/> near line 59, column 14

The Html if seen directly render correctly it has no error anyone know why?

Send the PdfResult as an Email

Hello,
I want to send the PdfResult as an email. I could not convert the RdfResult to MemoryStream.
The following code needs to be run but It's not working.
How can I fix this problem? Thank you.

public ActionResult test() {
PdfResult pdf1 = new PdfResult();
var context = ControllerContext;
MemoryStream asPdf = pdf1.ExecuteResult(context);
//other lines
return View();
}

Not compatible with Asp.net MVC 5?

Hi,

it looks like there are problems with MVC 5 and RazorPDF.

I cannot generate PDFs from iText XML files. RazorPDF always throws an exception. Do you know about the problem?

Regards
Markus

[XmlException: Name cannot begin with the '$' character, hexadecimal value 0x24. Line 1, position 2.]
System.Xml.XmlTextReaderImpl.Throw(Exception e) +69
System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) +78
System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) +5636816
System.Xml.XmlTextReaderImpl.ParseElement() +399
System.Xml.XmlTextReaderImpl.ParseDocumentContent() +149
System.Xml.XmlTextReaderImpl.Read() +213
System.Xml.XmlTextReader.Read() +13
RazorPDF.PdfView.Render(ViewContext viewContext, TextWriter writer) +225
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +480
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +50
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +123 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +582
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +115 System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +321 System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +184 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +140 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +63 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +50 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +45 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +81
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +146 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +66 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +50 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +50 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +146 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +66 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +50 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +50 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +45 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +81
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +146
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +66
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +50
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +49
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9631512
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Separate extensions for pdf templates

The project depends on the usage of PdfResult. This is nice and simple but forces you to make the decision on the type of output when writing the controller. This is opposed to the idea of being able to swap view engines without touching controller code and makes RazorPDF particularly problematic to use in environments where presentation is bound to the view model in a late manner.

I'm specifically talking about Orchard: http://orchardproject.net/. Orchard builds up dynamic view models but the templates are bound to the view models as a later step; this makes it possible to e.g. use separate view engine side by side, where one engine builds the markup for part of the layout and another for the other part.

The output type can be much loosely coupled to the controller if it depends on the views: you could just return a View("MyView") from your controller. Now if there's a MyView.cshtml, the result will be HTML. If it is (making up the extension) MyView.cspdf the result will be a PDF file.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.