How to use RazorPDF in Umbraco 4.11

358 Views Asked by At

I'm using Umbraco 4.11.8 and want to create a PDF. I have HTML code, that should be downloadable as a PDF

I found a package RazorPDF, which works perfectly in a MVC sample.

But when I try it in Umbraco, I don't know how to get it.

Do I need a SurfaceController or anything else.

If yes, how do I say Umbraco to use my (Surface)Controller?

2

There are 2 best solutions below

5
On

The best place to start for what you need is here: http://our.umbraco.org/documentation/Reference/Mvc/

But no, strictly speaking you don't need a SurfaceController. You would only need one if you wanted to access the Umbraco context for the requests you are making via the controller.

So if you just want to have a controller serve up your PDF, you can have a standard controller implementation. You will have to adjust your routes for this though, and this is all covered in the Umbraco documentation above.

Edit:

You'll need a route like this:

RouteTable.Routes.MapRoute(
    name: "PdfRazor",
    url: "PdfCreator/{action}"
);

You will also need to add the path to the Web.config for Umbraco to ignore, e.g:

<add key="umbracoReservedPaths" value="~/umbraco,~/install,~/pdfcreator" />
0
On

I put it as answer so it's more readable. Feel free to edit.

I don't find my fault or what I'm missing.

My Controller signature is like this: public class PdfCreatorController : Controller

and the method, which I want to call is called public override ActionResult Pdf().

My routing:

RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    RouteTable.Routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );`. 

Then I try to call my controller like www.url.com/PdfCreator/Pdf.