Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
1138 Views, 3 Replies

Using the PDF Translator with Inventor 2016 API

Hello,

I am trying to write a VBA function that saves PDF files automatically. I have been using Document.SaveAs(), however I need to be able to control the sheet range that is exported. My function is as follows:

 

 

  Public Sub SaveAsPDF(ByVal doc As Document)
        Dim oPDFAddIn As TranslatorAddIn
        oPDFAddIn = _invApp.ApplicationAddIns.ItemById _
        ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
        Dim oContext As TranslationContext
        oContext = _invApp.TransientObjects.CreateTranslationContext
        oContext.Type = kFileBrowseIOMechanism
        Dim oOptions As NameValueMap
        oOptions = _invApp.TransientObjects.CreateNameValueMap
        Dim oDataMedium As DataMedium
        oDataMedium = _invApp.TransientObjects.CreateDataMedium

        If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
            oOptions.Value("All_Color_AS_Black") = 1
            oOptions.Value("Remove_Line_Weights") = 1
            oOptions.Value("Vector_Resolution") = 400
            oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

        End If


        'Set the PDF target file name
        oDataMedium.FileName = "C:\test.pdf"
        'Publish document
        oPDFAddIn.SaveCopyAs(doc, oContext, oOptions, oDataMedium)

    End Sub

When I run the function, passing it the open document (which is a drawing) I get a message in Inventor that says "Failed to publish DWF file" and when I click cancel I get the following error in my MSVS debugger on the oPDFAddIn.SaveCopyAs(doc, oContext, oOptions, oDataMedium) line:

 

error.PNG

I verified that {0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4} is the PDF translator ID, and even tried {0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}, which is the DWF translator.

 

Any guidance would be much appreciated!

Thanks,

Rohan Jhunjhunwala