有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从pdf文档中获取一个页面,并显示在jsp页面中

在我当前的应用程序中,我可以使用html对象和jsp页面中的视图来加载全部pdf文档。但我需要单独显示文档中的每一页,就像adobe reader中的缩略图视图一样

这是我的jsp代码

<div class="showpdf" style="margin-left: 10%;">
    <object id="pdfPage"
        data="${pageContext.request.contextPath}/<%=session.getAttribute("fileName")%>"
        type="application/pdf" width="191" height="207" title="">
    </object>
</div>

这是我的servlet代码

File file = new File("D:/IIV 3 Project/Documents/Invoices/invoices/"+fileName+"");
    response.setHeader("Content-Type",    getServletContext().getMimeType(file.getName()));
    response.setHeader("Content-Length", String.valueOf(file.length()));
    response.setHeader("Content-Disposition", "inline; filename=\""+fileName+"\"");
         Files.copy(file.toPath(), response.getOutputStream());

下面是使用pdfbox从pdf获取单个页面的代码

File PDF_Path = new File("C:\\PDF.PDF");
    PDDocument inputPDF = PDDocument.load(PDF_Path);
    List<PDPage> allPages = inputPDF.getDocumentCatalog().getAllPages();
    inputPDF.close();
    PDPage testPage = (PDPage)allPages.get(0);

共 (0) 个答案