我在一个项目中使用 JSF 2.0、Tomcat 7.0、5.0 和 primefaces Viewer.js 对 pdf 文件进行索引以进行搜索、显示结果和查看文档。 问题是我需要从 PC 的文件系统打开 PDF 文档,我正在使用 Viewer.js 认为这是该项目的最佳选择,但仍然无法打开知道如何做吗?我只设法在我的项目文件夹中打开。
我尝试打开文档的方式如下:
<h:form id="form">
<p:dataList id="bus" value="#{beanBusqueda.bus}" var="busqueda" type="unordered" itemType="none" paginator="true" rows="20" emptyMessage="Sin resultados por el momento" paginatorAlwaysVisible="true">
<a href="http://localhost:8080/i-Bi/Viewer.js/#../file:///C:/directoriov1/#{busqueda.ruta}">Ver</a>
<h:outputText value="#{busqueda.resultados}" id="info"/>
<f:facet name="footer"><h:outputText value="#{beanBusqueda.buscar.info}" style="font-weight:normal"/></f:facet>
</p:dataList>
</h:form>
我的 ManagedBean 如下:
public void buscar() throws IOException{
setBus(new ArrayList<csBuscar>());
String resul="";
try {
directorio= FSDirectory.getDirectory(direct, false);
searcher= new IndexSearcher(directorio);
parser= new QueryParser("content", new StandardAnalyzer());
long start= new Date().getTime();
Query consulta= parser.parse(buscar.getBusqueda());
Hits hits = searcher.search(consulta);
long end= new Date().getTime();
Document doc=null;
if(hits.length()==0){
buscar.setResultados("No se encontraron resultados para "+buscar.getBusqueda());
}else{
for(int i=0;i<hits.length();i++){
doc=hits.doc(i);
//resul+=doc.get("nombre").substring(0,doc.get("nombre").length()-4)+"\n";
bus.add(new csBuscar(doc.get("nombre").substring(0,doc.get("nombre").length()-4)+"\n", doc.get("nombre")));
System.out.println(doc.get("absolute"));
}buscar.setResultados(resul);
buscar.setInfo("Se muestran "+hits.length()+" resultados para "+buscar.getBusqueda()+" en "+(end-start)+" milisegundos.");
System.out.println(buscar.getResultados());
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
searcher.close();
}
}
我也在尝试以下路线:
Viewer.js / # .. / C :/ directoriov1 / # {busqueda.ruta}
http://localhost:8080/i-Bi/Viewer.js/ # .. / C :/ directoriov1 / # {busqueda.ruta}
但是打不开。 我是否必须修改代码才能获取 Viewer.js? 希望建议谢谢。
最佳答案
您是否考虑过使用这个 google 的文档查看器?
这将在 iframe 中打开,您只能更改 pdf 的 url。
https://docs.google.com/viewer
Iframe 示例:
<iframe src="http://docs.google.com/viewer?url=http%3A%2F%2Fs3.documentcloud.org%2Fdocuments%2F509922%2Ffernandez-cristina-elisabet-anual-2011.pdf&embedded=true" width="600" height="780" style="border: none;"></iframe>
你好!
关于javascript - 使用 JSF 和 Viewer.js 从文件系统打开 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782756/