我目前使用的是PDFBox 3.0.1版本,在尝试从URL加载PDF时遇到了挑战。似乎没有为此提供具体的方法。
以下是我尝试过的代码片段,但它没有按预期运行:
public void loadPDF(String url, String name) throws IOException {
PDDocument document = null;
URL pdfUrl = new URL(url);
URLConnection urlConnection = pdfUrl.openConnection();
InputStream ip = urlConnection.getInputStream();
BufferedInputStream bf = new BufferedInputStream(ip);
try {
document = Loader.loadPDF((RandomAccessRead) ip);
} catch (IOException e) {
Assert.fail("Could not load PDF. Please check the URL again");
}
}
有人能为从PDFBox 3.0.1中的URL加载PDF提供指导或替代方法吗?