0

I tried to merge two pdf using SelectPdf library. I used Vb.Net as language.It gave me an error like this

System.InvalidCastException: 'Conversion from string ""D:\PDF\1.pdf" to type 'Integer' is not valid.'

I did all the things after reading their references. Please help me to solve this problem.

 Public Sub MergePDF()
        
        Dim file1 As String = "D:\PDF\1.pdf"
        Dim file2 As String = "D:\PDF\2.pdf"

        ' load the 2 pdf documents
        Dim doc1 As New PdfDocument(file1)  //error generate here
        Dim doc2 As New PdfDocument(file2)

        ' create a new pdf document
        Dim doc As New PdfDocument()

        ' add the pages of those 2 documents to the new document
        doc.Append(doc1)
        doc.Append(doc2)

        ' save pdf document
        doc.Save(Response, False, "Sample.pdf")

        ' close pdf document
        doc.Close()

        ' close the original pdf documents
        doc1.Close()
        doc2.Close()
       
    End Sub
delma wax
  • 13
  • 2
  • The error suggests that the constructor is expecting an integer as opposed to a string/filepath – Anu6is Dec 29 '22 at 11:33
  • [https://selectpdf.com/demo-vb/pdf-merge.aspx] – delma wax Dec 29 '22 at 11:37
  • Got it but they used string for the constructor. – delma wax Dec 29 '22 at 11:38
  • The documentation shows that the [Constructor of that class](https://selectpdf.com/html-to-pdf/docs/html/M_SelectPdf_PdfDocument__ctor_1.htm) has just one overload, which expects an Enumerator (hence an integer value), which defines the type of PDF. The example is most probably wrong, find another – Jimi Dec 29 '22 at 11:52
  • You may need to confirm which dlls you have installed. While [this](https://selectpdf.com/docs/T_SelectPdf_PdfDocument.htm) appears to have multiple overloads, as Jimi points out [this](https://selectpdf.com/html-to-pdf/docs/html/T_SelectPdf_PdfDocument.htm#!) isn't as flexible. – Anu6is Dec 29 '22 at 12:02
  • I used 20.2.0.0. but actually, it does not contain multiple constructors like [this](https://selectpdf.com/docs/T_SelectPdf_PdfDocument.htm) – delma wax Dec 29 '22 at 12:27
  • As @Anu6is pointed out, it's the assembly that you're referencing that counts. My comments suggests that you're using `Select.HtmlToPdf.dll` instead of `Select.Pdf.dll`. Not sure whether you have downloaded the trial, community or paid version of the library and what's available. The free version has many limitations. You can always move to IText7 – Jimi Dec 29 '22 at 13:58
  • Thank you all. I used another library and did. – delma wax Dec 30 '22 at 06:20
  • Questions should not be left unanswered. If you have solved your issue, please add your own answer and accept it, so everyone can see that the question has been answered without reading the comments. – jmcilhinney Dec 31 '22 at 04:55

0 Answers0