Good morning , is there any way to specify the file name when the file is downloaded when you're using a DefaultStreamedContent
<pe:documentViewer height="500"
id="documentoView" value="#{managedBean.content}"
style="width:100%;height:100%;" />
pe:documentViewer
-
- Posts: 45
- Joined: 03 Jul 2014, 19:04
- Location: Biarritz, France
You need to do it programmatically. DefaultStreamedContent has several constructors:
Reference: http://www.primefaces.org/docs/api/5.3/ ... ntent.html
- DefaultStreamedContent()
- DefaultStreamedContent(InputStream stream)
- DefaultStreamedContent(InputStream stream, String contentType)
- DefaultStreamedContent(InputStream stream, String contentType, String name)
- DefaultStreamedContent(InputStream stream, String contentType, String name, String contentEncoding)
Reference: http://www.primefaces.org/docs/api/5.3/ ... ntent.html
PrimeFaces 5.3 - PF Extensions 4.0.0 - OmniFaces 2.2 - Mojara 2.2.12 - GlassFish 4.1.1 - Java 7 - Netbeans 8.1
I am using constructor with custom Filename
public DefaultStreamedContent(InputStream stream,
String contentType,
String name)
but when i am trying to save PDF-document its default name is document.pdf.
Also my filename has not been taken.
Could anybody shows working example?
public DefaultStreamedContent(InputStream stream,
String contentType,
String name)
but when i am trying to save PDF-document its default name is document.pdf.
Also my filename has not been taken.
Could anybody shows working example?
It looks like in the pdf.viewer.js which is from the Mozilla PDF.js library they try and guess the name from the URL. But since the streamed content does not have a file name in the URL it can't figure out the name and gives it the default "document.pdf".
Code: Select all
/**
* Returns the filename or guessed filename from the url (see issue 3455).
* url {String} The original PDF location.
* @return {String} Guessed PDF file name.
*/
function getPDFFileNameFromURL(url) {
var reURI = /^(?:([^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
// SCHEME HOST 1.PATH 2.QUERY 3.REF
// Pattern to get last matching NAME.pdf
var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
var splitURI = reURI.exec(url);
var suggestedFilename = reFilename.exec(splitURI[1]) ||
reFilename.exec(splitURI[2]) ||
reFilename.exec(splitURI[3]);
if (suggestedFilename) {
suggestedFilename = suggestedFilename[0];
if (suggestedFilename.indexOf('%') !== -1) {
// URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
try {
suggestedFilename =
reFilename.exec(decodeURIComponent(suggestedFilename))[0];
} catch(e) { // Possible (extremely rare) errors:
// URIError "Malformed URI", e.g. for "%AA.pdf"
// TypeError "null has no properties", e.g. for "%2F.pdf"
}
}
}
return suggestedFilename || 'document.pdf';
}
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Posts: 7
- Joined: 14 Aug 2015, 20:09
I am also looking for a solution to this and was wondering if anyone has thought of a way around Mozilla PDF.js using the default document.pdf when passing in a StreamedContent object to documentViewer.
If you create a ticket on GitHub I will see if there is something clever I can do for the 6.1 Release...
https://github.com/primefaces-extension ... com/issues
https://github.com/primefaces-extension ... com/issues
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
I created issue: https://github.com/primefaces-extension ... issues/436
It is fixed in PF Extensions 6.1. You can use a new property "download" to set the name like...
It is fixed in PF Extensions 6.1. You can use a new property "download" to set the name like...
Code: Select all
<pe:documentViewer height="500" value="#{basicDocumentViewerController.content}" download="extensions-rocks.pdf"/>
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Posts: 7
- Joined: 14 Aug 2015, 20:09
Melloware,
Thank you so much, I cannot wait to test this!
Adam
Thank you so much, I cannot wait to test this!
Adam
No problem. If you want to see a sneak peak of it in action you can see it on my BETA site for 6.1
http://melloware.dyndns-free.com:8080/pe-showcase/
http://melloware.dyndns-free.com:8080/pe-showcase/
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1
-
- Posts: 7
- Joined: 14 Aug 2015, 20:09
Melloware,
It works!!!! - Any estimated release date?
Tooltip is looking pretty sweet too, never noticed that before...
Thank you once again,
Adam
It works!!!! - Any estimated release date?
Tooltip is looking pretty sweet too, never noticed that before...
Thank you once again,
Adam
-
- Information
-
Who is online
Users browsing this forum: No registered users and 15 guests