AnsweredAssumed Answered

"Print to PDF" and save to specified directory

Question asked by Shaun Jalbert on Oct 21, 2015
Latest reply on Dec 3, 2015 by Heinz Navratil

We've been performing "Save as PDF" for creating all of our PDF's but ran into some issues recently and now management wants us to "print to PDF" instead.


For our save as PDF, we had a handy little macro that:

1) ran the save as PDF command.

2) saved the PDF to a specified location.


Is it possible to manipulate our API code to do this again, but launch the "Print as PDF" command instead?

Another issue is that we require the PDF file to be full scale - so is there an option for that too?


Below is our previous code for reference:


Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim sFileName As String

Dim sPathName As String

Dim strFullPath As String

Dim bRet As Boolean

Dim nErrors As Long

Dim nWarnings As Long

Dim Path As String


Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc


    sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

    sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1)


    sPathName = Environ("USERPROFILE") & "\Desktop\Export\"


    If Dir(sPathName) = "" Then

            MkDir sPathName

    End If


    sPathName = sPathName & sFileName & ".PDF"


    bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)



    If bRet = False Then

        swApp.SendMsgToUser2 "Problems saving file.", swMbWarning, swMbOk

    End If


End Sub


Public Function FolderFromPath(strFullPath As String) As String

    Dim I As Integer


    strFullPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") - 1)


    For I = Len(strFullPath) To 1 Step -5

        If Mid(strFullPath, I, 1) = "\" Then

            FolderFromPath = Left(strFullPath, I)

            Exit For

        End If


End Function