Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename PDF in primefaces media tag

I am using streamedcontent in primefaces and using media tag to show it. When download button is pressed in the viewer it downloads file with the name dynamiccontent.properties. Is there any way to rename it?

I am using html4, java 7 and primefaces 5.2.24.

I have tried to set parameter #toolbar to hide the toolbar like below but it is not working:

<p:media id="pdfViewer" value="#{mybean.pdfMedia}" width="100%" height="90%" player="pdf" cache="false" >
        <f:param name="#toolbar" value="0"></f:param>
</p:media>

and my streamed content is generating from iText like this:

   baos = new ByteArrayOutputStream();
   document = new Document();
   document.setPageSize(PageSize.A4);
   document.setMargins(70, 70, 100, 100);
   writer = PdfWriter.getInstance(document, baos);
   document.open();
   document.newPage();
   XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new ByteArrayInputStream(pageContents));
   document.close();

   InputStream stream = new ByteArrayInputStream(baos.toByteArray());
   StreamedContent  pdfMedia = new DefaultStreamedContent(stream, "application/pdf");

Is there any way to rename the it? or is there any way to hide the tool bar?

like image 307
Imran Khurram Avatar asked Dec 20 '18 08:12

Imran Khurram


1 Answers

This was a bug in PF 5.2.24 that you are using and is fixed in PF 6.1 or higher.
See this bug ticket: https://github.com/primefaces/primefaces/issues/2055

Make sure to set "NAME" in the DefaultStreamedContent by either using the constructor org.primefaces.model.DefaultStreamedContent.DefaultStreamedContent(InputStream stream, String contentType, String name) or the org.primefaces.model.DefaultStreamedContent.setName(String) method.

like image 62
Melloware Avatar answered Nov 13 '22 23:11

Melloware