我们将Base 64编码的图形图像作为webservice响应,我们必须将其转换为PDF文件。我们使用波纹管代码片段将base 64编码的图形图像转换为pdf doc。将Base 64编码的图形图像转换为PDF文件时的问题
// First decode the Base 64 encoded graphic image
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(s);
// Create the pdf file
File file = new File("output.png");
FileOutputStream fop = new FileOutputStream(file);
fop.write(decodedBytes);
fop.flush();
fop.close();
但是,当我们打开PDF文件,我们得到了波纹管错误。
Adobe Reader无法打开“output.pdf”,因为它不是受支持的文件类型,或者是因为文件已损坏。
我们尝试了PDF框,波纹管,
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(s);
ImageToPDF imageToPdf = new ImageToPDF();
imageToPdf.createPDFFromImage("output.pdf", decodedBytes.toString());
这也没有帮助我们。请给我建议一种方法来创建从Base 64编码图形图像的PDF文件。
感谢Santosh的评论。我想直接将Base 64编码图形图像转换为pdf文件,而不是先将其转换为图像,然后再转换为pdf。 –