如何在 Java 中将 ByteArrayOutputStream 转换为 PDF 并保存在硬盘中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4322240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert a ByteArrayOutputStream into a PDF and save in hard disk in Java?
提问by user526211
How to convert a ByteArrayOutputStream into a PDF and save in hard disk in Java? Please give a sampple.
如何在 Java 中将 ByteArrayOutputStream 转换为 PDF 并保存在硬盘中?请举个例子。
回答by Nicolas Repiquet
What do you mean by "convert a ByteArrayOutputStream into a PDF"? A ByteArrayOutputStream containing PDF data that you wanna write on disk? Then maybe something like that :
“将 ByteArrayOutputStream 转换为 PDF”是什么意思?包含要写入磁盘的 PDF 数据的 ByteArrayOutputStream?那么也许是这样的:
String filename = "c:\test.pdf";
FileOutputStream output = new FileOutputStream(filename);
output.write(byteArrayOutputStream.toByteArray());
output.close();
回答by mark stephens
A PDF is a binary object so treat it like a JPEG or image file. Do not treat it like a text file or you will break it.
PDF 是二进制对象,因此将其视为 JPEG 或图像文件。不要把它当作一个文本文件,否则你会破坏它。