title: Open Pdf file on web page in Spring boot
body: <pre><code>@GetMapping(value = &quot;/pdf&quot;,produces= MediaType.APPLICATION_PDF_VALUE)
      public ResponseEntity&lt;InputStreamResource&gt; getTermsConditions() throws Exception {
  
          String filePath = &quot;C:\\&quot;;
          String fileName = &quot;PDF.pdf&quot;;
          File file = new File(filePath+fileName);
          HttpHeaders headers = new HttpHeaders();
  //        headers.add(&quot;content-disposition&quot;, &quot;inline;filename=&quot; +fileName);
          headers.add(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + fileName);
  
          InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
          return ResponseEntity.ok()
                  .headers(headers)
                  .contentLength(file.length())
                  .contentType(MediaType.parseMediaType(&quot;application/pdf&quot;))
                  .body(resource);
      }
  </code></pre>
  <p>Open file, but  format is incorrect.</p>
  <p><em>���� 6 0 obj &lt;&lt; /Type /ExtGState /BM /Normal /ca 1 &gt;&gt; endobj 7 0 obj &lt;&lt; /Type /ExtGState /BM /Normal /CA 1 &gt;&gt; endobj 10 0 obj &lt;&lt; /Filter /FlateDecode /Length 156465 /Length eP}��&amp;֓�����</em></p>
  <p>Please help me. I want to open book pdf in browser like online library</p>