gpt4 book ai didi

java - 需要 pdf 渲染器的帮助

转载 作者:行者123 更新时间:2023-12-04 06:46:54 34 4
gpt4 key购买 nike

我正在使用 PDF-Renderer 在我的 Java 应用程序中查看 PDF 文件。它适用于普通的 PDF 文件。

但是,我希望应用程序能够显示加密的 PDF 文件。 ecrypted 文件将被解密 密码输入流 ,但我不想将解密的数据保存在磁盘上。我正在想办法从 传递解密数据密码输入流 PDF文件构造函数而不必将解密的数据写入文件。

如果有人可以帮助提供 PDF-Renderer 教程的链接,我也将不胜感激,以便我可以阅读更多相关内容。

谢谢。

最佳答案

尝试以下类(class):

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);

关于java - 需要 pdf 渲染器的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3632833/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com