Exporting Embedded PDF

Programming and macros
JeromeP
Posts: 12
Joined: Wed Mar 24, 2021 12:40 pm
Answers: 0
x 1
x 2

Exporting Embedded PDF

Unread post by JeromeP »

Hello everyone,
I'm trying to automate the export of the embedded files (PDF and Office) from the design binder of a part,
I could open the files and save them but it's unreliable.
So I tried to write the buffer to a file, but there is some extra data that makes it unreadable.
Does someone know the encoding or serialization used for this buffer?

Code: Select all

    Const swCommands_Activate_Doc_Or_Journal As Integer = 2059

    Private Sub ExtractOLE()
        Dim swApp As SldWorks
        swApp = GetObject(, "SldWorks.Application")
        Dim swModel As ModelDoc2
        swModel = swApp.ActiveDoc

        Dim vOleObjs As Object 
        vOleObjs= swModel.Extension.GetOLEObjects(0)

        Dim i As Integer
        For Each swOleObj As SwOLEObject In vOleObjs
            i += 1
            'Console.WriteLine("  Filename: " & swOleObj.FileName & "  Is linked? " & swOleObj.IsLinked)
            'Console.WriteLine("  Buffer size: " & swOleObj.BufferSize)

            'open the file
            'swOleObj.Select(False)
            'swModel.Extension.RunCommand(swCommands_Activate_Doc_Or_Journal, "")
            
            'Extract the file
            Dim OleData As Byte()
            OleData = swOleObj.Buffer
            File.WriteAllBytes("C:\temp\test" & i & ".pdf", OleData)
        Next
End Sub
User avatar
AlexB
Posts: 493
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 27
x 265
x 440

Re: Exporting Embedded PDF

Unread post by AlexB »

I don't know if this helps, but I'm assuming this approach will get rather technical since the only information I can find regarding the file format is linked below. I haven't worked with anything like this before but this is where I'd start.

https://docs.microsoft.com/en-us/opensp ... 701c5fbb6f
JeromeP
Posts: 12
Joined: Wed Mar 24, 2021 12:40 pm
Answers: 0
x 1
x 2

Re: Exporting Embedded PDF

Unread post by JeromeP »

The encoding format is "Microsoft Compound Document File"
I manage to adapt a library that open them
https://github.com/ironfede/openmcdf
It's a bit dirty at this time but it works
User avatar
bnemec
Posts: 1941
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2540
x 1398

Re: Exporting Embedded PDF

Unread post by bnemec »

JeromeP wrote: Thu May 26, 2022 10:58 am The encoding format is "Microsoft Compound Document File"
I manage to adapt a library that open them
https://github.com/ironfede/openmcdf
It's a bit dirty at this time but it works
I used that library (nuget package) a few years ago with good results. The owner is active and responds to the mailing list. IMO it's a great tool. I like that it's simple and doesn't have a ton of other dependencies. Although I did not use it in the same way you are. I used it to parse/dissect Solid Edge CAD files to get properties and file references without using the Design/Revision manager API which starts a DesignMgr process that needs a license.

Anyway, if you need to dig around in a compound file I would say that's a good library to use. For viewers I used both the Example (Structured Storage Explorer) in ironfede's repo as well as a tool called SS Viewer (structured storage viewer) from Mitec. It almost feels like Mitec cloned the Explorer from ironfede's repo.
Post Reply