简体   繁体   English

Java在Adobe Reader中的客户端上打开pdf文件

[英]java open pdf file on client side in adobe reader

In Java Web Application, I have to open PDF file in client machine which is available in share that too without copying to client side. 在Java Web Application中,我必须在客户端计算机中打开PDF文件,该文件也可以共享使用,而无需复制到客户端。 It should open in adobe reader in client side. 它应该在客户端的Adobe Reader中打开。

If the file is located on the client side, If he double clicks the file, it would open in the Adobe reader :-) 如果该文件位于客户端,则如果他双击该文件,它将在Adobe Reader中打开:-)

But the server can't open a file located on the client side. 但是服务器无法打开位于客户端的文件。 If the web application needs to open then the file needs to be present in the server readable location. 如果需要打开Web应用程序,则文件必须存在于服务器可读位置。 You can write a servlet to open the PDF file. 您可以编写一个servlet来打开PDF文件。

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletOutputStream servletOutputStream = null;
BufferedInputStream bufferedInputStream = null;
BufferedOutputStream bufferedOutputStream = null;
try {

    // Public user guide
    String fileName = "MyFile.pdf";


    bufferedInputStream = new BufferedInputStream(new FileInputStream(fileName));

    byte[] data = new byte[bufferedInputStream.available()];
    bufferedInputStream.read(data);

    response.setContentType("application/pdf");
    servletOutputStream = response.getOutputStream();
    bufferedOutputStream = new BufferedOutputStream(servletOutputStream);
    bufferedOutputStream.write(data);

} catch (Exception e) {
    LOG.error(e);
} finally {

    if (bufferedInputStream != null) {
        bufferedInputStream.close();
    }

    if (bufferedOutputStream != null) {
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
    }

    if (servletOutputStream != null) {
        servletOutputStream.flush();
        servletOutputStream.close();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Adobe Reader专门打开文件PDF? - How open file PDF exclusively with Adobe reader? 在特定程序(Adobe Reader)中打开下载的文件(PDF) - Open downloaded file (PDF) in specific program (Adobe Reader) 在Java应用程序中通过Adobe Acrobat打开PDF文件(通过OLE) - Open PDF File with Adobe Acrobat inside Java Application (via OLE) 如何从Adobe Reader中的Android应用程序从服务器打开pdf - How to open pdf from server from Android app in Adobe Reader Adobe Acrobat Reader 无法打开 pdf 文件,因为它不是受支持的文件类型或文件已损坏 - Adobe Acrobat Reader could not open pdf file because it is either not a supported file type or because the file has been damaged 如何通过iText读取PDF文件并像在Adobe Reader中一样显示它? - How to read PDF file through iText and display it as in Adobe Reader? 文件传输但无法加载到其各自的启动器(Adobe Pdf)-Java Server Client - File Transfer But Cannot load in its respective Launcher(Adobe Pdf) - Java Server Client 从PDF Reader中的原始文件夹中打开pdf文件 - Open pdf file from raw folder in PDF Reader 尝试打开使用iText库创建的PDF时,Adobe Reader在Mac上显示错误 - Adobe reader shows error on mac when trying to open pdf which is created using iText library 客户端加密:Javascript,Java Applet,Adobe Air - Client side encryption: Javascript vs Java Applet vs Adobe Air
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM