xml2pdf 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # pdf generation from xml and xsl
  3. # $1: .xsl file
  4. # $2: .xml file
  5. if [ $# -ne 2 ]
  6. then
  7. echo "usage: ${0##*/} <file.xsl> <file.xml>"
  8. exit 1
  9. fi
  10. test -z "$JAVA" && \
  11. JAVA=`which java`
  12. test -z "$JAVA" && \
  13. JAVA="$JAVA_HOME/bin/java"
  14. if [ ! -x "$JAVA" ]
  15. then
  16. echo 'error: java not found in your $PATH or in $JAVA_HOME/bin'
  17. exit 1
  18. fi
  19. test -z "$SAXON" && \
  20. SAXON=`which saxon`
  21. if [ -z "$SAXON" ]
  22. then
  23. test -z "$SAXONJAR" && \
  24. SAXONJAR='/usr/share/java/saxon.jar'
  25. if [ ! -f "$SAXONJAR" ]
  26. then
  27. SAXONJAR='/usr/local/share/java/saxon.jar'
  28. if [ ! -f "$SAXONJAR" ]
  29. then
  30. echo "error: neither saxon nor saxon.jar were found"
  31. exit 1
  32. fi
  33. fi
  34. SAXON="$JAVA -jar $SAXONJAR"
  35. fi
  36. if [ -n "$XML_CATALOG_FILES" ]
  37. then
  38. CATALOG_FILES=$XML_CATALOG_FILES
  39. else
  40. echo "warning: XML_CATALOG_FILES is not set or empty"
  41. CATALOG_FILES="/usr/local/etc/xml/catalog /etc/xml/catalog
  42. /usr/local/share/xml/catalog $HOME/xml/catalog"
  43. fi
  44. KEY="http://docbook.sourceforge.net/release/xsl/current"
  45. # manual base name
  46. SCM=claws-mail-manual
  47. for CATALOG in $CATALOG_FILES
  48. do
  49. if [ -s "$CATALOG" ]
  50. then
  51. DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY/")
  52. # second chance
  53. if [ $? -ne 0 -o -z "$DOCBOOKXSLPATH" ]
  54. then
  55. DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY")
  56. # still not found
  57. test $? -ne 0 -o -z "$DOCBOOKXSLPATH" && \
  58. continue
  59. fi
  60. test "`echo ${DOCBOOKXSLPATH} | cut -c 1-7`" = "file://" && \
  61. DOCBOOKXSLPATH=`echo ${DOCBOOKXSLPATH} | cut -c 8-`
  62. if [ -n "$DOCBOOKXSLPATH" ]
  63. then
  64. echo "docbook-xsl path found: $DOCBOOKXSLPATH"
  65. sed "s|@DOCBOOK_XSL_PATH@|$DOCBOOKXSLPATH|g" "$1" \
  66. > ${SCM}.xsl && \
  67. $SAXON -o ${SCM}.fo "$2" ${SCM}.xsl && \
  68. fop -fo ${SCM}.fo -pdf ${SCM}.pdf
  69. exit $?
  70. fi
  71. fi
  72. done
  73. echo "couldn't find docbook-xsl path from any of the following catalog files:"
  74. echo "$CATALOG_FILES"
  75. exit 1