Boa noite pessoal,
Sei que existem vários tópicos sobre jasper + jsf, porém após 2 dias procurando não encontrei algo que venha a me ajudar.
O problema é o seguinte, após pegar alguns exemplos no próprio fórum estou tentando gerar um arquivo pdf através de um resultset e o negócio não vai pra frente.
Não recebo nenhum erro, porém o arquivo não é renderizado em tela, o que aparece após eu clicar em um item de menu e disparar uma ação é mostrado abaixo:
%PDF-1.4
%����
4 0 obj
<</Length 1179/Filter/FlateDecode>>stream
x�͚ˎ�6��z
.�E\�"JZN�K�d�
Yhh�QA[�l7h_����@I�bS��RǬa�x΁�K���O�4�%/� �H9�/�W��}B�[�.F���F�|�|�#��2y���W]{,I�X�nDR�dƙِ ��i�ܭ�g˪[W��zW)Z=��_>*]���v�(ϊYq�a�a�r/wW�j��kZ���h*�5����a��&u"�e�*ӎ#�{�kԘ1WE�$�3�er?m <C��_���q���r/�'�F1|;�K=�e�L(B���Դk�解o�&Ⴄ3��dy=]��f���pSs��I�*L�5Ķ���`_bM(�JgBqsyU]�s
B$+�O�4<%n6�\�kD{&E�G�n�͟uw.�H��#��cD���ΐ��,�YbD��w�k���� =o���;YT���(�ё��l;��,��G
�TQ�k��YoZ���_��\��C.��%�vһ��d���lۉ��0%ք"\�t&����D�~1ȁQ?�]�:��1a�4�XXv)�e�]s�b������Q��o��aYo�o4�av�]�L;�c��wC5ha��)mۉ��0%ք"\�t&K����4ڱ��ΥfU����1`a'ݶB�{�3N!$�@��R�cy~!���J:8**�X�FI�j��i�� �c,�3��K��rһ�Z�_Clۉ^�%ք"\�t&�����4��Z@ܨ��Ͷ���faup���L�[��pPv�2.�pz)؁��;0*.�H>;�|��]m�J�����'㎦�e�vһ��P�k�m;ў�ĚP��΄bqw]]��;RB��wp�O�gyp��<���eT�Q���<xPQ�aGEe��(�~���6&�HA=�2�K-`���
���p_�mۉ��1%ք"\�t&˼���D�hI�3ﵬ�a���s��x`޻�r���ց14�b�0h��u�A7!c�TT��QQYG8e�>�x�;y�N{�>tX�PE;��P
Up�kJ�v�=5L�5�(� ł4
t�C�
����>�� 8��bܰ�Sb|������8��wS#"TT��QQ�K>����w�h�l6�'��҃��@7��F�]����2��R��f�fy0��jU�
��3�Q:%��#�s_���y����R_�����S�6��\�_{�
�
endstream
endobj
1 0 obj
<</Group<</Type/Group/CS/DeviceRGB/S/Transparency>>/Parent 5 0 R/Contents 4 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/ColorSpace<</CS/DeviceRGB>>/Font<</F1 2 0 R/F2 3 0 R>>>>/MediaBox[0 0 595 842]>>
endobj
7 0 obj
<</Length 917/Filter/FlateDecode>>stream
x�͙�n�0��s>����=�?��X5a&M� �Y� n�.�e��ɤ/VkU�Խ��/y�g��39�%�#�9�͓���:�Х�6EX��߂fh�L^�KQ��"y�r���� CO ��x‘�|~�|�O�'F��h���9����x{�@�����'�u�޿�"�S�eja�𮆻c;Z�lK��K��7})���5�e���aT,w'��2�� �fB�h��qU��Z�e�����3Fwf�a�ܙA -�G��W��T��$��(�Dq�ΰ��(�׍\�k��aNOK����h��
j�
���F���\���(##Q�R�
�-Wsa�p�E�6jB����7�j�l�Aa!���-�Z�7�x.X�S�e��v5SwlG[p�g�R�@�M_�N�Ia���up�Yq�=dnW8D��`Ǣ�H��;�rpT\��t�r�^� �� g�ސc"uD1Nun��(��7TK��ę�>Py�a��jR��B�P�D@�hF���S�,FG�8ۘȏ�6�SQ�GEee�t�mgJ*����X������e�H����P-I�j�;���m�3})|��/n'դ@�ah�p���2
��Y�Z����L�÷�6��[���7�Sq�FE�e#��U6��
�e��o��7Js��T�jYByW�ݱmYaK��K��7}qx;�&��h��~�q���X�opJ�Qm��M��H|�;�opTT����M����u�8�@.#[ȵ~o��Q�S�e�#
�5�
��-q�/�T���A9¡=�JCnrp���C,��Q��ep��tD@�R�I:�SQIaG�%&��#�9¶oV�ƹ�7�����+����)"�w|0ă~_ɻe�^8̌��8t�C��)�6z�Z�U#Q&��fu_�Ӱ׌��Qj�
endstream
endobj
6 0 obj
<</Group<</Type/Group/CS/DeviceRGB/S/Transparency>>/Parent 5 0 R/Contents 7 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/ColorSpace<</CS/DeviceRGB>>/Font<</F1 2 0 R>>>>/MediaBox[0 0 595 842]>>
endobj
8 0 obj
[1 0 R/XYZ 0 854 0]
endobj
9 0 obj
[6 0 R/XYZ 0 854 0]
endobj
2 0 obj
<</BaseFont/Helvetica/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
3 0 obj
<</BaseFont/Helvetica-Bold/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
endobj
5 0 obj
<</ITXT(2.1.7)/Type/Pages/Count 2/Kids[1 0 R 6 0 R]>>
endobj
10 0 obj
<</Names[(JR_PAGE_ANCHOR_0_1) 8 0 R(JR_PAGE_ANCHOR_0_2) 9 0 R]>>
endobj
11 0 obj
<</Dests 10 0 R>>
endobj
12 0 obj
<</Names 11 0 R/Type/Catalog/ViewerPreferences<</PrintScaling/AppDefault>>/Pages 5 0 R>>
endobj
13 0 obj
<</Creator(JasperReports \(RelatorioProdutos\))/Producer(iText 2.1.7 by 1T3XT)/ModDate(D:20100628230801-03'00')/CreationDate(D:20100628230801-03'00')>>
endobj
xref
0 14
0000000000 65535 f
0000001262 00000 n
0000002793 00000 n
0000002881 00000 n
0000000015 00000 n
0000002974 00000 n
0000002489 00000 n
0000001505 00000 n
0000002723 00000 n
0000002758 00000 n
0000003043 00000 n
0000003124 00000 n
0000003158 00000 n
0000003263 00000 n
trailer
<</Root 12 0 R/ID [<674033d37891fbbdb674e18ce1286a7c><34eeeda8242a1955497ef8b608d8c895>]/Info 13 0 R/Size 14>>
startxref
3431
%%EOF
O código Java que estou utilizando para tentar gerar o pdf é o seguinte:
public void gerarPDFProduto() throws IOException, JRException, SQLException, DAOException{
JRResultSetDataSource jrRS = new JRResultSetDataSource(dao.rsGerarPDF());
JasperPrint jasperPrint = JasperFillManager.fillReport("C:/RelatorioProdutos.jasper", new HashMap(), jrRS);
this.enviarPDF(jasperPrint);
}
public void enviarPDF(JasperPrint jasperPrint){
try{
//GERA PDF
// @ outputStream
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType("application/pdf");
//response.setHeader("Content-Disposition", "filename=relatorio.pdf");
response.setContentLength(pdfStream.size()); //para o pdfStream
// Flush pdfStream pra response
ServletOutputStream flusher;
flusher = response.getOutputStream();
pdfStream.writeTo(flusher);
flusher.flush();
flusher.close();
FacesContext.getCurrentInstance().responseComplete();
pdfStream.close();
pdfStream = null;
}catch (Exception e) {
e.printStackTrace();
}
}
Qualquer ajuda é bem vinda, inclusive código fonte com algum exemplo funcionando.
Obrigado!