Save pdf file from html form on live server - java

I have a simple html file that contain input and send button. is there a way to that, when the user submits, puts the data into a PDF file and sends/saves it on live server ? i use jsPDF library but it save pdf on client side.

Common approach is rather to send to the server request from html form than to form pdf on the client side.
If the server is java I would recommend iText library to create pdf.

Related

View Content of data stored on google cloud to frontend application instead of download file with the name of blob

I am currently storing text on the cloud using
bucket.create(blobName, "hello".getBytes());
and blob name looks like this 1/1/1674/2020-06-02/9998-2-202062
The requirement is to generate pdf file from the data of multiple blobs. We can do this on our backend in java by getting the content from blob path like this
Blob blob=bucket.get("1/1/1674/2020-06-02/9998-2-202062");
new String(blob.getContent())
But we don't want to increase the load on the server by downloading the content first on the server and then send it to the front-end. So we are sending the signURL on the front-end so we can get the content at the front-end(angular 8) by using that URL and create the pdf. We are creating singurl this way.
Blob blob=bucket.get("1/1/1674/2020-06-02/9998-2-202062");
URL url=blob.signUrl(1, TimeUnit.HOURS,SignUrlOption.signWith(
ServiceAccountCredentials.fromStream(new FileInputStream(jsonfilePath))));
But the issue on front-end is whenever we click the URL on any browser it downloads the file with the blob-name
9998-2-202062 instead of just showing the content.
Is there any way so we can read the data from that cloud URL instead of downloading the content by chrome automatically?
And we do not change the browsers setting because it can not be done on the client machine?
The signUrl method only creates a link to the specified resource, you have to implement a way to read it, join the rest of the files you want to add and process them to create your PDF on the client side.
That said, for example you can create a javascript file and use the signed URL in a fetch function to gather all the text from the blobs, I found this example on another stackoverflow answer that might help you:
Promise.all([
fetch(signedURL1).then(x => x.text()),
fetch(signedURL2).then(x => x.text())
]).then(([sampleResp, sample2Resp]) => {
console.log(sampleResp);
console.log(sample2Resp);
});
Replace the signedURL1 and signedURL2 for the actual signed URLs that you created.
Once that you have the content of your files, you just have to create the PDF, I found a library named jsPDF that could be of your interest.

How to export excel file in GWT?

My requirement is to export an excel from GWT application on click of export button. In my case There is no need to send data from client to server as I can directly obtain data from database(same data is being populated on the client that is being exported).
All I tried to send a RPC call from Client site . but I am not able to figure out how to export excel on receiving the RPC call at server site.
This is certainly possilbe 100% client side.
You can use an Excel JavaScript builder like https://github.com/stephenliberty/excel-builder.js and call it from GWT with jsni or jsinterop.
Later you can save the file by
For Internet explorer for example filesaver.js https://github.com/eligrey/FileSaver.js/ in the same way.
For other browsers using HTML5 downloadv (using FileDownloadBuilder.createFileDownload().generateTextDownloadLink()) from https://github.com/akjava/html5gwt
Note for the generating an Excem file you could also just create an html file with table tags and save it as .xls, it with filesaver.js.
I use the html solution and filesaver.js/html5 download in my project and this works without a problem, and without the need for any serverside code, or any plugin on the client. 100% HTML5/javascript.
There is no way generating a excel file on the client site with native GWT without adding a third party product. (see knarf answer below)
I personally prefer this solution:
open an new window on the client
use a url, that triggers a servlet on the server
let the server generate the excel file
save the newly generated file inside the webspace
return the url to the excel file to the client
This works for me.

convert AngularJS to word document

I have in my disposal a Spring MVC backed server, using AngularJS in client side to display dynamic content. Was researching possibility to get current content displayed in the browser and convert it to a word document.
I assume there's a way to do build word documents with Java, but to do so i'll have to send existing HTML to the server side - how would i do that? just send the document DOM object?
Suppose i'll be able to do so, what if i want to include 2 images? I do know its possible to send images as base64 string.
To conclude, my general approach would be to try and send all client side data to the server and use Java to generate word document.
I have found docx4j so this approach seems possible.
Is that the right way to go? Any thoughts would be appriciated.
On the server side, you can use a library like Apache POI for creating docx documents.
There are multiple ways to pass data from client to server:
Make an AJAX call
How to send FormData objects with Ajax-requests in jQuery?
Ajax Upload image
Submit a form from the client side to the server using POST. Using multi-part forms will allow you to send attachments to the server
See Handling HTML (multipart form-data) file uploads with Java
On the client side, there are some JS libraries available for creating docx documents:
https://github.com/evidenceprime/html-docx-js
Generate a Word document in JavaScript with Docx.js ?

non-form based file upload servlet in Java

I am trying to upload files using HTML5 File API to a Java Servlet. Here is the use case
A user downloads the file to local file system (using HTML5 file api)
Once, the required change is done, the file needs to be uploaded back to the server.
There is no form based selection and the file needs to be streamed. I am successful in converting files to base64 encoded string and sending to the server (which is form based upload) as a string attribute.
But, I wanted to server to accept Arraybuffer or binary streams. This is not possible in form-based based upload. So, is there any other way of handling file uploads in Java other than form-based methodologies ?

java - checking file content before uploading to server

i have got a situation now.
I need to develop a webpage where user can select a file to upload and before uploading the file to server i need to check first few lines of the file whether the data is valid or not and if the data is valid then upload the file, if not through an error message.
the file will be text file.
thanks,
Sandeep
HTML/Javascript does not offer a way of reading the contents of a local file. You must either upload it and check it in the server.
If you really want a client side check, you then must build a signed applet(or even ActiveX) to run in your webpage and handle the upload instead of using plain HTML.
You should perform your validation on the server side, right before you perform the upload.

Categories

Resources