【发布时间】:2018-12-05 22:39:13
【问题描述】:
我有一个服务已经保存了 pdf 但保存在服务器中, 我将不胜感激,我尝试使用 servlet,但我认为我做得不对 这是我的代码:
@POST
@Path("reporteComisiones")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void reporteComisiones (Dtorest2 dtorest2) throws DocumentException, FileNotFoundException, ParseException, IOException
{
Date fecha = new Date();
SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy");
List<DtoOutrest2> lista = serComisiones(dtorest2);
Document document = new Document();
FileOutputStream FOS = new FileOutputStream("C:\\reportes\\"+dtorest2.persona_id+"-"+formateador.format(fecha)+".pdf");
PdfWriter.getInstance(document, FOS);
document.open();
Paragraph titulo = new Paragraph("Reporte Comisiones",FontFactory.getFont(FontFactory.TIMES_BOLD,20,Font.BOLD,BaseColor.BLUE));
titulo.setAlignment(titulo.ALIGN_CENTER);
document.add(titulo);
Paragraph Indicefecha = new Paragraph("Del "+ dtorest2.FechaIni + "hasta el "+ dtorest2.FechaFin,FontFactory.getFont(FontFactory.TIMES_BOLD,12));
Indicefecha.setAlignment(Indicefecha.ALIGN_CENTER);
document.add(Indicefecha);
document.add(new Paragraph("----------------------------------------------------------------------------------------------------------------------------------"));
document.close();
/*HttpServletResponse response = null;
try{
FileInputStream archivo = new FileInputStream("C:/reportes/"+dtorest2.persona_id+"-"+formateador.format(fecha)+".pdf");
int longitud = archivo.available();
byte[] datos = new byte[longitud];
archivo.read(datos);
archivo.close();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","attachment;filename="+dtorest2.persona_id+"-"+formateador.format(fecha)+".pdf");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(datos);
ouputStream.flush();
ouputStream.close();
}catch(Exception e){
e.printStackTrace();
}
*/
}
【问题讨论】:
-
这是什么意思:“在客户端保存 pdf”?
-
我将我的项目部署在服务器中,但是当在其他电脑(客户端)中使用应用程序时,应用程序将文件保存在服务器中
-
我的回答对你有帮助吗?
标签: java pdf servlets itext report