Page 1 of 2

pe:documentViewer

Posted: 26 Oct 2015, 19:17
by rlimamiranda
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%;" />

Re: pe:documentViewer

Posted: 27 Oct 2015, 11:27
by Mathieu-Castets
You need to do it programmatically. DefaultStreamedContent has several constructors:
  • 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)
Just use one of the last two to specify a filename.

Reference: http://www.primefaces.org/docs/api/5.3/ ... ntent.html

Re: pe:documentViewer

Posted: 22 Jun 2016, 10:04
by Ksyusha
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?

Re: pe:documentViewer

Posted: 30 Dec 2016, 22:54
by Melloware
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';
}

Re: pe:documentViewer

Posted: 25 Jan 2017, 19:07
by adamjfusco
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.

Re: pe:documentViewer

Posted: 25 Jan 2017, 22:58
by Melloware
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

Re: pe:documentViewer

Posted: 28 Jan 2017, 16:37
by Melloware
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...

Code: Select all

<pe:documentViewer height="500" value="#{basicDocumentViewerController.content}" download="extensions-rocks.pdf"/>

Re: pe:documentViewer

Posted: 09 Feb 2017, 19:51
by adamjfusco
Melloware,
Thank you so much, I cannot wait to test this!

Adam

Re: pe:documentViewer

Posted: 09 Feb 2017, 20:07
by Melloware
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/

Re: pe:documentViewer

Posted: 09 Feb 2017, 20:45
by adamjfusco
Melloware,
It works!!!! - Any estimated release date?
Tooltip is looking pretty sweet too, never noticed that before...

Thank you once again,
Adam