I just did a Google Search:
iText7 merge 2 PDF - Google[
^] and found this:
Is it possible to merge several pdfs using iText7 - StackOverflow[
^].
The solution given is from the itextpdf java example. Here is the .Net version:
iText: Jump-Start Tutorial for .NET[
^]. There is this section that explicitly explains what you are trying to do (using C#):
Chapter 6: Reusing existing PDF documents | .NET - section: Merging documents with PdfMerger[
^]
Here is the code from that page (and yes, it looks the same as what you have posted, but keep reading):
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfMerger merger = new PdfMerger(pdf);
PdfDocument firstSourcePdf = new PdfDocument(new PdfReader(SRC1));
merger.Merge(firstSourcePdf, 1, firstSourcePdf.GetNumberOfPages());
PdfDocument secondSourcePdf = new PdfDocument(new PdfReader(SRC2));
merger.Merge(secondSourcePdf, 1, secondSourcePdf.GetNumberOfPages());
firstSourcePdf.Close();
secondSourcePdf.Close();
pdf.Close();
Looks pretty straight forward to me. However, it's not in Vb. That is easily fixed by using
ChatGPT[
^]. Here is how I would ask
ChatGPT[
^] to translate the code for me:
Convert the following code from C# to VB.Net:
[paste code here]
The output has both an explanation and code. Here is the code generated from the above query:
Dim pdf As New PdfDocument(New PdfWriter(dest))
Dim merger As New PdfMerger(pdf)
Dim firstSourcePdf As New PdfDocument(New PdfReader(SRC1))
merger.Merge(firstSourcePdf, 1, firstSourcePdf.GetNumberOfPages())
Dim secondSourcePdf As New PdfDocument(New PdfReader(SRC2))
merger.Merge(secondSourcePdf, 1, secondSourcePdf.GetNumberOfPages())
firstSourcePdf.Close()
secondSourcePdf.Close()
pdf.Close()
If you're not happy with that solution, there are others in that StackOverflow link + others in the Google Search above.
If you find C# solutions, you now know how to easily convert to VB.Net. A warning though... ChatGPT is not always accurate, so you may need to do a little work to debug and complete the conversions.
Lastly, I suggest to create a prototyping console application to test any solution
BEFORE adding to your main project. This will help to focus in on the part you are trying to implement and remove the distractions of merging into your application. It's quick and clean. Once you have it working, then focus on adding it to your main project. Quarantine, evaluate/test, then implement.