Attachment 'pdf.xsl'

Download

   1 <?xml version="1.0" encoding="UTF-8"?>
   2 <xsl:stylesheet version="1.0" xmlns="urn:WebWorks-Engine-Files-Schema"
   3                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   4                               xmlns:msxsl="urn:schemas-microsoft-com:xslt"
   5                               xmlns:wwmode="urn:WebWorks-Engine-Mode"
   6                               xmlns:wwlinks="urn:WebWorks-Engine-Links-Schema"
   7                               xmlns:wwfiles="urn:WebWorks-Engine-Files-Schema"
   8                               xmlns:wwdoc="urn:WebWorks-Document-Schema"
   9                               xmlns:wwsplits="urn:WebWorks-Engine-Splits-Schema"
  10                               xmlns:wwtoc="urn:WebWorks-Engine-TOC-Schema"
  11                               xmlns:wwproject="urn:WebWorks-Publish-Project"
  12                               xmlns:wwpage="urn:WebWorks-Page-Template-Schema"
  13                               xmlns:wwlocale="urn:WebWorks-Locale-Schema"
  14                               xmlns:wwprogress="urn:WebWorks-XSLT-Extension-Progress"
  15                               xmlns:wwlog="urn:WebWorks-XSLT-Extension-Log"
  16                               xmlns:wwfilesystem="urn:WebWorks-XSLT-Extension-FileSystem"
  17                               xmlns:wwuri="urn:WebWorks-XSLT-Extension-URI"
  18                               xmlns:wwstring="urn:WebWorks-XSLT-Extension-StringUtilities"
  19                               xmlns:wwunits="urn:WebWorks-XSLT-Extension-Units"
  20                               xmlns:wwfilesext="urn:WebWorks-XSLT-Extension-Files"
  21                               xmlns:wwprojext="urn:WebWorks-XSLT-Extension-Project"
  22                               xmlns:wwadapter="urn:WebWorks-XSLT-Extension-Adapter"
  23                               xmlns:wwimaging="urn:WebWorks-XSLT-Extension-Imaging"
  24                               xmlns:wwexsldoc="urn:WebWorks-XSLT-Extension-Document"
  25 							  xmlns:wwdistpdf="urn:WebWorks-Distiller-PDF-Printer" 
  26                               exclude-result-prefixes="xsl msxsl wwmode wwlinks wwfiles wwdoc wwsplits wwtoc wwproject wwpage wwlocale wwprogress wwlog wwfilesystem wwuri wwstring wwunits wwfilesext wwprojext wwadapter wwimaging wwexsldoc wwdistpdf"
  27 >
  28  <xsl:param name="GlobalInput" />
  29  <xsl:param name="GlobalPipelineName" />
  30  <xsl:param name="GlobalProject" />
  31  <xsl:param name="GlobalFiles" />
  32  <xsl:param name="ParameterDependsType" />
  33  <xsl:param name="ParameterSplitsType" />
  34  <xsl:param name="ParameterPDFSplitFileType" />
  35  <xsl:param name="ParameterType" />
  36  <xsl:param name="ParameterCategory" />
  37  <xsl:param name="ParameterUse" />
  38  <xsl:param name="ParameterDeploy" />
  39 
  40 
  41  <xsl:namespace-alias stylesheet-prefix="wwfiles" result-prefix="#default" />
  42  <xsl:strip-space elements="*" />
  43 
  44 
  45  <xsl:key name="wwfiles-files-by-groupid-type" match="wwfiles:File" use="concat(@groupID, ':', @type)" />
  46  <xsl:key name="wwsplits-files-by-documentid" match="wwsplits:File" use="@documentID" />
  47 
  48 
  49  <xsl:variable name="GlobalActionChecksum">
  50   <xsl:variable name="VarTransformChecksums">
  51    <xsl:value-of select="concat(wwuri:AsFilePath('wwtransform:self'), ':', wwfilesystem:GetChecksum(wwuri:AsFilePath('wwtransform:self')))" />
  52   </xsl:variable>
  53   <xsl:value-of select="wwstring:MD5Checksum($VarTransformChecksums)" />
  54  </xsl:variable>
  55 
  56 
  57  <xsl:template match="/">
  58   <wwfiles:Files version="1.0">
  59 
  60    <!-- Groups -->
  61    <!--        -->
  62    <xsl:variable name="VarProjectGroups" select="$GlobalProject/wwproject:Project/wwproject:Groups/wwproject:Group" />
  63    <xsl:variable name="VarIgnore1">
  64     <xsl:value-of select="wwprogress:Start(count($VarProjectGroups))" />
  65    </xsl:variable>
  66    <xsl:for-each select="$VarProjectGroups">
  67     <xsl:variable name="VarProjectGroup" select="." />
  68 
  69     <xsl:variable name="VarIgnore2">
  70      <xsl:value-of select="wwprogress:Start(1)" />
  71     </xsl:variable>
  72 
  73     <!-- Load splits -->
  74     <!--             -->
  75     <xsl:for-each select="$GlobalInput[1]">
  76      <xsl:variable name="VarFilesSplits" select="key('wwfiles-files-by-groupid-type', concat($VarProjectGroup/@GroupID, ':', $ParameterSplitsType))[1]" />
  77      <xsl:variable name="VarSplits" select="wwexsldoc:LoadXMLWithoutResolver($VarFilesSplits/@path)" />
  78 
  79      <!-- Process group input documents -->
  80      <!--                               -->
  81      <xsl:variable name="VarFilesByType" select="key('wwfiles-files-by-groupid-type', concat($VarProjectGroup/@GroupID, ':', $ParameterDependsType))" />
  82      <xsl:variable name="VarIgnore3">
  83       <xsl:value-of select="wwprogress:Start(count($VarFilesByType))" />
  84      </xsl:variable>
  85      <xsl:for-each select="$VarFilesByType">
  86       <xsl:variable name="VarFile" select="." />
  87 
  88       <xsl:variable name="VarIgnore4">
  89        <xsl:value-of select="wwprogress:Start(1)" />
  90       </xsl:variable>
  91 
  92       <!-- Get PDF path -->
  93       <!--              -->
  94       <xsl:for-each select="$VarSplits[1]">
  95        <xsl:variable name="VarPDFSplitFile" select="key('wwsplits-files-by-documentid', $VarFile/@documentID)[@type = $ParameterPDFSplitFileType][1]" />
  96        <xsl:for-each select="$VarPDFSplitFile">
  97         <!-- Up-to-date? -->
  98         <!--             -->
  99         <xsl:variable name="VarUpToDate" select="wwfilesext:UpToDate($VarPDFSplitFile/@path, '', $VarFile/@groupID, $VarFile/@documentID, $GlobalActionChecksum)" />
 100         <xsl:if test="not($VarUpToDate)">
 101          <!-- Generate PDF -->
 102          <!--              -->
 103          <xsl:variable name="VarIgnore5">
 104 			 <!-- Try with Distiller -->
 105 			 <!--                    -->
 106 			 <xsl:variable name="VarPDFWithDistiller" select="wwdistpdf:FileToPDF($VarFile/@path, $VarPDFSplitFile/@path, wwprojext:GetFormatSetting('pdf-job-settings', 'Standard'))" />
 107 			 <xsl:if test="not($VarPDFWithDistiller)">
 108 				 <!-- Try again -->
 109 				 <xsl:variable name="VarPDFWithDistiller2" select="wwdistpdf:FileToPDF($VarFile/@path, $VarPDFSplitFile/@path, wwprojext:GetFormatSetting('pdf-job-settings', 'Standard'))" />
 110 				 <xsl:if test="not($VarPDFWithDistiller2)">
 111 					 <!-- Use GhostScript -->
 112 					 <!--                 -->
 113 					 <xsl:variable name="VarMsgGS" select="wwlog:Warning('Problem with Distiller; GhostScript used to generate ', $VarPDFSplitFile/@title)" />
 114 					 <xsl:value-of select="wwimaging:PostScriptToPDF($VarFile/@path, 'default', $VarPDFSplitFile/@path)" />
 115 				 </xsl:if>
 116 			 </xsl:if>
 117          </xsl:variable>
 118         </xsl:if>
 119 
 120         <!-- Track PDF file -->
 121         <!--                -->
 122         <wwfiles:File path="{$VarPDFSplitFile/@path}" type="{$ParameterType}" checksum="{wwfilesystem:GetChecksum($VarPDFSplitFile/@path)}" projectchecksum="" groupID="{$VarPDFSplitFile/@groupID}" documentID="{$VarPDFSplitFile/@documentID}" actionchecksum="{$GlobalActionChecksum}" category="{$ParameterCategory}" use="{$ParameterUse}" deploy="{$ParameterDeploy}">
 123          <wwfiles:Depends path="{$VarFile/@path}" checksum="{$VarFile/@checksum}" groupID="{$VarFile/@groupID}" documentID="{$VarFile/@documentID}" />
 124         </wwfiles:File>
 125 
 126        </xsl:for-each>
 127       </xsl:for-each>
 128 
 129       <xsl:variable name="VarIgnore6">
 130        <xsl:value-of select="wwprogress:End()" />
 131       </xsl:variable>
 132      </xsl:for-each>
 133 
 134      <xsl:variable name="VarIgnore7">
 135       <xsl:value-of select="wwprogress:End()" />
 136      </xsl:variable>
 137     </xsl:for-each>
 138 
 139     <xsl:variable name="VarIgnore8">
 140      <xsl:value-of select="wwprogress:End()" />
 141     </xsl:variable>
 142    </xsl:for-each>
 143 
 144    <xsl:variable name="VarIgnore9">
 145     <xsl:value-of select="wwprogress:End()" />
 146    </xsl:variable>
 147 
 148   </wwfiles:Files>
 149  </xsl:template>
 150 
 151 <!-- PostScript-to-PDF Code block -->
 152 <!--                              -->
 153 	
 154  <msxsl:script language="C#" implements-prefix="wwdistpdf">
 155   <![CDATA[
 156 		
 157 
 158     public bool  FileToPDF(string  ParamPostScriptFilePath,
 159                            string  ParamPDFFilePath,
 160                            string  ParamPDFOptions)
 161     {
 162       bool  VarResult = false;
 163 
 164       if (System.IO.File.Exists(ParamPostScriptFilePath))
 165       {
 166         string  VarParentDirectoryPath;
 167 
 168         // Create parent directories as needed
 169         //
 170         VarParentDirectoryPath = System.IO.Path.GetDirectoryName(ParamPDFFilePath);
 171         while (( ! String.IsNullOrEmpty(VarParentDirectoryPath)) &&
 172                ( ! System.IO.Directory.Exists(VarParentDirectoryPath)))
 173         {
 174           System.IO.Directory.CreateDirectory(VarParentDirectoryPath);
 175 
 176           VarParentDirectoryPath = System.IO.Path.GetDirectoryName(VarParentDirectoryPath);
 177         }
 178 
 179         // Parent directory exists?
 180         //
 181         VarParentDirectoryPath = System.IO.Path.GetDirectoryName(ParamPDFFilePath);
 182         if (System.IO.Directory.Exists(VarParentDirectoryPath))
 183         {
 184           object  VarDistillerInstance = null;
 185 
 186           try
 187           {
 188             Type  VarDistillerType;
 189 
 190             // Instantiate the COM object using late binding
 191             //
 192             VarDistillerType = Type.GetTypeFromProgID("PDFDistiller.PDFDistiller.1", true);
 193             VarDistillerInstance = System.Activator.CreateInstance(VarDistillerType);
 194             if (VarDistillerInstance != null)
 195             {
 196               object  VarMethodResult;
 197               long    VarOriginalSpoolJobs;
 198               long    VarSpoolJobs;
 199               short   VarMethodResultAsInt16;
 200 
 201               // Disable job spooling
 202               //
 203               VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
 204                                                               System.Reflection.BindingFlags.GetProperty,
 205                                                               null,
 206                                                               VarDistillerInstance,
 207                                                               null);
 208               VarOriginalSpoolJobs = Convert.ToInt32(VarMethodResult);
 209               VarSpoolJobs = 0;
 210               VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
 211                                                               System.Reflection.BindingFlags.SetProperty,
 212                                                               null,
 213                                                               VarDistillerInstance,
 214                                                               new object[]{VarSpoolJobs});
 215 
 216               // Invoke PostScript to PDF VarMethod
 217               //
 218               VarMethodResult = VarDistillerType.InvokeMember("FileToPDF",
 219                                                               System.Reflection.BindingFlags.InvokeMethod,
 220                                                               null,
 221                                                               VarDistillerInstance,
 222                                                               new object[]{ParamPostScriptFilePath, ParamPDFFilePath, ParamPDFOptions});
 223               VarMethodResultAsInt16 = Convert.ToInt16(VarMethodResult);
 224               if (VarMethodResultAsInt16 < 0)
 225               {
 226                 // Error during PDF generation!
 227                 //
 228               }
 229               else if (VarMethodResultAsInt16 == 0)
 230               {
 231                 // Invalid parameters!
 232                 //
 233               }
 234               else // (VarMethodResultAsInt16 > 0)
 235               {
 236                 // Success!
 237                 //
 238                 VarResult = true;
 239               }
 240 
 241               // Restore original job spooling setting
 242               //
 243               VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
 244                                                               System.Reflection.BindingFlags.SetProperty,
 245                                                               null,
 246                                                               VarDistillerInstance,
 247                                                               new object[]{VarOriginalSpoolJobs});
 248             }
 249           }
 250           catch
 251           {
 252             // Nothing to do!
 253             //
 254           }
 255           finally
 256           {
 257             // Clean up COM object
 258             //
 259             if (VarDistillerInstance != null)
 260             {
 261               System.Runtime.InteropServices.Marshal.ReleaseComObject(VarDistillerInstance);
 262             }
 263           }
 264         }
 265       }
 266 
 267       return VarResult;
 268     }
 269   ]]>
 270 		
 271  </msxsl:script>
 272 </xsl:stylesheet>

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-02-13 06:16:05, 0.6 KB) [[attachment:pdf.fti]]
  • [get | view] (2008-02-13 06:16:05, 12.3 KB) [[attachment:pdf.xsl]]
  • [get | view] (2008-02-13 06:16:05, 4.7 KB) [[attachment:scriptblock.txt]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.