0

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. The URL is accessed by:

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

But the PDF file is displaying on the whole page. My PDF is from my local I want to display it with just a portion of webpage. Maybe a <div> or anything that suit the approach best. Any thoughts of how can I do this?

4

2 回答 2

0
<?php
$file = "file.pdf";
$read = file_get_contents($file);
echo $read;
?>
于 2013-11-02T07:14:44.550 回答
0

如果用户有 adobe pdf,只需 iframe,然后他们就可以在浏览器中看到

于 2013-11-02T06:53:50.663 回答