r/visualbasic • u/Chriand VB.Net Intermediate • Oct 27 '20
Adobe Acrobat combine several PDFs
Hello, I have a code that creates PDFs off all items listed in a listbox.
Now I want these newly created PDFs to be combined into one. I've searched around the web and can't seem to find a example I can write to my own, so I'm asking you for some help.
Dim Acroapp As Acrobat.CAcroApp = CreateObject("AcroExch.App")
Dim files(ListBox4.Items.Count) As String
Dim Path As String = TextBox1.Text
If Not System.IO.Directory.Exists(Path) Then IO.Directory.CreateDirectory(Path)
Dim invapp As Inventor.Application
invapp = GetObject(, "Inventor.Application")
For Each itm In ListBox4.Items
Dim x As Integer = ListBox4.Items.IndexOf(itm)
invapp.Documents.Open(itm.ToString & "idw", True)
invapp.ActiveDocument.SaveAs(Path & "\" & itm.ToString & ".pdf", True)
files(x) = Path & "\" & items.ToString & ".pdf"
invapp.ActiveDocument.Close()
Next
'Acroapp.saveas(files(), Path & "\CombinedFile.pdf") 'This is the step I can't any examples of.
MsgBox("Completed")(Tried to clean up the code to only show relevant info, so there might be some errors)
Thanks for any help!
Bonus: If its possible to skip creating the single PDFs before combining, that would be great.
2
u/EveryoneLikesMe VB.Net Advanced Oct 27 '20
I use PDFSharp for this. It is free. Feed it a list of file paths as strings, and set the filepath for output and it'll give you a combined PDF.
If you need help with the syntax, I can convert some of my C# code to work in VB. It's rather straight forward though.
1
u/Chriand VB.Net Intermediate Oct 27 '20
Thank you. If I can’t find a solution with Adobe, I might have to ask you later for the C# code.
1
u/Chriand VB.Net Intermediate Oct 28 '20
I have a issue with referencing pdfsharp in my project. The download doesn't contain any .dll files I can reference.
Do you remember how you did it?
2
u/EveryoneLikesMe VB.Net Advanced Oct 28 '20
I did it via NuGet package manager in Visual Studio. Assuming you're also using VS...
Tools>NuGet Package Manager>Manage NuGet Packages For Solution...
In dialog box, search PDFsharp. Install to project. Should add the references automagically.
If not, let me know and I'll get you an alternative
1
u/Chriand VB.Net Intermediate Oct 28 '20
How will this affect others using my .dll? They would also have to download PDFSharp?
Context: I'm creating a add-in for Inventor that my coworker will also use.
1
u/EveryoneLikesMe VB.Net Advanced Oct 28 '20
It will be compiled in to the final binary and redistributed with your package. To the end user, it's seamless.
3
u/andrewsmd87 Web Specialist Oct 27 '20
I haven't done a ton of work with pdfs and VB, but I don't know what Acroapp is. Is that something you downloaded? AFAIK the best free thing to use for creating pdfs programmatically is ITextSharp. But it's been years since I've used it