-1

このエラーに直面しています - 「application/pdf」はサポートされている MIME タイプではありません。p:editor のコンテンツを pdf としてローカル マシンに保存しようとしています。

輸入品

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;

関数

        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;
                  }
            }

次の優れた投稿: https://forum.primefaces.org/viewtopic.php?f=3&t=21342&p=170835#p170835

助けてください !

編集 - - - - - - - - -

MIME タイプを image/jpg として使用すると、同じエラーが発生します。問題は別のもののように見えます。誰でも私にそれを指摘してください。

javax.portlet.faces.BridgeException: java.lang.IllegalArgumentException: image/jpg is not a supported mime type
4

1 に答える 1