PDF Viewer in Cuba

Hi,

Is there any inbuilt PDF viewer component available with Cuba platform?

To brief on the requirement, A web service returning base64Binary needs to be consumed from Service layer (core module) which is further invoked from controller (web module) and converted into PDF from base64Binary in-memory or persisted as file. This retreived PDF from service needs to be displayed to user on the UI with some sort of Viewer for instance PDF Viewer.

I have gone through FileDescriptor but couldn’t figure out how to assign returned based64Binary (byte[] array) from web service to FileDescriptor.

Please see answer here: Include PDF Reader in JavaScript in Cuba - CUBA.Platform

Hi Yuriy,

Thanks for responding. I have gone through this link and was able to implement it, but I have couple of concerns with the provided samples.

  1. If the file is stored on the file system, how would it work in Clustered setup? I have faced such situations with other frameworks earlier, where file get persisted on say First Node it wont be accessible from Second Node.

  2. If I want to persist the file in data store (database) for instance using dataManager.commit(fileDescriptor) and try to access the file on UI layer it’s unavialble as referring to example I"m using embedded.setSource(String.format(“reporting-service%s.pdf”, UUID.randomUUID()), new FileDataProvider(fileDescriptor)) but I think there must be other provider to return the data in some temp location from DB.

Please do note, as following standards and best practices I don’t think it’s feasible to connect UI layer (web moduel) directly to database, rather I would like to know If i could get the file from Database directly into some temp location like in-memory and use it on UI layer. Currently I tried to persist the FileDescriptor in Database and return the reference for FileDescriptor from Service Layer to UI Layer but it’s still looking for the PDF file in local file system as I"m using FileDataProvider.

Please guide how to store this PDF file in database and retreive in UI layer and display in Embedded component. Also if there is possibility to retreive and store files in-memory for some duration as long as the request scope is alive or something like that.

Hi,

By default files are stored in a file system of middleware servers and files are saved on all servers if you save it using FileUploading from the web client. You can use any third party replication for files such as dedicated NAS or simple NFS.
More information about default FileStorage you can find here [url=https://doc.cuba-platform.com/manual-6.1/file_storage_impl.html]https://doc.cuba-platform.com/manual-6.1/file_storage_impl.html[/url]

If you want to change mechanism of storing files you can implement your own FileStorage to store files in a database. For example see additional implementation of FileStorage - com.haulmont.cuba.core.app.filestorage.amazon.AmazonS3FileStorage.

You can enable your implementation instead of the standard one by declaring it in the spring.xml file of the core module:


<bean name="cuba_FileStorage" 
      class="com.haulmont.cuba.core.app.filestorage.amazon.AmazonS3FileStorage"></bean>

FileDataProvider uses FileStorage to obtain files from a middleware and you can continue using it even if you replace implementation of FileStorage.

We don’t have request scope files and we don’t store the content of files in memory. You can manipulate with a temporary file in the web client using FileUploadingAPI.getFile(uploadField.getFileId()), for example, you can save byte[] content of the file directly to an entity field.

1 Like