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?

Community
  • 1
  • 1
newbie
  • 1,884
  • 7
  • 34
  • 55
  • There is many possibilities, see this question http://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html – LaurentG Nov 02 '13 at 05:46
  • @LaurentG `pdf.js` is a bit complicated to me. I don't know where to start. Can you give a sample code of how can I display PDF from a local path. – newbie Nov 02 '13 at 05:54

2 Answers2

0

Just iframe it if the user has adobe pdf then they will be able.to see in in there browser

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