簡體   English   中英

我已經生成了pdf文件,現在我不想下載文件,但是我想使用Java直接在ftp上上傳文件

[英]I have genrated the pdf file now i dont want to download the file but i want to upload the file directly on ftp using java

所以我現在每次運行代碼時都將html轉換為pdf文件,該文件被下載並且其工作正常,但我不想下載,而是想在文件生成后立即直接上傳到ftp服務器上,下面是我的代碼

@GET
@Path("/test")
public String test(@Context HttpServletResponse response){

String strHtml ="<html><body>"Here is my html"</body></html>";
String filename=test.pdf";
DocumentBuilder builder   =   DocumentBuilderFactory.newInstance().newDocumentBuilder();
      @SuppressWarnings( "deprecation")
      org.w3c.dom.Document doc = builder.parse( new StringBufferInputStream(strHtml.replaceAll("&" , "&amp;")));
     ITextRenderer renderer = new ITextRenderer();
      renderer.setDocument((org.w3c.dom.Document) doc, null);

      renderer.layout();

           response.setHeader( "Cache-Control","private" );
           response.setHeader( "Pragma","expires" );
           response.setHeader( "Content-Disposition", "attachment; filename=\"" + filename  + "\"");

      renderer.createPDF(response.getOutputStream());
      response.getOutputStream().flush();
      response.getOutputStream().close();

}

我建議使用Apache Commons Net庫來使用FTP。 這是一個簡單的FTP客戶端示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM