简体   繁体   English

从Itext pdf源生成inputStream

[英]Generate inputStream from Itext pdf source

I'm trying to generate an inputStream Object from a file generated by iText library. 我正在尝试从iText库生成的文件生成inputStream对象。 These are the first bytes in the file: 这些是文件中的第一个字节:

%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 1571/Filter/FlateDecode>>stream
)©toÿqûºÒç¹Ð4)ÖÞ{Ñ$,·7?ÂDCþDÆü½

Suppose that you created your PDF like this: 假设您创建了这样的PDF:

ByteArrayOutputStream out = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph("Hello World"));
document.close();

In that case you can convert the OutputStream to an InputStream like this: 在这种情况下,您可以将OutputStream转换为InputStream如下所示:

InputStream in = ByteArrayInputStream(out.toByteArray());

Suppose that you created the PDF like this: 假设你创建了这样的PDF:

FileOutputStream out = new FileOutputStream("my.pdf");
Document document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.add(new Paragraph("Hello World"));
document.close();

Then you can create an InputStream like this: 然后你可以像这样创建一个InputStream

InputStream in = new FileInputStream("my.pdf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM