Last active
November 10, 2020 01:42
-
-
Save mbgarcia/5f98c0d78f05f83fdee804cfe20135ad to your computer and use it in GitHub Desktop.
Transfer OutputStream to InputStream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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