I am re-implementing a subset of pdftk (pdftk fails with newer versions of pdf) and one of it's features it the ability to output an interactive pdf file to the command line (for piping purposes). I currently am doing that with
File tmp=new File("tmp.pdf");
output= new String(Files.readAllBytes(Paths.get("tmp.pdf")), "UTF-8");
As discussed in the comments - instead of saving to a temp file, you can save to System.out:
Although I've never tested whether System.out can be used for such a purpose and keep the content intact, so I'd recommend that you do some binary test to compare the original PDF and what you get out of the pipe.