Convert XML to PDF

Scripting call:
sPdfFile = XmlToPdf (sPublication, sXmlFile, sLocation)

Function

Create a PDF rendition of an XML file.

The publication must have a partition called Template. The properties of this partition are used to initialise the temporary partition.

If a PDF file is successfully created, the temporary partition is removed.

If the PDF cannot be generated, an empty string is returned. In this case the temporary partition is retained, and its name is stored in the Partition property. After investigating the cause of the error, you can use the RemovePartition method to remove it.

Note that any composition problems, including warnings, will prevent the PDF from being created. To create the PDF when there are warnings and/or errors, use the GetPDF method.

This is a convenience method provided in the scripting interface only. The same effect can be achieved using the other interfaces by calling the appropriate functions directly.

The creation of the PDF can be controlled by properties of type pdf set with the Set Transform Property method.

[Warning] Warning

Any errors or warnings when creating a PDF are written to a log file in the same directory as the output file. The log file has the same name as the output file but with extension “.log” replacing the extension (if any) of the output file. Any existing file with this name will be silently removed.

Arguments

sPublication

The path to a publication, relative to the TopLeaf repository root. A temporary partition is created in this publication and the XML data in sXmlFile is linked to it.

sXmlFile

The path to a file containing the XML data.

sLocation

Determines where the PDF file is created:

  • If null or the empty string, the file is created in a directory designated for temporary files.

  • If it is the path to an existing directory, the file is created in this directory.

  • Otherwise, the file is created using sLocation as a path. Any existing file with this path will be overwritten.

Scripting Call Return

The return value is a string containing the path to the PDF file. This is always an absolute path. It is also available as the value of the OutputFile property.

If the PDF cannot be generated, an empty string is returned.

If warnings are reported in the composition, an empty string is returned and the Status property is set to 1093. In this case a PDF is generated and can by located using the value in the OutputFile property.

The PdfLog property contains the path to the log file containing warning and/or messages from the PDF builder, or the empty string if there were no messages.

Example

Scripting call:

file = topleaf.XmlToPdf("UserManual", xmlFile, "C:\\Temp");