Vaadin file preview - java

Can anyone support me with the following issue:
I am working with Vaadin and need to develop a code tt will allow the user to preview the file in such formats as pdf, image, video and audio files. All files are stored in database and may be or various possible types. For pdf it is enough to add the following code:
StreamResource resource = file.downloadFileFromDatabase();
Embedded pdf = new Embedded("", resource);
pdf.setMimeType("application/pdf");
pdf.setType(Embedded.TYPE_BROWSER);
pdf.setSizeFull();
pdf.setHeight("310px");
verticalLayout.setSizeFull();
verticalLayout.addComponent(pdf);
verticalLayout.setExpandRatio(pdf, 1.0f);
But this code doesn't work with video and audio files. Do I need to add a sort of if-else statement to arrange preview of file in accordance with its format? Thank u in advance.

Playing videos from vaadin is possible, there exists the Video class for this.
But since it renders a html5 <video> tag, it requires url as video source. In addition to this, you need a browser supporting the video tag, and the specific video encodings your videos have.
This can help for the player elements to control playback:
https://vaadin.com/directory#!addon/mediaelementjs-player
Here some more info for debugging your potential problem:
https://vaadin.com/forum#!/thread/2445276

Related

How to know that provided URL is Image or Video in Android Studio

I am Using Firebase as Database where user can Upload Image or Video so I am Fetching URL from my database so I am getting two URLs one of them can be either video or image so what can I do to detect the URL.
Let Suppose this is the URL.
This is the example URL. NOTE URL can be different
any help will be appreciated
Edited
for better understanding I will providing some example code:
MyUserModel model; //this is the model class where I can get the url in String
String Url = model.getUrl(); //its URL can be video or image
//Can I write something like this:
//does any method like this : isVideo();
// if the url is video then this function will return true else false;
if(isVideo(Url)){
videoView.setVideoPath(Url); //and other stuffs
}else{
Glide.with(context).load(Url).into(ImagView); //something like this.
}
...
NOTE : SOME URLS DON'T HAVE EXTENTIONS LIKE PNG, MP4, JPG ETC. I am saying this because I have a some URLs with no extension related to mp4 or png etc.
I will suggest you to have one column named as "type" and keep 0 for image and 1 for video when you are saving image/video into data base. This way you can recognise the type easily.
You may need to tweak UI little bit. You can provide an option to capture image from UI and launch camera app only to capture image. Similarly provide an option to capture only video. This way you can make sure at front end user is capturing either image or video at a time. Save that type value in firebase db as above.

Extracting media objects present in LibreOffice Impress using LibreOffice APIs

I am trying to get details of the media contents (video, audio ) present in a LibreOffice Impress document through LibreOffice API in java. The details which I want to extract is the type of media content present in the document. And also ways to export them. I have gone through the java examples given on the Website but could not find anything relevant to type of video or audio present in file and extraction of video files. I have gone through the example given for exporting Images from Impress Documents using GraphicExportFilter, but it is not able to export video or audio files present in the document. I also tried to extract the type of media content by using XShape (code below), but it only gives the name of the media content and not its type(audio/video/or media extension).
For exporting I am also aware of the method of converting documents to pptx and then renaming and extracting all types of media files. But I suppose that would consume more time to extract (correct me if I am wrong) in practical application, so I was trying to do the same by LibreOffice API.
XComponent xDrawDoc = Helper.loadDocument( xOfficeContext,fileName, "_blank", 0, pPropValues );
XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc,nPageIndex );
XIndexAccess xIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class,xPage);
long shapeNumber = xIndexAccess.getCount();
for(int j=0;j < shapeNumber;j++)
{
XShape xShape =UnoRuntime.queryInterface(XShape.class, xPage.getByIndex(j));
XNamed xShapeNamed =UnoRuntime.queryInterface(XNamed.class, xShape);
System.out.println(j+":"+xShapeNamed.getName());
}
(This code gives me the names of the media contents present in Impress but not its type or extension)
Thanks in Advance..

GraphicsMagick + im4java, how can I remove color profile (and other redundant data)

