5 Replies Latest reply on Aug 26, 2015 1:50 PM by Rajendra Vedaraju

    Watermark in PDF using Solidworks API

    Rajendra Vedaraju

      Hi all,


      I am generating PDF's using ModelDocExtension::SaveAs API call but I found no option for creating watermark.

      I can insert the Watermark in my Drawing Template for future Drawings but I need to generate it on the fly for existing Drawings.

      I am trying to insert the Note as watermark using API but no success so far. Following are the steps I am trying to automate:


      1. Right click on Drawing -->Edit Sheet Format

      2. Insert Note

      3. Right click on Note and select "Display text behind Drawing"

      4. Finish the command


      While I keep trying, I was curious to know if anyone tried and had success on this?

      Thanks in advance.

        • Re: Watermark in PDF using Solidworks API
          Agostino Cavallotto

          In what step you stop?




          • Re: Watermark in PDF using Solidworks API
            Rajendra Vedaraju

            Thanks Karim. Here is my method on what I am trying to achieve.

            I have to open each sheet and created watermark. Then I have to create a PDF.

            Issue is that, PDF does not show the watermark on all sheets, though the watermark gets created successfully on each sheet.

            Appreciate any clues on this.


            Public Sub CreateWatermarkNote()



                    Dim swModel As ModelDoc2

                    Dim swModelDocExt As ModelDocExtension

                    Dim swDrawing As DrawingDoc

                    'Dim swDrawing As IDrawingDoc()

                    Dim swSelectionMgr As SelectionMgr

                    Dim swNote As Note

                    Dim fileName As String

                    Dim status As Boolean

                    Dim errors As Integer

                    Dim warnings As Integer

                    Dim swApp As Object

                    Dim swTextFormat As ITextFormat

                    Dim swAnnot As IAnnotation

                    Dim vSheetNames As Object

                    Dim currentsheet As Sheet

                    Dim swPDFExport As ExportPdfData

                    Dim swExtension As ModelDocExtension

                    'swApp = New SldWorks.SldWorks()






                        swApp = CreateObject("SldWorks.Application")

                        swApp.Visible = True

                        swModel = swApp.ActiveDoc

                        swDrawing = swModel

                        swExtension = swModel.Extension


                          'Get all sheets

                        vSheetNames = swDrawing.GetSheetNames


                      'Open each sheet and crate watermark

                        For Each sheet In vSheetNames

                            Console.WriteLine("Creating Watermark for Sheet: " + sheet)





                            swNote = swDrawing.CreateText2("", 0.1, 0.1, 0, 0.01, 0.785)

                            swNote.BehindSheet = True

                            swNote.PropertyLinkedText = "<FONT color=0x00C0C0C0><FONT>FOR QUOTE ONLY"




                           'Create PDF

                        Dim objs() As Object

                        Dim count As Integer

                        count = UBound(vSheetNames)

                        ReDim objs(count)


                        swPDFExport = swApp.GetExportFileData(swExportDataFileType_e.swExportPdfData)

                        swPDFExport.SetSheets(swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, objs)



                        ' Convert the document to PDF

                        Dim convFileName As String = "c:\temp\1.pdf"



                        swExtension.SaveAs(convFileName, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, swPDFExport, errors, warnings)


                        End Sub