我使用下面的代码片段代码生成Java中
代码HTTP请求PDF作为输出流: -生成PDF作为输出流中的Java HTTP请求
webAppAccess.getHttpServletResponse().setContentType("application/pdf");
try {
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, webAppAccess
.getHttpServletResponse().getOutputStream());
// step 3
document.open();
// step 4
document.add(new Paragraph("Hello World"));
document.add(new Paragraph(new Date().toString()));
// step 5
document.close();
} catch (DocumentException de) {
throw new IOException(de.getMessage());
}
我收到的PDF上屏幕
%PDF-1.4%2 0 OBJ <>流X + R 26S00SI2P51BҸ4>>> /多媒体[0 0 595 842] /家长3 0 R /内容 2 0 R /类型/页>> endobj 1 0 OBJ <> endobj 3 0 OBJ <> endobj 5 0 OBJ <> endobj 6 0 OBJ <> endobj外部参照0 7 0000000000 65535˚F0000000331 00000Ñ0000000015 00000Ñ0000000419 00000ñ0000000174 00000ñ 0000000470 00000ñ0000000515 00000ñ拖车<] /信息6 0 R >> %的iText-5.4.0 startxref 668 %% EOF
请帮我出了相同的
您需要设置内容类型标题。您收回的数据是PDF,但浏览器不知道它是PDF。 – HocusPocus 2014-10-20 14:46:47
我应该为此添加哪段代码?能否请你给我.. – eagle 2014-10-20 14:53:05