Forum Discussion

ykrrishna's avatar
ykrrishna
Occasional Contributor
8 years ago
Solved

Does JavaBridge in testComplete work on a Python Project ?

I am working on a project to test the contents of a pdf file.

 

I was suggested with this URL in my previous question "https://support.smartbear.com/articles/testcomplete/testing-pdf-files-with-testcomplete/#Preparation".

 

Now when I tried it following the steps I got an error stating this

"RuntimeError

java.lang.IllegalArgumentException: argument type mismatch"
 
In this particular code step
 
docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(path)
 
Under path I have given the entire path of the file like D:\somepath\filename.pdf
 
Also, I have tried with the following
docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3("D:\somepath\filename.pdf")
docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3("D:\\somepath\\filename.pdf")
 
Need advice
  • That article was created for PDFBox version 1.8.6. The current version is 2.0.4 and it appears to have introduced some breaking changes. For example, PDDocument.load no longer accepts file names and requires a java.io.File object instead. So you need to use something like:

    file = JavaClasses.java_io.File.newInstance("C:\\MyFile.pdf")
    docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_2(file)

    AlexKaras posted some more tips in another thread, check the first link in his answer.

     

    Also, the PDFBox API docs are the source of truth for parameter types, supported methods, etc.

4 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    That article was created for PDFBox version 1.8.6. The current version is 2.0.4 and it appears to have introduced some breaking changes. For example, PDDocument.load no longer accepts file names and requires a java.io.File object instead. So you need to use something like:

    file = JavaClasses.java_io.File.newInstance("C:\\MyFile.pdf")
    docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_2(file)

    AlexKaras posted some more tips in another thread, check the first link in his answer.

     

    Also, the PDFBox API docs are the source of truth for parameter types, supported methods, etc.

    • ykrrishna's avatar
      ykrrishna
      Occasional Contributor

      HKosovaThanks for the link and the trick. It worked well ! , with a little more tweaking.

       

      AlexKarasI was actually working on the latest version 2.0.4. Your answer from the other chain helped me a lot. Thanks !

       

      tristaanogreI missed out checking load_2 and 1  as you said. That was so lame of me, as said always "Continuous Learning" isn't ? :P  Thanks for pointing it out !

       

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    As the article notes, the "load" function is overloaded so it generates load, load_2, and load_3.  But I'm not 100% certain that load_3 is the method for passing in the filename string.  As per the article, use CodeCompletion to make sure that load_3 is the method you want.  It SOUNDS like you're passing a string and the load_3 method is expecting something different like a stream.

    JUST out of curiousity, have you tried changing load_3 to load_2 and seeing if it works?