views:

467

answers:

3

EDIT: User has informed me that he will accept PDF format also

I have to create a simple RTF or PDF document in server side code and save on a network driver for future downloading.

The letter will be populated from info that I have stored in a SQL Server (2005). I access the databse using a Linq-to-Sql model. The document will be downloaded by a ASP.Net MVC 1.0 front end.

The structure of the file will be pretty basic. Its a letter with some basic info on it.

I have done some surfing and seen a few post recommending that I use XSLT to generate the RTf document.

Can anyone recommend a good tutorial on this? I've never used XSLT before, so a "For Dummies" tutorial would be great!

Any other technology suggestions would be appreciated. Looking for a quick win, doesn't need to be the perfect solution.

Thanks

C

+2  A: 

I'm a fan of the w3schools tutorials.

Here is one on XSLT: http://www.w3schools.com/xsl/

John Gietzen
+2  A: 

If you adopt this approach then the workflow you'll run will be something along the lines of:

  1. SQL Server -> Internal Representation
  2. Internal Representation -> XML Representation (probably using Linq to XML)
  3. XML + XSLT -> Output representation.

Basically what XSLT does is allow you to take XML and generate text from it according to a set of rules that are more functional than procedural its different. Having ascended the learning curve I've had a lot of success with XSLT (mostly producing HTML documents). The book that I leant on a lot to get started was the first edition of: XSLT: Mastering XML Transformations. For Beginners and Advanced Users by Doug Tidwell (which, with that long title, is now a second edition).

The practical question is do you want to produce a document from a template - that is you'll have a set of data will you be able to create the required document by mechanically dumping the data into a framework? The good news in this respect is that you can do a lot with XSLT. The better news is that you can store the XLST separately from the application, this makes it easier to tweak things and also gives you the option of having multiple templates that can be applied as required.

Since RTF is a text document format (?) you should be able to produce what you need from XLST.

The problem with PDF - if going down the XSLT route is that you need something to convert XSL-FO into a PDF document, not only that it will introduce more complexity and - in terms of a quick win - quite a bit more to learn.

Your alternative is to generate RTF or PDF straight from your internal model. You lose the templating capability but bring yourself closer to your basic comfort (code) - in this respect isharptext has had nice things said about it hereabouts.

I agree about the w3schools stuff.

I've gone on a bit, but the point is that yes, it should let you do want you need and will be a positive and flexible addition to your toolkit but you may suffer some pain along the way (XSLT is not procedural code, if you try and treat it that way you'll struggle).

Murph
For my longer term progress I'll look into the recommend book. I like the look of isharptext to get this done quickly. Have you seen it sued with a MVC action before?
littlechris
I haven't used iSharpText - I have done XML to PDF by way of XSL-FO using XML... but that requires a suitable toolkit and most are expensive. I'm also new to MVC, but it seems to me that it just something that will occur in an action. Unless I'm missing something, providing a link back via view should be straightforward if required.
Murph
+1  A: 

The two technologies I've used to produce PDFs:

  1. XML -> XSL-FO -> Apache FOP (Formatting Objects Processor) -> PDF. Advantages: if you understand HTML and XSLT, creating output with XSL-FO is not a lot harder than creating HTML with XSLT, software is open source. Disadvantages: Slow; XSL-FO is a bizarre funhouse-mirror form of HTML; you're integrating a big messy Java application into your document-production pipeline; software hasn't been upgraded since 2007.

  2. XML -> HTML -> Prince XML -> PDF. Advantages: Prince XML is fast and pretty functional; easy to create PDFs once your HTML format's worked out; software's free if all you're doing is printing the documents. Disadvantages: Prince's CSS extensions for pagination are not documented quite as well as I'd like; software's not free if you're producing PDF files; software's seriously not free if you're licensing it for a server.

The starting point in both cases is the XML -> XSLT -> HTML pipeline, so I'd start by learning that.

You can generate RTF and PDF directly via XSLT, but to do that, you need to know RTF and PDF pretty intimately, and PDF in particular is, as a CS professor I knew used to say, extremely non-trivial.

Robert Rossney