Opening PDF in a browser with Github Pages

Yan Song picture Yan Song · Jun 10, 2015 · Viewed 24.1k times · Source

I am using GitHub Pages to host my website. I have a PDF file that I want visitors to be able to open directly in a browser. But when I upload the PDF file to GitHub Pages and link to it it opens in GitHub's viewer. Is there any way to open the PDF in a browser? I do not want to upload the document to dropbox or Google Drive as these services are not available in certain countries.

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

Answer

ruifgmonteiro picture ruifgmonteiro · Feb 5, 2019

Suppose your personal website is hosted in a Github page as follows:

https://username.github.io

The repository should be name as username.github.io. If you have a pdf file named document.pdf and you place it in the directory folder then you should be able to open it directly in the browser through the following link:

https://username.github.io/folder/document.pdf

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

<a href="username.github.io/folder/document.pdf" target="_blank">PDF.</a>