【发布时间】:2015-02-05 14:23:27
【问题描述】:
我有以下情况,入一个方法我有:
ByteArrayInputStream fis = new ByteArrayInputStream(Bean.getValoreString("PDFmulti", "PDF").getBytes());
如您所见,fis 变量是 ByteArrayInputStream 和 Bean.getValoreString("PDFmulti", "PDF").getBytes()返回一个 byte[]
所以现在我需要使用 iText 将 fis 对象的内容放入 PDF。
我能做些什么呢?我认为我必须读取此输入流并将其内容放入 ByteArrayOutputStream,如下所示:
public static byte[] readFully(InputStream stream) throws IOException
{
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int bytesRead;
while ((bytesRead = stream.read(buffer)) != -1)
{
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
然后呢?
【问题讨论】:
标签: java pdf pdf-generation itext bytearrayoutputstream