Darren Ferguson - Blog

14 November 2011 at 21:40

Simple PDF generation from Umbraco with Razor or XSLT

Tags: PDF, XSL, Umbraco, XSL-FO, Razor, XSLT
Author: Darren Ferguson

The screencast below demonstrates PDF Creator for Umbraco 2.0. I've dropped the XSL prefix from the package title as you can now use the templating language of your choice to output PDF.

This tool does not mimic your HTML layouts in PDF format but allows you to define rich, unrestricted layouts suitable for printing using FO.

  • PDF files are created as Umbraco templates
  • PDFs are created using your templating language of choice, Razor, XSLT or your favourite.
  • Easily embed Fonts, Images and SVG.

vimeo_thumb

PDF Creator is a commercial package.

New features in version 2:

  • No custom Macro required - just use standard Umbraco templates to output FO.
  • Use Razor and other template languages.
  • Force the browser to download a PDF with a specific file name.
  • Big performance gains, both memory and CPU.
  • Newer version of PDF rendering engine with better FO support.
  • Improved user manual.

For examples of PDF files generated using PDF creator please have a look at the Vizioz Umbraco case studies  page.

I've also written a blog post on how to get started with the package.

 

12 November 2011 at 17:12

PDF From Umbraco in 3 Minutes

Tags: Umbraco, XSL-FO, PDF, FO, Razor
Author: Darren Ferguson

Here is a quick demonstration of how to generate PDF files from Umbraco using  PDF Creator for Umbraco. The whole process should take less than 3 minutes. You can click on the screenshots below for larger versions.

- Navigate to the Developer section of Umbraco.
- Expand the packages node in the tree and click "Umbraco package repository".
- Type PDF Creator in the search dialogue.

Screenshot1

- In the search results hover over PDF creator and then click Install Package

Screenshot2

- On the resulting screen check the checkbox labelled Accept License.
- Click the Install Package button.

Screenshot3

- Wait for package installation to be confirmed.
- Navigate to the settings section of Umbraco.
- Expand Document Types in the tree.
- Choose a Document type.
- In the Allowed templates control check one or more sample PDF templates.

Screenshot4

- Go to the Content section of Umbraco.
- Open a document of the type you set up a PDF template for.
- Associate one of those templates with your document.
- Click Save and Publish

Screenshot5

- When you open the document it is rendered as a PDF.

Ss7

By default this works for any document type that uses bodyText as the alias for the main Rich text content area.

PDF output can be fully customised by modifying the templates.

09 November 2011 at 21:02

Umbraco 5: Adding Dashboards via plugins

Tags: Umbraco, Jupiter, Plugin
Author: Darren Ferguson

I'll add this post to the Umbraco 5 wiki in due course.

This blog post will describe how to add dashboards to Umbraco 5 via a plugin - before starting, consider the following useful background reading:

There are 5 parts to Shannon's series on Umbraco jupiter plugins.

At time of writing (9th November 2011) some of the techniques used here require you to work from the latest Umbraco Jupiter source code - the example won't work with the latest alpha release.

Sample source code for the techniques described here are available at: http://umbraco5contrib.codeplex.com/ and you can get the source (mercurial) by cloning: https://hg01.codeplex.com/umbraco5contrib

The solution that this article refers to is in Source\Dashboard.HelloWorld.sln.  Please read ReadMe.txt  in the project root before building.

Obective:

To display a (Razor) view on and Umbraco 5 dashboard - using a custom controller provided by an Umbraco 5 plugin.

Plugin folder structure:

Plugins go in: App_Plugins\Packages\  for now we'll be copying from Visual Studio to this location using post build events. To package and redistribute a plugin you'll want to read Mat's article which is linked above.

In Dashboard.HelloWorld.csproj  you will need to modify the following XML to specify where you are running Umbraco 5 from.

<PropertyGroup>
    <Umbraco5Dir>C:\Users\Darren\Source\Umbraco\Source\Web Apps\Umbraco.CMS.Web.UI</Umbraco5Dir>
</PropertyGroup>

If you build the solution and browse to:

 App_Plugins\Packages\MyPackage.1.0  you should see the following child folders:

  • lib (DLL files from your plugin)
  • Views\Partial (Razor cshtml files from your plugin)

You'll also have a web.config at the root of your plugin folder. If you refresh the Umbraco back office you should see a Hello world view on your dashboard.

What makes this work:

The dashboard is defined in your plugin web.config - Umbraco Jupiter uses a technique known as deep config which means plugin cofig is merged with the main application configuration.

The dashboard snippet looks like this:

<umbraco.cms>
  <dashboard-groups>
    <group>
      <applications>
        <addapp="*"/>
      </applications>
      <dashboards>
        <addtab="Hello There people"type="childAction"name="Dashboard.Index"/>
      </dashboards>
    </group>
  </dashboard-groups>
</umbraco.cms>

The configuration above defines the following things:

  • The Umbraco application/section to add the dashboard to (in this case * which means all)
  • The tab title "Hello There people"
  • The type - childAction for a controller - you can use partialView to display a Razor file directly.
  • name - references the controller in the format Name.Action

How Umbraco 5 finds plugins:

In the solution open up AssemblyInfo.cs and note the inclusion of the following:

[assembly: AssemblyContainsPlugins()]

This attribute tells Umbraco to look inside this assembly for plugins.

Modifications to the controller:

Consider the controller in our project:

[Editor("960d4aaf-8fae-44da-a3ff-5a2430ee6e4a", HasChildActionDashboards = true)]
public class DashboardController : BaseEditorController
{
   public DashboardController(IBackOfficeRequestContext requestContext)
       : base(requestContext)
   {
   }

   [ChildActionOnly]
   public ActionResult Index()
   {
       return View("HelloWorld");
   }
}

The changes we've made in order for this to work on the dashboard are:

  • Decorate the class with the Editor  attribute and provide a GUID
  • In the Editor attribute pass in true to the HasChildActionDashboards property
  • Inherit from the base class BaseEditorController
  • Mark your action with the ChildActionOnly attribute