Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home

Running PDF conversion in event handler (VBscript)

Last updated on 28 September 2021

PDF Conversion

Overview

Please notice that scripting is not a part of standard support, and this is just an example script to show how to use the API. Be aware that all scripts are run at your own risk.

PDF conversions in M-Files can usually be managed in workflow state actions. However, in some cases it may be useful to be able to trigger this in an event handler. Such a case might be when the documents already have a workflow defined that cannot be changed, and you would like to trigger PDF conversion on some specific event.

The following script will offer some ideas for getting started with this. It is run in the BeforeCheckInChanges event handler, and includes some basic checks to not run for all objects.

Solution

Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer, False)
Dim oDocumentFiles : Set oDocumentFiles = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(ObjVer.ObjID, True, True).VersionData.Files
Dim oDocumentFile

'Only objects with Object ID of 0 will be handled
If ObjVer.Type = 0 Then

    'Only classes with class ID of 1 will be handled
    If PropertyValues.SearchForProperty(100).TypedValue.GetValueasLookup().Item = 1 Then

        For Each oDocumentFile In oDocumentFiles
            If oDocumentFile.Extension <> "pdf" And oDocumentFile.Extension <> "PDF" Then
            Vault.ObjectFileOperations.ConvertToPDF ObjVer, oDocumentFile.ID, False, True, False, False
            End If
        Next
    End if
End if

 

Still need help?

On this page