Print

ConvertFileToPDFEx()

A ConvertFileToPDFEx() function converts a file (Word, Excel, XML, HTML, JPG etc.) to a PDF file and returns it. When it comes to converting an XML file to the PDF, an XSLT template file has to be used. The XSLT file can be provided in an actionObject.options.xsltTemplate argument. If not provided, AMODIT will try to find it in the XML file and if not found, a raw XML content will be returned.

Syntax

ConvertFileToPDFEx(actionObject);

Function arguments

  • actionObject – (Object) an action object containing a sourceFile property from which the PDF file will be generated and an options object for other parameters;
  • actionObject.sourceFile – (UNKNOWN) a source file which will be converted to PDF. It can be a file name, a file id or a field name of the document type;
  • actionObject.options – (Object) [optional] an object that can contain an outputFilename and a xsltTemplate parameters:
    • actionObject.options.outputFilename – (String) [optional] a new name for the converted file;
    • actionObject.options.xsltTemplate – (UNKNOWN) [optional] an XSLT template identifier. It can be a template name, a template id or a name of the field with the XSLT template.

Return value

This function returns File.
The ConvertFileToPDFEx() function returns a file if the conversion has been successful, otherwise throws an exception that should be handled with a try/catch expression.

Examples

Example 1

The given actionObject with the sourceFile property will try to convert  a file attached to „Invoice” document-type field to a PDF and assign it in a file variable. If the conversion is not successful, the ConvertFileToPDFEx() function will throw an error, which can be handled in try and catch block.

actionObject.sourceFile = 'Invoice'
try
{
  file = ConvertFileToPDFEx(actionObject);
}
catch
{
  ShowMessage(1, exception);
}

Example 2

The given actionObject with the sourceFile property will try to convert an XML source file attached to „Invoice” document-type field to a PDF using an XSLT template attached to „Xslt for invoice” document-type field.

options.xsltTemplate = 'Xslt for invoice'
actionObject.sourceFile = 'Invoice'
actionObject.options = options
file = ConvertFileToPDFEx(actionObject)
file.fileName = 'Invoice.pdf'

Example 3

The given actionObject with the sourceFile property will try to convert an XML content taken from the source file attached to „Invoice to convert” document-type field to a PDF using an XSLT template attached to „Xslt for invoice” document-type field.

options.xsltTemplate = 'Xslt for invoice'
actionObject.sourceFile = [Invoice to convert]
actionObject.options = options
file = ConvertFileToPDFEx(actionObject)
file.fileName = 'Invoice.pdf'

Example 4

The given actionObject with the sourceFile property will try to convert an XML source file attached to „Invoice” document-type field to a PDF using an XSLT template attached to „Xslt for invoice” document-type field. Then the generated PDF file will be stored in „Converted invoice” document-type field with the name „Invoice.pdf” (assigned to the options.outputFilename parameter).

options.xsltTemplate = 'Xslt for invoice'
options.outputFilename = 'Invoice.pdf'
actionObject.sourceFile = 'Invoice'
actionObject.options = options
file = ConvertFileToPDFEx(actionObject)
[Converted invoice] = file

 

Czy artykuł był pomocny?
0 na 5 gwiazdek
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
How Can We Improve This Article?