如何在 downloading/exporting 时指定 pdfbox.apache 文件名?

how to specify the pdfbox.apache filename when downloading/exporting?

只是想知道在将 doc.name 指定为模板

之后是否有任何方法可以命名文档
  PDDocument doc = PDDocument.load(play.Play.application().resource("/templates/" + FileName));

  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            doc.save(byteArrayOutputStream);
            doc.close();

因此,当您下载PDFBOX渲染文件时,无法指定pdf文件的名称。还有其他方法吗?

我不熟悉 Play 框架。

如果您想让用户能够下载文件并为其提供文件名,那么您需要设置 HTTP header

Content-Disposition: attachment; filename=myfile.pdf

当浏览器看到这个 header 时,用户将看到一个对话框来保存文件,并建议名称为 myfile.pdf.