External Java Code

I would like to add some Java code to my solution. Below is the pure java code. I added the three necessary jar to /applcation_server/lib folder. I have tried adding and not adding the jars to my startup script class path.

http://webcam-capture.sarxos.pl/ Link to developers site.

Jars
bridj-0.7-20130703.103049-42.jar
webcam-capture-0.3.10-RC4.jar
slf4j-api-1.7.2.jar

    Webcam webcam = Webcam.getDefault();
    webcam.open();
    BufferedImage image = webcam.getImage();
    ImageIO.write(image, "PNG", new File("test.png"));

I get lost here as you can see below in defining the class.

var webcam = new java.webcam???

Hi,

I am not sure if you can access external jar files by placing them in lib folder, but as far as i know we can access methods of external JARs by placing them in the application_server/plugins or application_server/beans folder(which will be shipped for smart client directly).

Then we need to access the method by specifying the full hierarchy from package to class to the methods name, e.g:

var webcam = new Packages.com. ... .Webcam.getDefault();

You can find more discussion Accessing methods in an external JAR.

Thanks,
Sovan

Hi

We recently built a webcam bean around the sarxos library which will be going up to servoyforge in the coming weeks.
In the mean time I can either send you the source and or the compiled bean jar file.

If this is of use please pm me.

Thanks for all your help. Moved the jars to bean folder and with the code below I have a basic webcam capture function. Please forgive me for my ignorance with embedding java in servoy.

  var webcam = new Packages.com.github.sarxos.webcam.Webcam.getDefault();

  webcam.setViewSize(new Packages.java.awt.Dimension(640,480));
  
  webcam.open();
  
  new Packages.javax.imageio.ImageIO.write(webcam.getImage(),'JPG',new Packages.java.io.File('C:\\webcam1.jpg'));
  
  webcam.close();

What I need the ability to click a button have a webcam preview displayed. Then be able to take a still image and send it to a specific server location.

Hopefully Mccourt.cordingley1372837951’s webcam bean will solve all my problems. :D

Did you try the scanner Pro plugin? https://www.servoyforge.net/projects/scannerpro/wiki
(can access webcams also)

Yes, i tried scanner pro. Didn’t have any success with our webcams and dealing with twain drivers.

Hi

Sorry for the late response. We have been away with cluents all of last week.
The cam bean does have a review functionality and it seaks to non twain devives also.
I will send you tbe bean and source this afternoon.r

Regards

Hi

Sorry for the late response. We have been away with cluents all of last week.
The cam bean does have a review functionality and it seaks to non twain devives also.
I will send you tbe bean and source this afternoon.r

Regards

Hello,
we whould like to test the webcam bean, too. Is it now available for download?

briese-it:
Hello,
we whould like to test the webcam bean, too. Is it now available for download?

This bean is a project on ServoyForge, but the project leader (in this case McCourt) hasn’t made the project public (yet).
As he said in the previous post in this thread he will be making it available in the coming weeks.

Edit: I now see that his promise to publish is it from last november, so yes…when will it be published ? :)
McCourt ?

I have ran into another situation where I would like to use external java code. I have attempted to create a plugin for pdfbox with no success . I have switched gears and now I am attempting to access the java directly in servoy. I am using the pdfbox.jar to extract text from PDF’s. I have already placed the pdfbox.jar in the beans folder. Below is what I got so far:

var pdfbox = Packages.org.apache.pdfbox; //code works
pdfbox.ExtractText ???? this is where I run into issues can't get this to work.

Also, I can run this successfully from cli:

java -jar pdfbox.jar ExtractText C:\test.pdf C:\test.txt

Any help would be appreciated with the java code or creating the plugin (I have tried the tutorials on creating the plugin)

Hi,

I’ve been playing around with pdfbox a while ago.
Came up with this oneliner to convert pdf to images:

org.apache.pdfbox.PDFToImage.main(["-outputPrefix",_sPath + "page_","-resolution",96,"-nonSeq",_jsFile.getAbsolutePath()])

So I guess you should use something like

org.apache.pdfbox.ExtractText.main(["C:/test.pdf","C:/test.txt"])

There’s some more options like encoding.
This should be passed in the array, in front of the to current arguments.

org.apache.pdfbox.ExtractText.main(["-encoding","UTF-8","C:/test.pdf","C:/test.txt"])

Hope this helps.

The first bit of code calls the jar file from command line through servoy. This works, however I would like to call java or create a plugin for this as in the second example. The code will work in the second code example, but generates an empty text file.
#code segment 1

function Pdf()
{
	var file = plugins.file.showFileOpenDialog(1,'C:/pdf',false,null,null,'PDF')
	if(!file)return;
	file = plugins.file.convertToJSFile(file);
	if(!file.exists())return;
 
    var name = 'pdf';
    var temp = plugins.file.createTempFile('pdf','.bat');

    plugins.file.writeTXTFile(temp,'java -jar P:\\servoy\\pdfbox-app-1.8.5.jar ExtractText '+file.getPath());
    application.executeProgram(temp);
}

#code segment 2

function Pdf()
{
	var file = plugins.file.showFileOpenDialog(1,'C:/pdf',false,null,null,'PDF')
	if(!file)return;
	file = plugins.file.convertToJSFile(file);
	if(!file.exists())return;

   Packages.org.apache.pdfbox.ExtractText.main([file.getAbsolutePath(),'C:/pdf/text.txt']);
}

Hi,

tried this (on MacOSX), this works for me:

function Pdf() {
	var file = plugins.file.showFileOpenDialog(1,'C:/pdf',false,null,null,'PDF')
	   if(!file)return;
	   if(!file.exists())return;

	   Packages.org.apache.pdfbox.ExtractText.main(["-encoding","UTF-8",file.getAbsolutePath(),'C:/pdf/text.txt']);
}

I’ve replaced the paths again to the ones from your example

Thanks for all your help. For some reason I can’t get this code to convert the pdf to txt. Sometimes the code creates an empty text file while at other it throws the following error:
Wrapped org.apache.pdfbox.exceptions.WrappedIOException. This is strange because running pdfbox from the command line extracts the same pdfs to text every time.

I am runing Java 1.6
Servoy 5.2.16
pdfbox-app-1.8.5.jar (jar file is placed in application_server\beans)