I'm trying to generate an inputStream Object from a file generated by iText library. 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:
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:
InputStream in = ByteArrayInputStream(out.toByteArray());
Suppose that you created the PDF like this:
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 in = new FileInputStream("my.pdf");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With