我有以下代码:
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
//Want this to be on-the-fly pdf creation instead of using an existing one
File thePDF = new File("/path-to-pdf");
FileBody fb = new FileBody(thePDF);
builder.addPart("Body", fb);
....Code to use this builder with pdf in a rest callout在上面的代码中,我使用了一个现有的pdf文件。我想使用动态创建的pdf代替。我知道如何使用iText创建pdf,但我不想在服务器中创建一个新文件。是否有一种方法可以存储文件的内容并将其类型转换为FileBody或file,以便与MultipartEntityBuilder一起使用,而无需在磁盘上实际创建文件?
有什么建议吗?
提前感谢!
发布于 2017-04-11 20:27:46
用于创建PDF使用:
ByteArrayOutputStream baOut = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baOut);对于构建HttpEntity:
builder.addBinaryBody(name, baOut.toByteArray(), contentType, filename);https://stackoverflow.com/questions/43351378
复制相似问题