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

Using the PDF Translator with Inventor 2016 API

Anonymous

Using the PDF Translator with Inventor 2016 API

Anonymous
Not applicable

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

0 Likes
Reply
1,139 Views
3 Replies
Replies (3)

ekinsb
Alumni
Alumni

The first argument to HasSaveCopyAsOptions should be the document, not the DataMedium object.  Here's a version of your function that is working for me to print sheet 2 and 3.

 

Public Sub SaveAsPDF2(ByVal doc As Document)
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
    Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(doc, oContext, oOptions) Then
        oOptions.value("All_Color_AS_Black") = 0
        oOptions.value("Remove_Line_Weights") = 0
        oOptions.value("Vector_Resolution") = 400
        oOptions.value("Sheet_Range") = kPrintSheetRange
        oOptions.value("Custom_Begin_Sheet") = 2
        oOptions.value("Custom_End_Sheet") = 3
    End If

    'Set the destination file name
    oDataMedium.filename = "c:\temp\test2.pdf"

    'Publish document.
    Call PDFAddIn.SaveCopyAs(doc, oContext, oOptions, oDataMedium)
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

Anonymous
Not applicable

Thanks for the response!

 

I replaced the line If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) with If oPDFAddIn.HasSaveCopyAsOptions(doc, oContext, oOptions), but I still received the same error. I even copy and pasted the code in the above post, and still received the same error.

 

I've resorted to using Foxit PDF printer for now, but I would much rather use the Inventor Translator so that Foxit installation is not a prerequisite for using my application.

 

Thanks,

Rohan Jhunjhunwala

 

0 Likes

ekinsb
Alumni
Alumni

The code that I pasted in works for me.  There must be something different on your system that's causing the problem.  Unfortunately, I don't have any ideas what that might be.  Do you have access to another computer that you could try it on to see if it's somehow machine specific?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes