I am using jQuery.doGet() to get a csv file from the server. I am receiving the contents of the file in the onDataReceived function. How do I display the file dialog for the user to save it?
adsafe.util.doGet(url, params, onDataReceived);
onDataReceived(data) {
// how do i launch the file dialog for the user to save this data as a file.
}
Just today I did something similar but I just use window.open(file) and then issue the download in the new file.
I found a solution to this.
Instead of using doGet and then trying to launch the save box myself, I left it to the browser to do everything.
Simply calling
window.location = url
So this, downloads the file and displays the file dialog box.
Is this the right way to do it? Any comments?
Related
Html:
<iframe [src] ="fileurl" #iframe>
</iframe>
<button (click)="saveDoc()">
</button>
Stuck at savedoc() functionality.
Typescript:
/*api call to get document blob data on load*/
var fileurl = new blob([res.body],{type:application/pdf});
fileurl = URL.createObjectUrl(fileurl);
savedoc(){//here need logic to access edited pdf content as blob }
I am able to view and write in pdf editable fields (as input or checkboxes) but I can't figure out once filled all details, how to save/access that edited PDF content (mostly in blob format) to send back to server when click on save button. I have also tried ng2-pdf-viewer library of npm but same issue. I have to send this edited pdf to server in blob format to replace with existing.
How can I access edited pdf content?
Edited: Alternative approach, if its possible to trigger saveAs event from code to save iFrame pdf in local drive? I am using Window.showSaveFilePicker();but saved file seem corrupted or not exist.
Have a look at PDF-LIB.
It is a great JavaScript library which provides all sorts of tools to manipulate PDF documents. There is even tooling for filling the fields and saving the newly filled PDF.
In a past project, I used this library to capture user information from an HTML form and have it inserted and saved into a PDF.
Note:
Remember that once you have the filled PDF on client side, you must send it back to server side to update the PDF that is stored on the server.
Im using the following JS code to fetch an HTML file embedded in the server response:
$window.open('some url...');
The file is returned in the response body and being downloaded to the computer's file system.
I wish to open the file in a new tab in the browser (Chrome) rather than dowloading it.
Thanks
i think you should try it by calling function like this :-
function myFunction() {
window.open("..some url");
}
if it still download there is must be some other problem with your code
The Content-Disposition tells the browser to treat a file as a download.
Remove that header.
I have an application that generates a HTML page with data which the user can edit.
At the end I generate a .pdf file with jsPDF.
Is there any way that I can save this generated .pdf on my server-side database?
I'm using PrimeFaces.
Thanks in advance
Updating my solution for other users:
I found the .output('datauristring') method of the jsPDF which returns me a BASE64 String.
Then the String is sent via JSON to my backed bean and converted as my will.
Thanks all for the help! I've found my solution:
Once the user presses on the button to generate the .pdf, I'll save all the data he filled on the database, just the data.
When the user wants to see the pdf he generated back, I'll generate a new one with the data collected on his first submit.
Thank you all for the answers, they were helpful.
I suggest to use wkhtmltopdf.
It is a open source cross platform command line tool to generate pdf files from html content.
So to your requirement what you can do is, you need to send the html content to the server and save this content into a html file.
Once you saved html content into html you can call wkhtmltopdf like you execute MS-DOS commands in java.
Example: new ProcessBuilder("wkhtmltopdf.exe", htmlFilePath, pdfFilePath);
Once pdf file is generated you can read and store into database.
I have a form, where user can select values from collection of check boxes to filter data. Form posts to controller where xlsx format is defined to download xlsx file. I am using axslx_rails.
Now, I would like something to happen before and after the remote call.
And it works ok.
What I can't figure out is how to actually download a xlsx file as the respond block goes to JS format, not xlsx, which is something liek this:
format.xlsx { response.headers['Content-Disposition'] = 'attachment; filename="test.xlsx"'}
So, it works either one or the other way. Non-remote form downloads file as i have a format: xlsx defined. If i do a remote form, javascript works (show spinner, hide spinner, etc...), but file is not downloaded.
How can I achieve both?
Thx
OK, i've given up and went with a solution:
to save file to disk (to some publicly accessible location)
download file via jQuery fileDownload plugin
delete file
Seems like the best solution currently for what i need.
If someone has a more elegant solution, without extra JS library involved...
I am using .aspx page, i want to save some data on button click, which i extracted using function
function save() {
var t1 = document.getElementById('test').innerHTML;
alert(t1);
}
to .text file, .html file some folder on desktop.
the folder should appear, where i can save the file with any extension of .text or .html.
Javascript in the browser has no file i/o capabilities. The best you can do is popup a window with just the text you want to save and then save using the browser or send the text to the server and have it serve up the appropriate download mime-type as a new page.
You can't with javascript. You'll have to send the data file server side. See C# Asp.net write file to client.