Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

How to link a pdf which opens a pdf-viewer in GitHub pages

Solved! Go to Solution.

I am very new to GitHub and to web developing. I am creating a static personal page on GitHub pages. I have a set of slides and I managed to link to them using a picture. However, I am stuck with the solution below, which opens my directory and previews the file but does not open the slides nicely in a pdf-viewer.

<a href="https://github.com/fabfabit/MyStuff_public/blob/master/files/ProjMarr_slides.pdf" class="image fit" ><img src="images/marr_pic.jpg" alt=""></a>

I am too noob to understand the solutions below:

Opening PDF in a browser with Github Pages

https://webapps.stackexchange.com/questions/48061/can-i-trick-github-into-displaying-the-pdf-in-the-...

The only suspicion that I have is that this might be due to the fact that the website has not been published yet, but I am just speculating. Could anyone explain to me how to fix this?

 

Crossposting from here

2 Replies
Highlighted
Pilot Lvl 2
Message 2 of 3

Re: How to link a pdf which opens a pdf-viewer in GitHub pages

From the HTML code that you provided, it looks like you're trying to grab a PDF from a separate GitHub repository that is non-relating to your GitHub Pages one. To fix this issue, it is recommended that you upload the PDF to your main GitHub Pages repository and then referencing it in your HTML code. For example:

<a href="/pdfs/ProjMarr_slides.pdf" class="image fit"><img src="images/marr_pic.jpg" alt=""></a>

^ this is also assuming you put the PDF file in its own respective pdfs folder. If you still have a problem getting it to open correctly, try adding this to your <a> tag:

type="application/pdf"

 

Hope this works out well!

 

Gavin R. Isgar - Freelance Software Developer
Solution
Copilot Lvl 2
Message 3 of 3

Re: How to link a pdf which opens a pdf-viewer in GitHub pages

Thank you so much, you have been most helpful and kind.

For those who might be reading this because of a similar issue, I want to point out two minor things:

  1. The depository was already the one pertaining to my GitHub Pages. The issue was that by calling it as above, I was (I think) effectively treating it as an external depository;
  2. Once I used the correct method for calling the file, it worked. The only thing I had  to change (relative to your suggestion) was that I had to delete the firts "/" you put in your path.

The working solution was:

<a href="pdfs/ProjMarr_slides.pdf" class="image fit"><img src="images/marr_pic.jpg" alt=""></a>	

instead of

<a href="/pdfs/ProjMarr_slides.pdf" class="image fit"><img src="images/marr_pic.jpg" alt=""></a>

Thank you so much for your help.

 

Fabio