I am facing this error - "application/pdf" is not a supported mime type. I am trying to save the content of p:editor as pdf to my local machine.
Imports
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.pdf.PdfWriter;
Function
public StreamedContent getFile() {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Document document = new Document(PageSize.LETTER);
PdfWriter pdfWriter = PdfWriter.getInstance(document, os);
document.open();
document.addCreationDate();
HTMLWorker htmlWorker = new HTMLWorker(document);
String str = "<html><head></head><body>"+ this.getMessage() +"</body></html>";
htmlWorker.parse(new StringReader(str));
document.close();
InputStream is = new ByteArrayInputStream(os.toByteArray());
file = new DefaultStreamedContent(is, "application/pdf", "ohyeah.pdf");
return file;
}
catch (Exception e) {
return null;
}
}
Following an excellent post at : https://forum.primefaces.org/viewtopic.php?f=3&t=21342&p=170835#p170835
Please help !
EDIT------------------
If i use mime type as image/jpg, then also I receive the same error. Issue looks like something else. Can anyone point it to me please .
javax.portlet.faces.BridgeException: java.lang.IllegalArgumentException: image/jpg is not a supported mime type
Thanks Melloware for pointing it out that the error is portlet related.
If anyone is facing the same issue, here is the solution which worked for me. Tweak it as per your needs.