需要有关pdf渲染器的帮助 [英] Need help with pdf-renderer
问题描述
我正在使用PDF-Renderer来查看我的Java应用程序中的PDF文件.对于普通的PDF文件,它是完美的工作.
I'm using PDF-Renderer to view PDF files within my java application. It's working perfectly for normal PDF files.
但是,我希望该应用程序能够显示加密的PDF文件.加密后的文件将使用 CipherInputStream 进行解密,但是我不想将解密后的数据保存在磁盘上.我试图找到一种方法,可以将已解密的数据从 CipherInputStream 传递到 PDFFile 构造函数,而不必将已解密的数据写入文件.
However, i want the application to be able to display encrypted PDF files. The ecrypted file will be decrypted with CipherInputStream, but i do not want to save the decrypted data on disk. Am trying to figure a way i can pass the decryted data from CipherInputStream to the PDFFile constructor without having to write the decryted data to file.
如果有人可以帮助您链接到PDF-Renderer教程,我也将不胜感激.
I will also appreciate if someone can help with a link to PDF-Renderer tutorial, so that i can read up more on it.
谢谢.
推荐答案
尝试以下课程:
import com.sun.pdfview.PDFFile;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
public class PDFFileUtility {
private static final int READ_BLOCK = 8192;
public static PDFFile getPDFFile(InputStream in) throws IOException {
ReadableByteChannel bc = Channels.newChannel(in);
ByteBuffer bb = ByteBuffer.allocate(READ_BLOCK);
while (bc.read(bb) != -1) {
bb = resizeBuffer(bb); //get new buffer for read
}
return new PDFFile(bb);
}
private static ByteBuffer resizeBuffer(ByteBuffer in) {
ByteBuffer result = in;
if (in.remaining() < READ_BLOCK) {
result = ByteBuffer.allocate(in.capacity() * 2);
in.flip();
result.put(in);
}
return result;
}
}
因此致电:
PDFFileUtility.getPDFFile(myCipherInputStream);
这篇关于需要有关pdf渲染器的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!