I'm now counting the pages of the new pdf, and the pdf it shall insert.
newPDF.InsertPages(newPages - 1, currentpdf, 0, currentPages - 1, False)
The code below does exactly the same as the code in my previous post. It creates the pdf but are unable to insert.
I think I understood what you ment, and it makes sense.
Thank you so much for the time you try to help me out.
When I get this code to work, I'll buy you a beer 😁
Dim invapp As Inventor.Application
invapp = GetObject(, "Inventor.Application")
Dim asmDoc As AssemblyDocument
asmDoc = invapp.ActiveDocument
Dim asmpartnum As Inventor.Property = asmDoc.PropertySets("Design Tracking Properties").Item("Part Number")
If System.IO.Directory.Exists(Line(5) & "\Combined " & asmpartnum.Value) Then System.IO.Directory.Delete(Line(5) & "\Combined " & asmpartnum.Value, True)
System.IO.Directory.CreateDirectory(Line(5) & "\Combined " & asmpartnum.Value)
Dim PDFNewName As String
Dim newPDF As Acrobat.CAcroPDDoc
Dim PDFPath As String
Dim newPages As Integer
Dim currentPages As Integer
PDFPath = TextBox1.Text
PDFNewName = PDFPath & "\Combined all files " & asmpartnum.Value & ".pdf"
newPDF = CreateObject(“AcroExch.pdDoc”)
newPDF.Create()
For Each itm In ListBox4.Items
Dim x As Integer = ListBox4.Items.IndexOf(itm)
For Each items In ListBox1.Items
Dim y As Integer = ListBox1.Items.IndexOf(items)
If x = y Then
For Each Doc In asmDoc.AllReferencedDocuments
If Doc.displayname = items Then
Dim drawing As String = Doc.FullFileName
drawing = drawing.Substring(0, drawing.Length - 3)
Dim Drawingdocument As DrawingDocument = invapp.Documents.Open(drawing & "idw", False)
Dim PartnumberProp As Inventor.Property = Doc.PropertySets("Design Tracking Properties").Item("Part Number")
Dim RevisionNumberProp As Inventor.Property = Drawingdocument.PropertySets("Summary Information").Item("Revision Number")
Dim PDFname As String = Trim(PartnumberProp.Value) & "-" & RevisionNumberProp.Value & ".pdf"
Drawingdocument.Close()
Dim sourcePDF As String = Line(4) & "\" & PDFname
Dim destinationPDF As String = Line(5) & "\Combined " & asmpartnum.Value & "\" & PDFname
If System.IO.File.Exists(sourcePDF) Then
newPDF.Open(PDFNewName)
newPages = newPDF.GetNumPages()
Dim currentpdf As Acrobat.CAcroPDDoc
currentpdf = CreateObject(“AcroExch.pdDoc”)
currentpdf.Open(destinationPDF)
currentPages = currentpdf.GetNumPages()
newPDF.InsertPages(newPages - 1, currentpdf, 0, currentPages - 1, False)
currentpdf.Close()
Dim fi As New System.IO.FileInfo(sourcePDF)
fi.CopyTo(destinationPDF)
newPDF.Save(1, PDFNewName)
newPDF.Close()
End If
End If
Next
End If
Next
Next
newPDF = Nothing
MsgBox("Complete")