I'm using graphicsmagick + im4java for generating thumbnails in my web application. Unfortunately as I can see, while processing pictures taken with photo cameras, the thumbnails contains all original data such color profile, aperture, camera's manufacturer/model etc. In other words much more things than required for displaying just simple thumbnail on the page. Of course it causes large thumbnail's file size. The thumbnail for the same photo which was saved for the web from any graphic editor is much smaller.
How can I get rid of unwanted data with im4java before further processing?
Problem solved, following this GM gist:
mogrify +profile '*' -define jpeg:preserve-settings
I managed the problem in im4java with p_profile(java.lang.String profileName) method:
ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
op.addImage(sourcePath);
op.p_profile("*");
op.scale(123);
op.addImage(targetPath);
cmd.run(op);

Writing text to Image in Google App Engine (Java)

I'm writing code that runs on Google App Engine (Java). What I'm trying to do is augment an existing image by adding text. GAE does not have any text handling in its ImagesService.
Does anyone have any idea?
I'd like my code to look something like this:
...
// Read image
byte[] pageData = readImage("images/page.png");
Image pageImage = ImagesServiceFactory.makeImage(pageData);
// Add text here
...
return pageImage;
If you just need to overlay some simple text you could combine the Google Charts API with the Composite image function in the AppEngine Image API to get the desired result.
First construct a URL and use urlfetch from your app to grab the required text-image via the Charts API like:
URL: http://chart.apis.google.com/chart?chs=300x50&cht=p3&chtt=hello&chts=FFFFFF,24&chf=bg,s,000000
(Note the size, and colour params in this url)
Open your image with the Image API and use Composite with the image you wish to overlay text on.
You can extend the colors on Google charts with alpha values, that way you can have a transparent png that you can overlay on top of another image using the Composite function.
http://chart.apis.google.com/chart?chs=300x50&cht=p3&chtt=hello&chts=000000FF,24&chf=bg,s,00000000

Running a JavaScript command from MATLAB to fetch a PDF file

I'm currently writing some MATLAB code to interact with my company's internal reports database. So far I can access the HTML abstract page using code which looks like this:
import com.mathworks.mde.desk.*;
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.setCurrentLocation(ReportURL(8:end));
pause(1);
s={};
while isempty(s)
s=char(wb.getHtmlText);
pause(.1);
end
desk=MLDesktop.getInstance;
desk.removeClient(wb);
I can extract out various bits of information from the HTML text which ends up in the variable s, however the PDF of the report is accessed via what I believe is a JavaScript command (onClick="gotoFulltext('','[Report Number]')").
Any ideas as to how I execute this JavaScript command and get the contents of the PDF file into a MATLAB variable?
(MATLAB sits on top of Java, so I believe a Java solution would work...)
I think you should take a look at the JavaScript that is being called and see what the final request to the webserver looks like.
You can do this quite easily in Firefox using the FireBug plugin.
https://addons.mozilla.org/en-US/firefox/addon/1843
Once you have found the real server request then you can just request this URL or post to this URL instead of trying to run the JavaScript.
Once you have gotten the correct URL (a la the answer from pjp), your next problem is to "get the contents of the PDF file into a MATLAB variable". Whether or not this is possible may depend on what you mean by "contents"...
If you want to get the raw data in the PDF file, I don't think there is a way currently to do this in MATLAB. The URLREAD function was the first thing I thought of to read content from a URL into a string, but it has this note in the documentation:
s = urlread('url') reads the content
at a URL into the string s. If the
server returns binary data, s will
be unreadable.
Indeed, if you try to read a PDF as in the following example, s contains some text intermingled with mostly garbage:
s = urlread('http://samplepdf.com/sample.pdf');
If you want to get the text from the PDF file, you have some options. First, you can use URLWRITE to save the contents of the URL to a file:
urlwrite('http://samplepdf.com/sample.pdf','temp.pdf');
Then you should be able to use one of two submissions on The MathWorks File Exchange to extract the text from the PDF:
Extract text from a PDF document by Dimitri Shvorob
PDF Reader by Tom Gaudette
If you simply want to view the PDF, you can just open it in Adobe Acrobat with the OPEN function:
open('temp.pdf');
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.executeScript('javascript:alert(''Some code from a link'')');
desk=com.mathworks.mde.desk.MLDesktop.getInstance;
desk.removeClient(wb);

Categories

Resources