Slashdot Mirror


Pretty Printing From An XML File?

Omega1045 writes "Where I work we are developing a new product that receives an XML document (on a W2k workstation), and we need to format and print said document. We are currently using XSLT + CSS to build a cool little HTML page out the the XML, then use a browser to print out the HTML. However, while HTML is a nice format for display, it is not a nice format for printing. We have messed around with the idea of spitting out Rich Text with XSLT. However, Rich Text is confusing and quite frankly sucks. We are looking for a (free if possible) format that we can translate our XML document into via XSLT, and print. The best idea we have at this point is to translate into a Word or OpenOffice XML schema document, and use one of those applications to print. Other ideas?"

27 of 65 comments (clear)

  1. Postscript? by Hanji · · Score: 3, Interesting

    I'm not actually familiar with the details of postcript at all, but it certainly seems a logical format to consider if printing things is your concern.

    --
    A Minesweeper clone that doesn't suck
  2. FOP by pi_rules · · Score: 4, Informative

    Apache FOP Homepage

    Very powerful if you ask me. I used it on a project back in 2000-2001 and was pleased with how it turned out at the time. I'm sure the current product is much, much, better than it was back then.

    1. Re:FOP by danpat · · Score: 2, Informative

      I agree. XML-FO is supposed to be the W3C's "definitive" answer to an XML, page-oriented formatting language. XML-FO achieves basically exactly what PDF does, but in XML. It's supposed to be a structured representation of print-formatted data.

      I've used it quite a lot and it's great. It's very easy to transform your XML data into the XML-FO schema, from which you can use Apache-FOP (or one of the commercial tools) to turn it into a format other tools can use (PDF, ps, RTF, etc).

    2. Re:FOP by malachid69 · · Score: 2, Informative
      I agree. XML->XSL->FOP is the way to go.

      BTW, from http://www.w3schools.com/xslfo/xslfo_intro.asp:

      XSL-FO is Formally Named XSL Why this confusion? Is XSL-FO and XSL the same thing? Yes it is, but we will give you an explanation: Styling is both about transforming and formatting information. When the World Wide Web Consortium (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 separate Recommendations:

      • XSLT, a language for transforming information
      • XSL or XSL-FO, a language for formatting information
      • XPath, a language for defining parts of an XML document
      --
      http://www.google.com/profiles/malachid
    3. Re:FOP by pmuellr · · Score: 2, Interesting
      One problem with Apache's FOP is that it doesn't support keep, orphan, widow type stuff, so it's difficult to get nice looking paginated stuff, broken at natural places. FOP supports it in the 'spec', Apache FOP doesn't support it in the implementation.

      I was using FOP to create 'slides', and it did an ok job. Nice that it supports links in the PDF file.

      I also looked at ReportLab for Python, which seemed slightly better to me than FOP, with one exception. I think the link support was not as nice as Apache's, and at the time I was too reliant on it to be able to move to ReportLab.

  3. Try PDF by Mastos · · Score: 4, Informative

    I have a similiar problem I solve through the use of XSLT and XSL-FO. Use XSLT to transform the XML into XSL-FO. Then, use Apache FOP to render the XSL-FO into PDF.

    Another variation is to transform your XML into an HTML subset, then use a standard XSLT to transform the HTML into XSL-FO. A similiar technique is used by Aurigadoc to create all sorts of output formats using an XML source.

    1. Re:Try PDF by Apreche · · Score: 2, Informative

      That's a good idea. You can also translate into postscript, then send the postscript right to the printer. You can also use ps2pdf to make pdfs from the postscript. People don't realize, but postscript is actually a programming language you can write in. Turning an XML document into a postscript should be not outside the real of possibility with XSL.

      --
      The GeekNights podcast is going strong. Listen!
  4. XSLT-FO by JumpSuit+Boy · · Score: 4, Informative

    http://xml.apache.org/fop/
    http://www.cranesoftwr ights.com/training/ has a book about how do this that was created using XSLT-FO

    There are also paywhere implimentations XSLT-FO this. Basicaly it is the extension to XSLT for print.

    --
    Oh really?
  5. Consider YesLogic Prince by PornMaster · · Score: 3, Informative

    Prince is a batch formatter for converting XML into PDF and PostScript by applying Cascading Style Sheets (CSS). Unlike other formatters, Prince prints any XML vocabulary without relying on proprietary markup

  6. LaTeX by Asgard · · Score: 4, Insightful

    Generate a LaTeX document file, compile it using PDFLatex and print. Or, use normal LaTeX and print directly from it, depending if .dvi files offend you.

  7. PCL, depending on how complex your layout is. by np_bernstein · · Score: 2, Interesting

    The company I work for dynamically fills out complicated forms and fills in their data. We use PDF, sure, but if you've got any complicated stuff where you need things to be very exact, or need to support things like mixed pages sizes, etc. You want to look into Printer Control Language, originally created by HP and supported on most printers.

    --
    RandomAndInteresting.comdefending the world from stupidity since 1979
  8. Try Docbook by Pyromage · · Score: 2, Interesting

    Docbook is an XML based document format, with support to output to many different formats, including HTML and LaTeX, as I recall.

    I'm not sure how the docbook LaTeX filters work, but you may want to avoid LaTeX, for several reasons: special characters. LaTeX doesn't do Unicode, you'll have to translate those characters. That's not a huge problem, merely an annoyance.

    But quotes can be annoying. Latex wants directional quotes. This is fine only if you have full control of your source and are willing to deal with it.

    I tried to go direct to latex on one of my projects, it's not straightforward. Unless I'm missing something obvious; if someone does know a solution, please inform me 8-}

    1. Re:Try Docbook by CRCulver · · Score: 3, Informative

      LaTeX doesn't do Unicode, you'll have to translate those characters.

      Actually, LaTeX does do Unicode, and quite well. You just have to install Dominique Unruh's unicode package if your LaTeX distribution doesn't already ship it. I've used it for over a year to typeset documents with lots of Old Church Slavonic, Greek, and Hebrew, easily mixing scripts in one document and being free to keep all foreign scripts in UTF-8.

      If you would like to see some examples, check out my two tutorials for LaTeX for philologists (which I still work on and update from time to time).

  9. Docbook by ptaff · · Score: 3, Informative

    Another XML-based format is DocBook, which originally was SGML based but now has a XML DTD too. From this format you can output to ps, pdf, rtf and plenty of other formats.

    You could also hack one of the docbook XSL stylesheets (using XSLT? would be pretty!) to make it parse your own format.

    Feel ready to own one or many Tux Stickers?

  10. Apache FOP Supports Postscript by Mastos · · Score: 2, Informative

    While its support might not be complete (http://xml.apache.org/fop/output.html#ps) Apache FOP can also render into postscript. The advantage of XML-FO, while it hasn't been very well received, is it tries to be sufficiently expressive to support any number of output types from print (PDF, PS, RDF, etc) to graphics (SVG).

  11. SVG? by big+daddy+kane · · Score: 2, Interesting

    If I understand what you're asking, SVG would be a good choice. Bullet sharp text that prints excellently. It can be automatically generated and is based off of xml so it shouldn't be too hard to intergrate.

    1. Re:SVG? by hsoft · · Score: 2, Interesting

      Yup. I'd personally say "try harder with {X}HTML", but in case it fails utterly, SVG will definately be the way to go! It will be much harder for you though to transform XML into printable SVG than into XHTML.

      --
      perception is reality
  12. XMLPDF by WasterDave · · Score: 3, Informative

    Never quite sure what the hell it does myself, but a few people here swear by it:

    http://www.xmlpdf.com/

    Cheers,
    Dave

    --
    I write a blog now, you should be afraid.
  13. You're almost there... by BladeMelbourne · · Score: 4, Insightful

    Having been in the same situation before, this is what I suggest...

    Take the XML and the XSL and transform it into 100% valid XHTML. HTML 4 is deprecated, the standard will not be updated. XHTML 1.0 is 5 years old already - start to use it.

    Use CSS - pay attention to
    @media screen,print
    { /*Styles for browser and printer*/
    }
    @media screen
    { /*Styles for browser only*/
    }
    @media print
    { /*Styles for printer only*/
    }

    If it doesn't print well, you probably need to refresh your CSS here: http://www.w3.org/style

    Goodluck.

    1. Re:You're almost there... by Magnus+Reftel · · Score: 2, Interesting
      Take the XML and the XSL and transform it into 100% valid XHTML. HTML 4 is deprecated, the standard will not be updated.

      As the poster said, they've tried HTML, and didn't like it. I very much doubt that the print quality of XHTML would be any better than HTML. (I don't quite understand either why you're including screen styles for a page that is intended only for printing.)

      As for HTML 4 being a dead end, the WHAT WG, a collaboration among developers from most browsers, are defining a set of specifications intended to extend HTML4 in the short term, and serve as a base for a fifth version of HTML later.

      --
      print "Yet another p{erl,ython} hacker\n",
  14. Listen to me ;-) by cookiepus · · Score: 3, Interesting

    I've had do to just this, actually... here's the setup. Don't ask me why certain things were the way they were, certainly you can improve. I inherited some of this. But it worked...

    First, we had a bunch of product data in a MS SQL server db. We had a Java (I think) task that nightly dumped XML file (one per product) based on the DB.

    Then, we applied an XSLT transformation to each XML to produce the static HTML page for that day (static both to reduce server load and optimize google's searching of it, since Google didn't/doesn't like dynamic content)

    Then we wanted to produce a printer catalogue, so rather than printing pages, I made an XSLT that transformed the XML not into HTML but into FOP. FOP is some Java shit from Apache that takes FOP files and spits out a PDF.

    Obviously I don't remember details, but it worked.

    I had the idea to generate the PDFs not just for the printed catalogues but also as "printable version" for each HTML page. So both PDFs and HTMLs were generated nightly. Yeah it took a while but it was cool.

    It also served to improve our pagerank because (1) the PDFs made it look like we've got twice as much content and because (2) google gave higher weightings to PDFs (at the time, anyway)

    And, it was easy.

  15. ASCII by Rie+Beam · · Score: 3, Insightful

    You'd be surprised what a little coloring and some ASCII artwork can do.

  16. Me Too by KevMar · · Score: 3, Insightful

    We had this problem once, but worse.

    When I started with my current employer, we had a very complicated PDFing process. Every night a transfer workstation would copy datafiles localy from a backup of the production server. A pervasive driver was loaded to read the dat files. Access would import the data from pervasive and run a report that was saved as a RTF file. It was then opened in Word where a macro would then PDF the document and close. The PDF was then copied to the webserver for the users to download.

    What a mess and a nightmare to debug. It would work for a few months and then at seamingly random times, it would crash horibly for several days in a row.

    When it did break, i felt like I wasted a lot of time tracking down ghost problems. In my slow days I rewrote it.

    It now pulls read only data from the production server with that pervasive driver into a xml file. Then apply a xsl transform and pass the result to the FOP processor and place the result directly on the webserver.

    A process that took an hour to run now finishes in 2 minutes. It is quick enough, we run it every 20 min. FOP was quick to setup and the examples are like a blue print and easy to figure out.

    I have never had a problem with the new implementation and the end user had no impact and was unaware of the change.

    I would recomend using a FOP processor to my friends.

    --
    Im a gamer, not a grammer major. This post is full of spelling and grammer mistakes.
  17. XML -> RTF via XSL... by timjones · · Score: 2, Interesting
    I have two production applications at work that convert a subset of HTML to RTF via an rtf.xsl stylesheet, with results good enough, that my users actually call it (RTF) the "print" format, whilst the HTML is (naturally) the "view" format. The subset it supports is TABLE, TBODY/THEAD, TR/TD, FONT COLOR/SIZE, @BGCOLOR attributes, and rudimentary PNG/JPEG image embedding (but only as part of the text stream & in a table cell, not as independently positioned images). I had to add a few things to plain HTML, like a "base font size", a "landscape/portrait" attribute to BODY, and attributes to pass to RTF's "\cellx" tag (because HTML auto-sizes everything, and in RTF you have to specify the position of the right edges of table cells).

    All my users use Word as a helper application, which they think is great, but it makes me cringe to think of more invocations of an MS product.

    I would loved to try producing the PDF, XSL/FO and Postscript outputs via XSL transformations, just haven't had the time to try it yet. I'm sure they would yield better results, so go for it!

  18. ... Why are you asking slashdot? by op00to · · Score: 2, Funny

    Is /. now the offical R&D contractor for every shitty, piss-ant "company" with a "product" out there?

    Seriously, buddy. It's not hard. XML -> Perl/Php/Python/Whatever P you chose -> PostScript -> pretty printing

    Google is your friend.

  19. DocBook-XSL + XSL-FO + FOP by rjshields · · Score: 2, Insightful

    Use XSLT to transform your XML to DocBook, then use DocBook XSL to convert to XSL-FO, then Apache FOP to generate a PDF.

    Alternatively, skip the DocBook step and transform straight to XSL-FO.

    --
    In this world nothing is certain but death, taxes and flawed car analogies.
  20. Re:HTML is good enough by VTBassMatt · · Score: 2, Funny

    Welcome to my friends list.