Combining PDFs Using Adobe Acrobat

Combining PDFs Using Adobe Acrobat

Abby_Baratta
Enthusiast Enthusiast
902 Views
3 Replies
Message 1 of 4

Combining PDFs Using Adobe Acrobat

Abby_Baratta
Enthusiast
Enthusiast

Hello!

 

I've recently been updating some code that was originally written for AutoCAD 2004 to get it to run on AutoCAD 2021 and I've been running into some issues while trying to combine three PDFs using Adobe Acrobat.

 

The code was written to make three separate drawings, print them to PDF, add their locations to a list, and then use that list to combine them into a singular PDF.

 

The code is as follows:

  FileCopy PDFpage(1), FinalPDF
  
  Kill PDFpage(1)
       
  If pages > 1 Then
     Dim b As Boolean
     Dim AcroPDDoc As Acrobat.CAcroPDDoc
     Dim PDDoc As Acrobat.CAcroPDDoc
     Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
     b = AcroPDDoc.Open(FinalPDF)
     For i = 2 To 3
         Set PDDoc = CreateObject("AcroExch.PDDoc")
         b = PDDoc.Open(PDFpage(i))
         b = AcroPDDoc.InsertPages(i - 2, PDDoc, 0, 1, False)
         Sleep (500)
         'b = AcroPDDoc.Save(1, FinalPDF)
         b = AcroPDDoc.Save(PDSaveFull, FinalPDF)
         PDDoc.Close
         Set PDDoc = Nothing
         Sleep (500)
         Kill PDFpage(i)
     Next i
     AcroPDDoc.Close
     Set AcroPDDoc = Nothing
  End If

Final PDF is the name of the file that I want to add the remaining two pages to. 

 

From my understanding, this code is using the first entry of the list as the FinalPDF base file, then adding the second entry as first page and the third entry as the middle page, bumping the first list entry to the last page of the PDF.

 

Since everything has a boolean output, I've been able to see that lines 13 and 14 are setting b to True. The line that it has been throwing False at me is the AcroPDDoc.Save line (line 17). The original code had a 1 as the first entry, so I changed it to PDSaveFull, but that did not fix my problem.

 

I would appreciate any feedback or suggestions!

 

0 Likes
903 Views
3 Replies
Replies (3)
Message 2 of 4

Ed__Jobe
Mentor
Mentor

Before we spend a lot of time on this, do you realize that the PUBLISH command can do this and you don't need that old code?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 4

Abby_Baratta
Enthusiast
Enthusiast

I guess I didn't realize that PUBLISH would print all the open drawings to PDF - I'm not really an expert with AutoCAD, so I'm trying to learn the ins and outs of it while I'm fixing all this code. I know that for other bits of code that I've fixed, I've used AUTOPUBLISH to print to PDF all the tabs of a drawing. 

 

I haven't used a SendCommand with PUBLISH before, but I'll go peruse the internet to see if I can find an example to go off of. 

0 Likes
Message 4 of 4

Abby_Baratta
Enthusiast
Enthusiast

So I've got the code working to open up all my necessary drawings and use the PUBLISH command, but I'm struggling with the sheet set portion of it. I know that I need one in order to use the PUBLISH command to automatically run from a VBA script, but I'm unsure on how to go about doing that.

 

I found some stuff online about AcSm Components, but I've been unsuccessful in using them. So far, this is what I've got:

Dim OrdDraw As String
Dim CoreDraw As String
Dim ChkDraw As String
Dim SSM As AcSmSheetSetMgr
Dim oDB As AcSmDatabase

    OrdDraw = Order_dir & DwgName & "_Set.dwg"
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.Application.Documents.Open OrdDraw
    
    ThisDrawing.SendCommand "SDI 0 "
    
    CoreDraw = Order_dir & DwgName & "_Core.dwg"
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.Application.Documents.Open CoreDraw
    
    ChkDraw = Order_dir & DwgName & "_ChkList.dwg"
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.Application.Documents.Open ChkDraw
    
    'use the publish command
    Set SMM = GetObject("", "AcSmComponents.AcSmSheetSetMgr")
    Set oDB = SMM.CreateDatabase("C:\Autopoll_SC\temp\TESTSS.dst", "", True)
    
    ThisDrawing.SendCommand "PUBLISH C:\Autopoll_SC\temp\TESTSS.dst "
    
    'close the drawings
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.Application.ActiveDocument.Close
    
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.Application.ActiveDocument.Close
    
    ThisDrawing.SendCommand "SDI 1 "
    If Not (ThisDrawing.Saved) Then ThisDrawing.Save
    ThisDrawing.New ("acad.dwt")

 

I would really appreciate any help or feedback on the code!

 

0 Likes