> Save File as PDF Example (VB.NET)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

Save File as PDF Example (VB.NET)

This example shows how to save multiple drawing sheets to a PDF file.

'-----------------------------------

' Preconditions:

' 1. Specified drawing document to open exists.

' 2. The folder (c:\test) to which to save

'    the PDF file, exists. If it does not exist,

'    create it or change the path to one that

'    exists on your system.

'

' Postconditions:

' 1. Specified drawing document is opened.

' 2. All but the last drawing sheet are saved to an array.

' 3. The array of drawing sheets are saved to a PDF

'    file called foodprocessor.pdf.

'---------------------------------------

Imports System.Runtime.InteropServices

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

Partial Class SolidWorksMacro

    Public Sub main()

 

        Dim swExportPDFData As ExportPdfData

        Dim swModel As ModelDoc2

        Dim swModExt As ModelDocExtension

        Dim swDrawDoc As DrawingDoc

        Dim boolstatus As Boolean

        Dim filename As String

        Dim errors As Integer

        Dim warnings As Integer

        Dim objs() As Object

        Dim obj As Object

        Dim dispWrapArr() As DispatchWrapper

 

        ' Save PDF file to this folder and filename

        filename = "c:\test\foodprocessor.pdf"

 

        ' Open drawing document

        swModel = swApp.OpenDoc6("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\advdrawings\foodprocessor.slddrw", swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)

        swModExt = swModel.Extension

        swExportPDFData = swApp.GetExportFileData(swExportDataFileType_e.swExportPdfData)

 

        ' Get the names of the drawing sheets in the drawing

        ' to get the size of the array of drawing sheets

        swDrawDoc = swModel

        obj = swDrawDoc.GetSheetNames

        Dim count As Integer

        count = UBound(obj)

        ReDim objs(count)

        Dim i As Integer

        ' Active each drawing sheet, except the last drawing sheet for

        ' demonstration purposes only, and add each sheet to an array

        ' of drawing sheets

        For i = 0 To count - 1

            boolstatus = swDrawDoc.ActivateSheet(obj(i))

            Dim swSheet As Sheet

            swSheet = swDrawDoc.GetCurrentSheet

            objs(i) = swSheet

        Next i

 

        ' Convert the .NET array of drawing sheets objects to IDispatch

        dispWrapArr = ObjectArrayToDispatchWrapperArray(objs)

 

        ' Save the drawings sheets to a PDF file

        boolstatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, dispWrapArr)

        boolstatus = swModExt.SaveAs(filename, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, swExportPDFData, errors, Warnings)

 

    End Sub

 

    Function ObjectArrayToDispatchWrapperArray(ByVal Objects As Object()) As DispatchWrapper()

        Dim ArraySize As Integer

        ArraySize = Objects.GetUpperBound(0)

        Dim d(ArraySize) As DispatchWrapper

        Dim ArrayIndex As Integer

        For ArrayIndex = 0 To ArraySize

            d(ArrayIndex) = New DispatchWrapper(Objects(ArrayIndex))

        Next

        Return d

    End Function

 

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

End Class



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Save File as PDF Example (VB.NET)
*Comment:  
x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2011 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of Dassault Systèmes SolidWorks Corporation or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2011 SP05.

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.