Monday, 15 November 2010

Creating PDF documents dynamically using Umbraco and XSL-FO part 2

Since my last post I have made a few modifications to the PDF generation, the main one being that the files are now dynamically renamed so that they reflect the name of the case study instead of all being called PDF.PDF which was not a very helpful filename, I just wanted to get something live last week, so decided that something was better than nothing :)

The issue with the filenames comes down to the way that the PDF's are being generated by using an alternative template in Umbraco, this means that all you need to do is add " /pdf " to the end of a case study URL and it will create a PDF version of the case study. The down side is that your browser will merrily download the file and save it as PDF.PDF because that is the name of the last part of the URL.

What you need to do is set the content-disposition header to be equal to the name you would like the file use, Darren Ferguson mentioned this on the Change the name of the PDF forum post.

We have used the same technique for downloading dynamically generated excel files, so I thought it would be useful to create a small macro to set both this header and also to set the caching headers to prevent any caching issues, I think in the past we have experienced all possible issues, including various issues where IE behaves differently to other browsers when you are using SSL and so the below code should work in all situations!

The template for the PDF alternative template is very simple:

<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
   <umbraco:Macro Alias="PDFHeaders" runat="server"></umbraco:Macro>
   <umbraco:Macro xsl="FO-CaseStudy.xslt" Alias="PDFXSLFO" runat="server"></umbraco:Macro>
</asp:Content>

The following code snippet is the XSLT macro that simply creates our file name and then passes the file name into the helper function:

<xsl:template match="/">
        <xsl:variable name="fileName">
            <xsl:text>Vizioz_</xsl:text>
            <xsl:value-of select="$currentPage/@nodeName" />
            <xsl:text>_case_study.pdf</xsl:text>
        </xsl:variable>
        <xsl:value-of select="Vizioz.Helper:AddDocumentDownloadHeaders('application/pdf', $fileName)"/>
    </xsl:template>

And the following code is the helper function that clears the current response and adds all the appropriate headers:

public static void AddDocumentDownloadHeaders(string contentType, string fileName)
{
 HttpResponse response = HttpContext.Current.Response;
 HttpRequest request = HttpContext.Current.Request;

 response.Clear();
 response.ClearHeaders();

 if (request.IsSecureConnection & request.Browser.Browser == "IE")
  {
   // Don't use the caching headers if the browser is IE and it's a secure connection
   // see: http://support.microsoft.com/kb/323308
  }
 else
  {
   // force not using the cache
   response.AppendHeader("Cache-Control", "no-cache");
   response.AppendHeader("Cache-Control", "private");
   response.AppendHeader("Cache-Control", "no-store");
   response.AppendHeader("Cache-Control", "must-revalidate");
   response.AppendHeader("Cache-Control", "max-stale=0");
   response.AppendHeader("Cache-Control", "post-check=0");
   response.AppendHeader("Cache-Control", "pre-check=0");
   response.AppendHeader("Pragma", "no-cache");
   response.Cache.SetCacheability(HttpCacheability.NoCache);
   response.Cache.SetNoStore();
   response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
  }

 response.AppendHeader("Expires", DateTime.Now.AddMinutes(-1).ToLongDateString());
 response.AppendHeader("Keep-Alive", "timeout=3, max=993");
 response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
 response.ContentType = contentType;
}

I will write another blog soon with some more details about XSL-FO and how to create the PDF's dynamically.

Please do re-tweet if you find this interest :)

Saturday, 13 November 2010

PDF from Umbraco | Creating PDF case studies from data in the Umbraco CMS

Last week we launched the first version of our website based on Umbraco 4.5.2 and this week we have just added a bit of extra functionality to the case studies section which enables you to download the case studies as PDF documents.

To do this we used the PDF Creator package by Darren Ferguson, this is actually a wrapper around a product from a company called Ibex, which is where you can download documentation for the mark up required.

The way Darren has made the implementation is really simple for anyone already familiar with the Umbraco CMS. You simple create a new template and call a Usercontrol macro, this then does the magic in the background and passes an XSLT file to the ibex engine.

What you need to be aware of is that you need to learn a new mark up language called XSL-FO this is actually part of the XSL 1.0 specification and is a language used to express print layouts.

As an indication of timescale, from knowing nothing about XSL-FO to the finished product that you can see on the website now has taken me 2 days of learning and just fiddling with the mark up to get the final result.

If anyone is interested I might post some code snippets to show you how some of it is done, I would also be really interested to have some feedback about the PDF layout and what you like and don't like about it.

Cheers,

Chris

Posted using BlogPress from my iPad

