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

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