0 Replies Latest reply on Oct 23, 2015 12:27 PM by Shaun Jalbert

    print to pdf silent

    Shaun Jalbert

      I posted a similar thread but have have decided to change directions - sort of.


      I'm in need of a macro to Print to PDF (Not to be confused with Save as PDF). It must be, no matter what, a "Print as PDF" macro because my manager absolutely refuses to permit  us to use the "Save as PDF" option because of some printing issues recently.

      The code below is what I have to work with, but I'm having some issues getting some standards nailed down.


      1) At the very least, I need the print specification in the script to set the options as shown in the attached image below. How can I do this?

      Right now, the script works, but my scales are off and adjusting the values below don't seem to have any effect.

          printSpec.FromScale = 1

          printSpec.ToScale = 1



      2) This is more of a wishlist item, but if its possible, it would be amazing if this script could run silently, naming the PDF as the SolidWorks file name (minus the "layout" or "sheet name" as the PDF automatically adds this) and then save it in a predetermined folder on the Users desktop called "Export". Can this be done?



      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swModelDocExt As SldWorks.ModelDocExtension

      Dim swPageSetup As SldWorks.PageSetup

      Dim printSpec As SldWorks.PrintSpecification

      Dim drawing As String

      Dim errors As Long

      Dim warnings As Long

      Dim footerTextNumber As String

      Dim footerTextCount As String

      Dim footerText As String


      Option Explicit

      Sub main()


          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swModelDocExt = swModel.Extension


          'Create a print specification

          swModel.Printer = "Adobe PDF"

          Set printSpec = swModelDocExt.GetPrintSpecification

          printSpec.ConvertToHighQuality = True

          printSpec.AddPrintRange 1, 1

          printSpec.FromScale = 1

          printSpec.ToScale = 1

          printSpec.ScaleMethod = swPrintSelection

          printSpec.PrinterQueue = ""

          printSpec.PrintToFile = False


          Debug.Print "Printing specifications:"

          Debug.Print "  Collate: " & printSpec.Collate

          Debug.Print "  Convert to high quality: " & printSpec.ConvertToHighQuality

          Debug.Print "  Current sheet: " & printSpec.CurrentSheet

          Debug.Print "  From scale: " & printSpec.FromScale

          Debug.Print "  To scale: " & printSpec.ToScale

          Debug.Print "  Number of copies: " & printSpec.NumberOfCopies

          Debug.Print "  Print background: " & printSpec.PrintBackground

          Debug.Print "  Print cross hatch on out-of-date views: " & printSpec.PrintCrossHatchOnOutOfDateViews

          Debug.Print "  Printer queue: " & printSpec.PrinterQueue

          Debug.Print "    File: " & printSpec.PrintFile

          Debug.Print "  Print white items black: " & printSpec.PrintWhiteItemsBlack

          Debug.Print "  Selection as defined in swPrintSelectionScaleFactor_e: " & printSpec.ScaleMethod

          Debug.Print "  Total sheet count: " & printSpec.SheetCount

          Debug.Print "  X origin: " & printSpec.XOrigin

          Debug.Print "  Y origin: " & printSpec.YOrigin


          ' Print the drawing to your default printer

          swModelDocExt.PrintOut4 "", "", printSpec





      End Sub