Thursday, 4 November 2010

Residential Care Homes website launched based on the Umbraco CMS

This week we have launched a new website for a local company called Ascot Residential Homes. They run two homes for the elderly and for those who suffer with dementia. Before we built the site for Ascot Residential Homes they asked us to visit the homes to get a feeling about how special they are. If you are looking for a home for an elderly relative I would highly recommend having a look at their website and if you are in the area arranging to visit them.

If you look on our site you will also find an Ascot Residential Homes case study in our Umbraco case studies section.

Monday, 23 August 2010

England v Ireland Women's World Cup Rugby

Well, this is a slightly off topic post, but I couldn't resist posting a photo of my parents and I at the first England v Ireland Women's Rugby World Cup match.

As you can see, I had just given them both a Vizioz Musto Jacket which was very useful due to the wind and drizzle!

Friday, 23 July 2010

How do I stop someone using my domain for Spam emails?

Hi Blog Readers,

Every now and then I seem to have one of those low life Viagra sellers using my domain for spam emailing people.

I have done everything I can think of to try and prevent then from doing this, but they seem to keep doing it.

I just wondered if anyone out there new of a way to stop them?

The headers from one of the bounce backs look like this:
Return-Path: <gavottes@vizioz.com>
Received: from rctp.telecomitalia.it (host49-133-dynamic.52-82-r.retail.telecomitalia.it
[82.52.133.49])
by mx.google.com with SMTP id o8si307731weq.161.2010.07.23.05.33.53;
Fri, 23 Jul 2010 05:33:59 -0700 (PDT)
Received-SPF: fail (google.com: domain of gavottes@vizioz.com does not designate 82.52.133.49 as
permitted sender) client-ip=82.52.133.49;
Authentication-Results: mx.google.com; spf=hardfail (google.com: domain of gavottes@vizioz.com does
not designate 82.52.133.49 as permitted sender) smtp.mail=gavottes@vizioz.com
Message-ID: <3aaefd5365a446c33cfb0bb627waxworks@vizioz.com>
Date: Fri, 23 Jul 2010 14:33:52 +0200
From: Garnett Mckinnie <gavottes@vizioz.com>
MIME-Version: 1.0
To: NAME REMOVE <EMAIL@REMOVED.COM>
Subject: Where we are well established we are


As you can see from the headers, I have setup the SPF record and it is receiving a "hardfail"

We are using Google Apps for our email hosting, so you'd kinda hope that they have got things pretty much secured down, so what I am missing? Or is it always going to be possible for other people to fake sending emails using another domain?

Thursday, 1 July 2010

Umbraco Bingo

This year's Umbraco Code Garden Conference ( Festival ) was excellent, it was great to see so many familiar faces again, to see some inspiring talks and to enjoy the local beverages!

It has become a bit of a tradition at Umbraco conference's to host a Bingo game where the prizes are various Umbraco branded accessories, only a true Umbracoholic would want ;-)

This year, the luck gods were shinning down on me and I won the "grand prize" delivered by a "motorcycle courier" as it was such a large present... at least, that was the build up to finding out what it was! So everyone including myself were thinking, if this is that big, how on earth will I get it on the plane home!

Luckily, it was actually easy to fit in the luggage, as you will see below :)

Friday, 11 June 2010

Umbraco Code Garden 2010 - Ticket Auction for Charity

Hi All,

When Code Garden 2010 was first announced I bought two early bird tickets for the conference as at the time I had hoped to offer the ticket to one of my developers, but unfortunately both of them are unable to make the conference so I am left with a spare ticket.

Some people would try to sell the ticket to get the money back, but I thought I'd prefer to put the ticket up for auction and donate all the money to a charity called Able Kidz who help children with disabilities by providing them special computers and software.

If you would like to bid for the ticket please look at the auction here:

Umbraco Codegarden 2010 Ticket

Happy bidding and hopefully see the winner at Codegarden!

Sunday, 6 June 2010

Almost at our first year anniversary!

It has been a hectic first year at Vizioz and things are still going from strength to strength. 11 months ago I started Vizioz with zero capital investment in the middle of a recession, which to some may seem a daunting prospect but to others including myself it was the challenge I needed to make me want to get up in the morning :) I wanted to prove that even in the curent financial climate it is still possible to start a new business.

We are still experiencing the normal growing pains of a small business but this is something we just need to work our way through, it is amazing how much paperwork and administration there is running a small business, office admin, insurance, vat and for the last few months PAYE.

