Groupdocs supported file detection

Hi, I would like to know what’s the supported file detection for groupdocs libraries ?


We’re using viewer for java to preview supported formats, and Apache Tika to detect mimetype. Based on this page, we created a list of supported mimetypes to allow file preview. For AI extension (adobe illustrator format) we get PDF mimetype, but the viewer library gives us com.groupdocs.viewer.exception.FileTypeNotSupportedException: FileTypeNotSupportedException when trying to preview file.
If we change file extension to .pdf though, it works correctly for instance with the sample files I attach. I remember that the previous viewer version worked with files even without extension, but now it doesn’t work.

In this case we’ll have to drop mimetype detection and use file extension to allow previews in our app, which is not what we’d like.

Hi Fdariasm,


Thanks for taking interest in GroupDocs.Viewer for Java and posting your query.
Can you please tell us, which version of the API (GroupDocs.Viewer for Java) you are integrating in your project?

Many Thanks

Hi, thanks for answering. I’m using version 3.x both for viewer and conversion.

Hi Fdariasm,


Thanks for answering the question.
We have logged your scenario in our internal issue tracking system.
Can you please share your project/source code for investigation, we would certainly appreciate your cooperation?

Many Thanks

Hi. I mean try previewing (with viewer library) a .pdf with changed extension (to .ai for instance). It will throw an unsupported file exception. I’m using something like this for mimetype detection with tika (Scala code):


def getMimetype(fis: FileInputStream, name: String): String = {
val config = TikaConfig.getDefaultConfig
val detector = config.getDetector
val stream = TikaInputStream.get(fis)
val metadata = new Metadata()
metadata.add(TikaMetadataKeys.RESOURCE_NAME_KEY, name)
val mediaType = detector.detect(stream, metadata)
val mimeType = mediaType.toString
  mimeType
}


Hi Fdariasm,


Thanks for providing the code snippet. We shall investigate your issue/scenario and get back to you with the outcomes.

Have a nice weekend ahead.
Best Wishes

Hi Fdariasm,


Let me share a solution with you. It is possible to view document and detect its format by mimetype when you are viewing document from URI or detecting document format from stream.
Please try the code given below also find the attached output file.

// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.getConfiguration();
// Create image or html handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
FileInputStream fileStream = new FileInputStream(“D:\GitRepos\GroupDocs.Viewer-for-Java\Examples\GroupDocs.Viewer.Examples.Java\Data\Storage\document.ai”);
// Or get pages from stream only
List pagesFromStream = imageHandler.getPages(fileStream);
for (PageImage page : pagesFromStream) {
Utilities.saveAsImage(page.getPageNumber() + “_” + “output”, “png”, page.getStream());
}

Keen to hear from you.

Kind Regards

Hi atirtahir3, thanks for answering. That’s great, but how can I get DocumentInfoContainer object using InputStream with ViewerImageHandler? I have something like this:


<pre style=“background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9.6pt;”>val _imageHandler: ViewerImageHandler = new ViewerImageHandler(imageConfig, new CustomDataHandler());

val docInfo = _imageHandler.getDocumentInfo(new DocumentInfoOptions(fileName))
var maxWidth = 0
var maxHeight = 0

for (pageData <- docInfo.getPages.asScala) {
if (pageData.getHeight() > maxHeight) {
maxHeight = pageData.getHeight()
maxWidth = pageData.getWidth()
}
}
val fileData = new FileData();
fileData.setDateCreated(new Date());
fileData.setDateModified(docInfo.getLastModificationDate());
fileData.setPageCount(docInfo.getPages().size());
fileData.setPages(docInfo.getPages());
fileData.setMaxWidth(maxWidth)
fileData.setMaxHeight(maxHeight)<pre style=“background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9.6pt;”>…
AFAIK ViewerImageHandler will need to read document to get information like page numbers, last modification date, page height, etc. I don’t see a similar method using InputStream.

We’re basically using the code here adapted for Scala. You can check, for instance, method GetImageUrlsResponse in line 297 to get what I mean.

Cheers.
David

Hi Fdariasm,


Thanks for sharing your experience.
Yes, apparently it seems that DocumentInfoOptions takes only String not InputStream. So, let us investigate this issue a bit more and then we shall certainly inform you about the outcomes. Please stay tuned.

