在Github中上传并直接显示pdf文件

https://webapps.stackexchange.com/questions/48061/can-i-trick-github-into-displaying-the-pdf-in-the-browser-instead-of-downloading/48133#48133?newreg=fee550d65482475eba49ba3c8951bc66


When viewing a PDF file on GitHub, there seems to be no way to have the browser simply display the file as opposed to downloading it.

None of these links work, and these are the only ones I'm able to get to (or derive from the behaviour of working with source code):



Github uses content-disposition: attachment for PDFs, which downloads the file automatically on github.com. You can host the file on a static page provided by GitHub which can link to this file and update as you update the PDF. For that, you can see github pages.

Summary

  • Create a repo named USERNAME.github.io.
  • In that repo, click Settings then click Automatic Page Generator, then complete the wizard to publish a User Page.
  • Go back to your content repo and click Settings then click Automatic Page Generator, then complete the wizard to publish a Project Page. (Logically, the project page's files would go in a special directory but GitHub puts them in a gh-pages branch. Don't merge that branch to/from master.)
  • Sync the gh-pages branch to your computer then copy in your PDFs:

    git checkout gh-pages
    git checkout master -- 'docs/*.pdf'

  • Commit the changes and push them to GitHub.
  • Now go back to the repo on GitHub and use the Automatic Page Generator to edit the Project Page, adding links to these PDFs of the form:

    [Intro.pdf](http://USERNAME.github.io/REPONAME/docs/Intro.pdf).

  • Republish the Project Page.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值