Using XML, XSLT, and C # to Create RTF or PDF

EDIT: User informed me that he will also accept PDF

I need to create a simple RTF or PDF document on the server side and save the network driver for later download.

The letter will be populated from the information that I saved on SQL Server (2005). I am accessing a database using the Linq-to-Sql model. The document will be loaded through the ASP.Net MVC 1.0 interface.

The file structure will be quite simple. This is a letter with some basic information about this.

I surfed and saw some posts recommending using XSLT to create an RTf document.

Can someone recommend a good tutorial on this? I have never used XSLT before, so the Dummies tutorial would be great!

Any other technology suggestions would be appreciated. Finding a quick win does not have to be the perfect solution.

thanks

WITH

+1
source share
3 answers

If you take this approach, the workflow that you will run will look like this:

  • SQL Server -> Internal View
  • Internal View -> XML View (possibly using Linq to XML)
  • XML + XSLT -> Output View.

Basically, what XSLT does allows you to take XML and generate text from it according to a set of rules that are more functional than procedural ones, different. Having emerged from a learning curve, I had great success with XSLT (mainly creating HTML documents). The book in which I talked a lot about getting started was the first edition: XSLT: Mastering XML Transformations. For beginners and advanced users, Doug Tidwell (which with this long title is now the second edition).

Practical question: do you want to create a document from a template - that is, you will have a data set, can you create the necessary document by mechanically dumping data into a structure? The good news in this regard is that you can do a lot with XSLT. The best news is that you can store XLST separately from the application, this simplifies setup, and also gives you the opportunity to have several templates that can be applied as needed.

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

The problem with PDF - if you go along the XSLT route, you need to convert XSL-FO to a PDF document, not only that it will introduce more complexity and - in terms of quick victory - a little more to study.

Your alternative is to generate RTF or PDF directly from your internal model. You are losing the power of templates, but approaching your basic comfort (code) - in this regard, I have nice things that are mentioned here.

I agree with the w3schools stuff.

I did a bit of work, but the fact is that yes, this should allow you to do what you need and will be a positive and flexible addition to your toolbox, but you may experience some pain along the way (XSLT is not procedural code if you try to process it that way, you will fight).

+3
source

I am a fan of w3schools tutorials.

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

+2
source

Two technologies that I used to create PDF files:

  • XML -> XSL-FO -> Apache FOP (Object Formatting Processor) -> PDF. Advantages: if you understand HTML and XSLT, generating output using XSL-FO is not much more complicated than creating HTML with XSLT, the software is open source. Disadvantages: slow; XSL-FO is a weird HTML form form for funhouse-mirror; You integrate a large, messy Java application into your workflow. The software has not been updated since 2007.

  • XML → HTML → Prince XML → PDF. Advantages: Prince XML is fast and fairly functional; easy to create PDF files after developing the HTML format; the software is free if all you do is print documents. Disadvantages: CSS pagination extensions for pagination are not as well documented as we would like; the software is not free if you create PDF files; software is seriously not free if you license it for a server.

The starting point in both cases is XML -> XSLT -> HTML pipeline, so I would start by exploring this.

You can create RTF and PDF directly through XSLT, but for this you need to have a very deep knowledge of RTF and PDF, and PDF, in particular, is a CS professor whom I usually knew was extremely non-trivial.

+2
source

Source: https://habr.com/ru/post/949201/


All Articles