Best Wishes

Hi Fdariasm,


how can I get DocumentInfoContainer object using InputStream with ViewerImageHandler?

We investigated this issue and contacted the concerned team, you cannot do this in the current version of the API. But the good news is, upcoming release of the API will support get DocumentInfoContainer object.
We cannot share any ETA about the release at the moment. However, as we get any update from the concerned team, we shall surely notify you.

I’m also getting this exception with .ps files:
Thanks for sharing the supported files. We shall investigate this issue and share outcomes with you. Please stay tuned.

Kind Regards

Hi, I’m also getting this exception with .ps files:


Caused by: com.groupdocs.viewer.internal.c.a.ms.a.Z: Unable to determine file type from a stream. Please try to specify filename with extension explicitly.

I attach file in question.

Thanks.

Hi Fdariasm,


exception with .ps files
We are able to reproduce this issue at our end as well. But if you pass guid with filename and exact extension to imageHandler.getPages(), you will not face this issue.
Furthermore, we would like to tell you that this issue will be resolved in the upcoming release of the API. As we get any news about the release date, we shall share it with you.

Have a nice weekend ahead.
Many Thanks

Hi Fdariasm,


We would like to update you that GroupDocs.Viewer for Java 3.7.0 is on-board. We would suggest you to download and integrate the latest version of the API in your application in order to avoid the issue you were facing earlier and share your valuable experience.
Keen to hear from you.

Kind regards

Hi, that’s great.


Is it the same API? are there any breaking changes? where can I find updated documentation or samples.

Thanks!

Hi Fdariasm,


Yes, it is the same API with an updated Version that contains a lot of bug fixes and improvements that were reported in older version of the API.
We would like to apprise you that you need to just replace this latest version of the API with the older one in your project. So, you can continue with your existing project. Download the API from here.

You may find following resources helpful:
Example Project - GitHub Source Code
API Documentation - GroupDocs.Viewer for Java Wiki

However, let me share the specific code and output file (output of pp.pps) for your ease.

try {
// Setup GroupDocs.Viewer config
ViewerConfig config = new ViewerConfig();
config.setStoragePath(“C:\storage”);
// Create image or html handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
FileInputStream fileStream = new FileInputStream(“C:\storage\pp.pps”);
List pagesFromStream = imageHandler.getPages(fileStream);
for (PageImage page : pagesFromStream) {
Utilities.saveAsImage(page.getPageNumber() + “_” + fileName, “png”, page.getStream());
}
} catch (Exception exp) {
System.out.println("Exception: " + exp.getMessage());
exp.printStackTrace();
}

We hope you will not face such issue again.

Have a nice weekend ahead.
Kind Regards

Hi Atir,


I’ve made the library upgrade and now I’m getting this warning during compile time:

[warn] … method getDocumentInfo in class ViewerHandler is deprecated: see corresponding Javadoc for more information.
What is the recommended way now? do you have Javadoc for the library or an example with the no deprecated method ?

Also, I can’t reproduce consistently but sometimes I’m not getting the first page of a document on the preview. I’ll further explore this, but if you heard anything about it and know what can be the issue please let me know.

Hi Fdariasm,


[warn] … method getDocumentInfo in class ViewerHandler is deprecated
Can you please provide us the code snippet? We’ll appreciate your cooperation.
I’m not getting the first page of a document on the preview
Are you using one of ours showcase project and facing this issue?

Kind regards
Hi,

Code snippet:
val docInfo = _imageHandler.getDocumentInfo(new DocumentInfoOptions(name))
Both getDocumentInfo and DocumentInfoOptions are marked as deprecated.

Yes I'm using showcase project for spring MVC adapted to Play Framework.

Hi Again,


Thanks for providing the details.
We shall investigate your scenario and share the outcomes with you. Please stay tuned.

Best wishes

Hi There,


Both <span style=“background-color: rgb(52, 65, 52); color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9.6pt;”>getDocumentInfo and <span style=“background-color: rgb(52, 65, 52); color: rgb(169, 183, 198); font-family: “Courier New”; font-size: 9.6pt;”>DocumentInfoOptions are marked as deprecated.
Are you facing this issue using latest release of the API. Keen to hear from you.

Best regards