Skip to content

Instantly share code, notes, and snippets.

@mbgarcia
Last active November 10, 2020 01:42
Show Gist options
  • Save mbgarcia/5f98c0d78f05f83fdee804cfe20135ad to your computer and use it in GitHub Desktop.
Save mbgarcia/5f98c0d78f05f83fdee804cfe20135ad to your computer and use it in GitHub Desktop.
Transfer OutputStream to InputStream
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class Teste {
public static void main(String[] args) {
try {
ByteArrayOutputStream o = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, o);
document.addTitle("My iText Test");
document.open();
Paragraph paragraph = new Paragraph();
paragraph.add("Hello World");
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
document.close();
ByteArrayInputStream input = new ByteArrayInputStream(o.toByteArray());
input.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment