// Now stream the docx final SaveToZipFile saver = new SaveToZipFile(output); ResponseBuilder builder = Response.ok( new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { try { saver.save(output); } catch (Docx4JException e) { throw new WebApplicationException(e); } } } ); builder.header("Content-Disposition", "attachment; filename=foo.docx"); builder.type("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); return builder.build();