For the last 9 months we have shared an office with another small business called Little Big Ideas. They are a design agency working across a broad spectrum of design from branding, print and digital. Last month we decided to move offices to a larger office and now have room for 8 of us, so now we need a couple more clients to help produce enough work to fill the space and grow to the next level.

As well as moving office 2 months ago I blogged about my first employee Colin starting work for me, he has picked up Umbraco very well and has mastered the art of good CSS design, as the majority of our clients are large multi-nationals they still require support for IE6 which as all web developers know is the nightmare of all web browsers.

This month has seen the next step in the growth of Vizioz as I have taken on another PhD graduate called Pricilla, welcome to the team!

This month we plan to launch our own website to enable us to showcase some of the sites we have built over the past 11 months and to allow potential clients to see what we can offer. We might still be relatively small but we have some great case studies to show and with two PhD graduates on the team we have great talent capable of producing complex and innovative solutions for our clients.

As soon as we have launched out new website I will blog again about what the future holds for Vizioz and what we can offer our prospective clients as well as e obvious Umbraco CMS solutions.

Thursday, 18 March 2010

Post build events using ROBOCOPY instead of XCOPY

I don't know about you, but for a long time I have used XCOPY statements in my Visual Studio post build events to copy my Umbraco files from the project folders to the local version of the website associated with the project.

For the last few months we have been building a website framework for a client, who has subsequently sold the site to 5 clients, each with a different skin and some variations in their functional requirements.

So, we now have a single source solutions, that builds and copies the site files into 5 seperate local websites, which enables us to easily test them all, what we had found was that this process was starting to slow up our build process and was reaching 30-45 seconds on a high spec Quad core machine (and slower on others)

Today I asked Colin to create seperate Solution Configurations within Visual Studio so that while we were developing we could target a single site, and when we wanted to test all sites, we could target "ALL" and the Post Build script would then copy the files to all sites.

This worked well, and with a couple of other optimisations, our build was now taking about 10 seconds for a single site.

Then Colin came across ROBOCOPY and suggested that maybe this would be a suitable alternative to XCOPY, well, I had not heard of it.. (shock horror some of you shout, some I am sure like me, are also wondering what it is!)

ROBOCOPY is new in Windows Vista & Windows 7 (you can also download it for XP & Windows 2003) and it has a lot of additional features, the two that were most interesting to us were:

/MIR = Mirror a folder tree
/XD = Exclude Directories
/NP = No Progress (i.e. it does not give you a chart of it's results, which just fills up your Output window!)

So, we set about implementing ROBOCOPY, we decided to use the /MIR switch on all folders that we knew were always stored in our project folders:

- images
- css
- masterpages
- xslt

And for other files we just used the straight robocopy functionality.

We also decided to exclude all the .SVN directories using the /XD switch and finally we added the /NP switch as mentioned above.

The beauty of all of this, is the /MIR functionality, as this means that only files that have changed will be copied across which greatly speeds up the process, especially on the images folders which previously copied across on every build, now, if we add a new image to the project it will be copied across automatically and then never again, unless we change it of course!

The build time now for all sites is approximately 4 seconds and for a single site, 2 seconds, I would highly recommend the time to make the same optimisations to your build processes if you have not done so already.

Welcome to my first official full time employee!

The last few months have been pretty manic and Vizioz has been growing successfully into a fully fledged development agency. I have been working with a couple of excellent off shore developers who I would like to publicly thank for all their hard work over the last couple of months!

This week has been the start of a new era for Vizioz, I have taken on my first full time developer who is now based in our office in Reading, welcome to Colin. Which means we now have 3 Umbraco developers! Currently one with Level 2 qualification (me) but if business keeps growing I'll be sending the others for training shortly so hopefully by the end of the summer we'll be a certified solution provider.

We have lots of plans for the next 6 months, so it should be exciting times, subscribe to my RSS feed to come along for the ride :)

Sunday, 7 February 2010

Using the Windows Explorer Context Menu to reset Umbraco Directory Permissions

Hi All,

As Umbraco matures I am assuming that needing to reset directory permissions might well become a thing of the past, but at the moment it is still something when I copy sites between machines that I often find myself doing.

As it's 4:30am I thought, there must be a better way than having to open up a DOS prompt, navigate to a directory and then run a batch file passing in the IIS root folder location.

Well.. there is :)

I googled for adding a command to the context menu within Windows Explorer, I found a way of doing this for XP, but it seems the functionality was removed from Windows 7, however I found a very neat freeware application called File Menu Tools which does work perfectly!

I have now added a command to my context menu that enables me to right click an IIS site root folder and then call my batch script and automatically pass in the directory.

This will save me a bunch of time :)

Top 5 most popular posts