简体   繁体   English

在网页中显示PDF

[英]Display PDF in webpage

To follow up to this post I change the code to this: 为了跟进这篇文章,我将代码更改为:

@RequestMapping( value = "/{prePath:^tutor$|^admin$}/module/{file_id}" )
public void getModule( @PathVariable( "file_id" )
int fileId, Model model, HttpServletResponse response, HttpServletRequest request )
{
     model.addAttribute( "id", fileId );

     File test = new File( "C:\\resource\\pdf\\test.pdf" );
     response.setHeader( "Content-Type", "application/pdf" );
     response.setHeader( "Content-Length", String.valueOf( test.length() ) );
     response.setHeader( "Content-Disposition", "inline; filename=\"test.pdf\"" );

     System.out.println( test.toPath() );
     try
     {
         Files.copy( test.toPath(), response.getOutputStream() );
     }
     catch( IOException e )
     {
         e.printStackTrace();
     }
}

And finally able to display PDF in the webpage. 最终能够在网页上显示PDF。 The URL is accessed by: 该URL可通过以下方式访问:

<a href="../admin/module/${ file_id }.do?test" >Spring Tutorial</a>

But the PDF file is displaying on the whole page. 但是PDF文件显示在整个页面上。 My PDF is from my local I want to display it with just a portion of webpage. 我的PDF来自我的本地,我只想显示一部分网页。 Maybe a <div> or anything that suit the approach best. 也许<div>或最适合该方法的任何东西。 Any thoughts of how can I do this? 关于如何执行此操作的任何想法?

如果用户使用的是Adobe pdf,则只需对其进行内嵌,就可以在该浏览器中看到

<?php
$file = "file.pdf";
$read = file_get_contents($file);
echo $read;
?>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM