Opening PDF in a browser using Github Pages

I use GitHub Pages to host my site. I have a PDF file that I want visitors to open directly in the browser. But when I upload a PDF file to GitHub Pages and link to it, it opens in the GitHub viewer. Is there a way to open PDF in a browser? I don’t want to upload the document to Dropbox or Google Drive, because these services are not available in some countries.

Using a raw URL will result in a download. But I would like to open the file in the browser.

+8
source share
5 answers

Instead of loading the PDF directly from GitHub, include it in the GitHub Pages branches as a static file. This can be done simply by placing the file somewhere in the source tree :

Each other directory and file, with the exception of those listed above, such as folders cssand images, favicon.icoetc., will be copied verbatim to the generated site. There are many sites already using Jekyll if you are interested to see how they are laid out.

So put the PDF somewhere that makes sense, for example, in pdfs/foo.pdf.

To link to this PDF work both locally and on GitHub pages, Jekyll recommends the following (note especially point 2):

Jekyll, gh-pages GitHub. , URL, GitHub , URL-. URL- GitHub (username.imtqy.com/project-name/), Jekyll .

  • _config.yml baseurl /project-name - .

  • JS CSS : {{ site.baseurl }}/path/to/css.css - ( "path" ).

  • : {{ site.baseurl }}{{ post.url }} - , .

  • , , / jekyll serve, --baseurl, localhost:4000 ( /project-name ): jekyll serve --baseurl ''

, PDF {{ site.baseurl }}/pdfs/foo.pdf.

+8

Pdf Github, ,

  • -/, Github, , sumanbogati, sumanbogati.imtqy.com
  • PDF
  • URL- Pdf, .

, pdf - Html

<embed src="https://sumanbogati.imtqy.com/sample.pdf" type="application/pdf" />

. .

+1

<a target='_blank' href={require('path/to/pdf/file')}>PDF Doc</a>

, GitHub, PDF

https://userName.imtqy.com/repoName/static/media/pdfFileName.hashNumber.pdf

, , , , .

0

PDF , ; www.website/pdf/example.pdf .

:

1. .

2. /pdf/ .

3. example.pdf

:: PDF ; www.website/pdf/example.pdf

4. , .pdf URL. index.html HTML PDF :

0

, - Github :

https://username.imtqy.com

username.imtqy.com. pdf document.pdf , :

https://username.imtqy.com/folder/document.pdf

To allow the user to open the PDF file in a new browser window, you can use the following HTML code, where "PDF" points to the link:

<a href="username.imtqy.com/folder/document.pdf" target="_blank">PDF.</a>
0
source

All Articles