Having had to write a cv for the first time in a few years i quickly realised how frustrating it can be to have to update it in multiple documents, be that Word, html, pdf etc.
I decided (being a techy) that i would use xml as the base format for my cv and then use all the clever things that .NET Framework allows for to render my cv on a web page and in the generation of a pdf.
XML is mark up language used to describe data.
XSLT is a language for transforming XML documents into other XML documents. For example to display on a web page for for printing as a pdf document.
XSL-FO is a language for formatting XML data and stands for Extensible Stylesheet Language Formatting Objects and is a W3C Recommendation.
When W3C made their first XSL Working Draft, it contained the language syntax for both transforming and formatting XML documents. Later the XSL Working Group at W3C split the original draft into three separate Recommendations
XSLT, a language for transforming information XSL-FO, a language for formatting information XPath, a language for defining parts of an XML document
NFop is a .NET implementation (http://sourceforge.net/projects/nfop/) of the open source Apache FOP project (http://xml.apache.org/fop/).
"FOP (Formatting Objects Processor) is the world's first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter."
I'm not aware of any standard xml schema for cv's so i simply wrote my own xml file using farily arbitrary tags. Note that i'm not advocating this approach. This article is purely for those who want to see how it all actually works, apologies in advance for any sloppy mark up or code;)
The first part was easy. www.keithpatton.com/cv.xml is the xml for my cv. This is file i will update and change when i want to amend my cv. www.keithpatton.com/cv-xhtml.xsl is the stylesheet which transformed the base xml into xhtml compliant code for display on a web page.
The following single line can then be used using ASP.NET for example to display my cv on a web page:
<!-- cv is transformed xml as xhtml --><asp:xml id="cv" DocumentSource="cv.xml" TransformSource="cv-xhtml.xsl" Runat="server" />
The results are in the main column of www.keithpatton.com/cv.aspx
There are at least half a dozen commercial .NET components that will allow you to generate PDF's either using their own proprietary object model or using XSL-FO. I chose to use XSL-FO simply because it is an open standard and that there is a freely available open source component that worked for my purposes.
Download the binaries and stick the dll file into the /bin folder of your ASP.NET web application. Importantly, rename the dll to ApacheFop.net.dll (or it may not work).
Now, making the pdf is a 2 step process. Firstly, we must 'transform' the base xml to xsl-fo using xslt, ready for use by NFop. The xsl stylesheet for this transformation can be found at www.keithpatton.com/cv-fo.xsl. Secondly, the resulting xsl-fo formatter xml file is used by NFop to make the pdf.
These 2 steps are carried out by using the MakePdf method of the sample VB.Net class below.
------------------------------------------------------------Imports System.IOImports System.XmlImports System.Xml.XslImports ApacheFop '' NFOP
Public Class CVPDFMaker
Public Shared Sub MakePdf Try Dim objFOStream As New StringWriter() Dim objDoc As New XmlDocument() objDoc.Load(Request.PhysicalApplicationPath & "cv.xml") Dim objTransform As New XslTransform() objTransform.Load(Request.PhysicalApplicationPath & "cv-fo.xsl") objTransform.Transform(objDoc, Nothing, objFOStream) Dim eng As New Engine() '' using NFop Dim spdf As SByte() spdf = eng.Run(objFOStream.ToString()) Dim intLength As Integer = spdf.Length Dim fs As New FileStream(Request.PhysicalApplicationPath & "cv.pdf", FileMode.Create, FileAccess.Write) Dim binWriter As New BinaryWriter(fs) For intLength = 0 To (intLength - 1) binWriter.Write(spdf(intLength)) Next fs.Close() binWriter.Close() Catch objException As Exception '' something's gone wrong End TryEnd Sub
I then made a page at www.keithpatton.com/cvMakePdf.aspx which will take cv.xml and make a pdf of it at www.keithpatton.com/cv.pdf. I run this manually to update my cv online when i change the cv.xml file.
For more on XSLT - http://www.w3schools.com/xsl/default.aspFor more on XSL-FO - http://www.w3schools.com/xslfo/default.aspFor more on NFop - http://sourceforge.net/projects/nfop/
Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in anyway.
© Copyright 2013, Keith Patton