Steve Anderson

CreatePDF2 API is not generating the same PDF as the drawing

Discussion created by Steve Anderson on Jul 22, 2020

This link is the recommended logic for saving PDF files:  http://help.solidworks.com/2019/english/api/sldworksapi/Save_File_as_PDF_Example_VBNET.htm?verRedirect=1

 

The frustration is that it just is not creating the correct PDF file.  We are getting latest on the drawing as well as the related model (part or assembly) prior to calling this sub. 

 

I have attached two files, and you can see the PDF does not match the SolidWorks Drawing (represented by JPG in attachment).

 

Below is the code:

    Private Sub SavePDF2(ByVal _pdffile As String, _swModel As ModelDoc2)

        ' Dim swDraw As DrawingDoc = _swModel

        ' swDraw.saveas(_pdffile)

 

        ' This method skips files!

        Dim swApp2 As New SldWorks

        swApp2 = SWAPP

 

        Dim swModelExt As ModelDocExtension = _swModel.Extension

        Dim swExportPDFData As ExportPdfData = swApp2.GetExportFileData(swExportDataFileType_e.swExportPdfData)

        Dim swDrawDoc As DrawingDoc = _swModel

        Dim swSheets As Object = swDrawDoc.GetSheetNames

        Dim swSheetList As New List(Of Sheet)

        Dim WrapperList As New List(Of Object)

        Dim swSheets2 As Object

 

        Dim count As Integer = UBound(swSheets)

        ReDim swSheets2(count)

 

        ' Dim arrObjIn(count) As System.Runtime.InteropServices.DispatchWrapper

 

        Dim boolstatus As Boolean

        For i As Integer = 0 To count - 1

            boolstatus = swDrawDoc.ActivateSheet(swSheets(i))

            Dim swSheet As Sheet = swDrawDoc.GetCurrentSheet

            swSheetList.Add(swSheet)

 

            ' WrapperList.Add(New System.Runtime.InteropServices.DispatchWrapper(swSheet))

 

            ' arrObjIn(i) = New System.Runtime.InteropServices.DispatchWrapper(swSheets2(i))

 

        Next i

 

        Dim errors As Integer

        Dim warnings As Integer

        boolstatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, swSheetList.ToArray)

 

        ' ' Save the drawings sheets to a PDF file

        ' boolstatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, (arrObjIn))

        ' boolstatus = swExportPDFData.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, WrapperList.ToArray)

 

        swExportPDFData.ViewPdfAfterSaving = False

 

        ' boolstatus = swModelExt.SaveAs(_pdffile, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, swExportPDFData, errors, warnings)

        boolstatus = swModelExt.SaveAs2(_pdffile, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, swExportPDFData, 0, 0, errors, warnings)

 

    End Sub

 

Much thanks for any help you can provide!

Attachments

Outcomes